Modal window in React Native with react-navigation

烂漫一生 提交于 2019-12-11 07:19:46

问题


I am using react-navigation in React Native and I want, on startup, to determine if the user is logged in, and if he/she is already logged in, I want to open a modal window (full screen).

How is this best done? I cannot find anything in the react-navigation docs where a screen is conditionally shown.


回答1:


Look, you needs to change the mode from Navigation.

const RootStack = StackNavigator(
  {
    Main: {
      screen: MainStack,
    },
    MyModal: {
      screen: ModalScreen,
    },
  },
  {
    mode: 'modal',
    headerMode: 'none',
  }
);

You can run this code here

Screenshots:

References:

  • Opening a full-screen modal
  • NavigatorConfig` props



回答2:


React has a Modal component that you can use to display a full-screen Modal. See the docs here: https://facebook.github.io/react-native/docs/modal.html

To display it conditionally if the user is logged in you can use the 'visible' property. E.g. drop this on the screen that your app loads to:

<Modal
      animationType={"slide"}
      transparent={false}
      visible={this.state.userIsLoggedIn}
      >



回答3:


you can do like this:

const ModalNavigator = StackNavigator(
  {
    ModalScreen: { screen: ModalScreen },
  },
  {
    mode: "modal",
    headerMode: "none",
  },
)


来源:https://stackoverflow.com/questions/44118018/modal-window-in-react-native-with-react-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!