Coder Social home page Coder Social logo

Comments (4)

brentvatne avatar brentvatne commented on April 28, 2024

hey @ScreamZ! this is a nice idea. I think a great example app for this would be to rebuild the "realworld" app: https://github.com/gothinkster/realworld

if you want to work on doing this we'd be happy to help as you run into issues along the way. one of the harder parts of getting started on it is that there is currently no existing mobile implementation, so you might have to make some ui design decisions

from react-navigation.github.io.

vonovak avatar vonovak commented on April 28, 2024

I'll try to answer. I have a fairly complex app with multiple users of different roles and deep linking, and it does work with react-navigation. In your ROOT you need to load the app state to find out if a user is already logged in or not. That will influence your initial screen. In the render method of ROOT, you'll do something like

  render() {
    let initialScreenString = 'Anonymous';
    if (hasValidCredentials) {
      initialScreenString = 'Authenticated'
    }
      // construct the right navigation structure conditionally 
      const RootStack = constructInitialStack(initialScreenString);

      return (
              <RootStack
                ref={NavigationService.setContainer}
                onNavigationStateChange={trackScreenChange}
              />
      );
    }
  }

Your navigation structure will be something like

const constructInitialStack = initialRouteName => {
  return MainStack(initialRouteName);
};

const MainStack = initialRouteName =>
  StackNavigator(
    {
      AnonymousStack: { screen: AnonymousStack,   
         navigationOptions: {
             header: null,
         },
      },
      AuthenticatedTab: { screen: AuthenticatedTab },
      ModalScreenOne: { screen: ModalScreenOne },
      ModalScreenOne: { screen: ModalScreenOne },
    },
    {
      ...commonStackStyles,
      initialRouteName,

      // headerMode: 'none', -> this would also affect the modal scenes and we do not want that
      // thus every navigator screen (eg. AnonymousStack) in this navigator must define header: null
      mode: 'modal',
    }
  );

const AnonymousStack = StackNavigator(
  {
    LoginScreen: { screen: LoginScreen },
    OnboardingScreen: { screen: OnboardingScreen },
  }
);

You will probably need to do some resets if you want to have some 'history' in your stack.

from react-navigation.github.io.

marcpicaud avatar marcpicaud commented on April 28, 2024

Hi,

OP has probably found a solution as I speak, but for future generations : this part of the docs explains the authentication flow very, very well 👍 https://reactnavigation.org/docs/en/auth-flow.html

If you get this right, building nested navigators on top of it will be a child's play.

cheers

from react-navigation.github.io.

ScreamZ avatar ScreamZ commented on April 28, 2024

@marcpicaud This was not set at the moment I wrote that topic, I think it's one of the consequence of this part of the documentation ;D

Regards

from react-navigation.github.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.