简体   繁体   English

反应原生导航

[英]React-native Navigation

I have created 2 Screens Screen1.js and Screen2.js Screen1.js will be splashscreen while Screen2.js will be loginscreen.我创建了 2 个屏幕 Screen1.js 和 Screen2.js Screen1.js 将是闪屏,而 Screen2.js 将是登录屏幕。 What i want to do is to open Screen2.js 5 seconds after Screen1.js is render.我想要做的是在 Screen1.js 渲染后 5 秒打开 Screen2.js。 I tried to import {Navigation} from 'react-native' but it is not anymore on this library.我试图从 'react-native' 导入 {Navigation},但它不再出现在这个库中。 Any idea how can i do it?知道我该怎么做吗?

If you'd like to use navigation in react-native , the project developers recommend you use react-navigation .如果您想在react-native使用导航,项目开发人员建议您使用react-navigation I've used it, and it works just fine.我用过它,它工作得很好。 Say for example you'd like a tab bar application.比如说你想要一个标签栏应用程序。 You can import TabNavigator from react-navigation and use it:您可以从react-navigation导入TabNavigator并使用它:

import { TabNavigator } from 'react-navigation'
...

const MyApp = TabNavigator({
  Home: {
    screen: MyHomeScreen,
  },
  Notifications: {
    screen: MyNotificationsScreen,
  },
}, {
  tabBarOptions: {
    activeTintColor: '#e91e63',
  },
});

More examples and docs: https://reactnavigation.org/docs/navigators/tab更多示例和文档: https : //reactnavigation.org/docs/navigators/tab

UPDATE:更新:

As there is update of react-navigation library which is v4.由于有反应导航库的更新,它是 v4。 In v4 you can create a tab in different ways like BottomTabNavigator, MaterialBottomTabNavigator and MaterialTopTabNavigator.在 v4 中,您可以使用不同的方式创建选项卡,例如 BottomTabNavigator、MaterialBottomTabNavigator 和 MaterialTopTabNavigator。 So in react-navigation v4 the above code looks like this:所以在 react-navigation v4 上面的代码是这样的:

import { createBottomTabNavigator } from 'react-navigation-tabs';
...

const MyApp = createBottomTabNavigator({
  Home: {
    screen: MyHomeScreen,
  },
  Notifications: {
    screen: MyNotificationsScreen,
  },
}, {
  tabBarOptions: {
    activeTintColor: '#e91e63',
  },
});

For more details docs: https://reactnavigation.org/docs/en/tab-based-navigation.html有关更多详细信息文档: https : //reactnavigation.org/docs/en/tab-based-navigation.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM