[英]Modal window in React Native with react-navigation
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). 我在React Native中使用
react-navigation
,我想在启动时确定用户是否已登录,如果他/她已经登录,我想打开一个模态窗口(全屏)。
How is this best done? 这怎么做得最好? I cannot find anything in the react-navigation docs where a screen is conditionally shown.
我无法在有条件地显示屏幕的react-navigation文档中找到任何内容。
React has a Modal component that you can use to display a full-screen Modal. React有一个Modal组件,可用于显示全屏模态。 See the docs here: https://facebook.github.io/react-native/docs/modal.html
请参阅此处的文档: 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. 要在用户登录时有条件地显示它,您可以使用“可见”属性。 Eg drop this on the screen that your app loads to:
例如,将其放在应用加载到的屏幕上:
<Modal
animationType={"slide"}
transparent={false}
visible={this.state.userIsLoggedIn}
>
you can do like this: 你可以这样做:
const ModalNavigator = StackNavigator(
{
ModalScreen: { screen: ModalScreen },
},
{
mode: "modal",
headerMode: "none",
},
)
Look, you needs to change the mode
from Navigation. 看,您需要从导航更改
mode
。
const RootStack = StackNavigator(
{
Main: {
screen: MainStack,
},
MyModal: {
screen: ModalScreen,
},
},
{
mode: 'modal',
headerMode: 'none',
}
);
You can run this code here 您可以在此处运行此代码
Screenshots: 截图:
References: 参考文献:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.