Giter Site home page Giter Site logo

how to switch rootscreen about rnn-screens HOT 2 OPEN

roycehe avatar roycehe commented on May 28, 2024
how to switch rootscreen

from rnn-screens.

Comments (2)

kanzitelli avatar kanzitelli commented on May 28, 2024 1

Hey @roycehe! Let's take this - https://github.com/kanzitelli/rnn-starter/blob/master/App.tsx - as an example.
Say, we have stores.auth where you store your auth state. You can use it in App function to determine which root you want to use first. Then from Login screen, you will need to setRoot manually to show your tabs.

import {LogBox} from 'react-native';
import {Root, Screen, BottomTabs} from 'rnn-screens';

import {screens} from './src/screens';
import {Services} from './src/services';
import {Stores, stores} from './src/stores';
import {DesignSystem} from './src/utils/designSystem';
import SplashScreen from 'react-native-splash-screen';

LogBox.ignoreLogs(['Require', 'RCTBridge']);

export const beforeStart = async (): PVoid => {
  // 1. hydrate stores
  await Stores.hydrate();

  // 2. configure design system
  await DesignSystem.configure();

  // 3. init services
  await Services.init();

  // 4. hide splash screen
  SplashScreen.hide();
};

export const App = () =>
  Root(
    // we can use `stores` here as it was already inited in beforeStart functions
    stores.auth.isLoggedIn ?
      Screen(screens.get('Login')) : 
      BottomTabs([
        Screen(screens.get('Main')),
        Screen(screens.get('Playground')),
        Screen(screens.get('Settings')),
      ]),
  );

I didn't test this code, but it seems like a working piece.

from rnn-screens.

DavidKarasek avatar DavidKarasek commented on May 28, 2024

This works when you launch the app. However, at least for me, the stores are not updating when state changes and the root stack never updates.

from rnn-screens.

Related Issues (8)

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.