我正在尝试使用 react-native-navigation 但我遇到了一个简单的问题。
该应用程序有一个没有标签的登录页面。 (非常类似于 facebook 登录页面)(图片引用 -
The image is just to give an idea. Image Courtesy -
Google
用户登录后,我想转换为基于选项卡的应用程序,并且我希望两个选项卡具有不同的导航堆栈(就像在 Quora 等应用程序中发生的那样)
(图片引用 - Again Image is just a reference)
我正在使用 mobx 进行状态管理。
我知道这是一个常见的用例,但我对我已知的两个选项感到困惑 -
例如——
应用程序.js
constructor() {
reaction(() => auth.isLoggedIn, () => app.navigateToHome())
reaction(() => app.root, () => this.startApp(app.root));
app.appInitialized();
}
startApp(root){
switch (root) {
case 'user.login':
Navigation.startTabBasedApp({
tabs: [
{
label: 'One',
screen: 'user.login',
icon: require('./assets/one.png'),
selectedIcon: require('./assets/one_selected.png'),
navigatorStyle: {},
}
]
screen: {
screen: root,
title: 'Login',
navigatorStyle: {
screenBackgroundColor: colors.BACKGROUND,
statusBarColor: colors.BACKGROUND
},
navigatorButtons: {}
}
})
return ;
case 'user.home':
Navigation.startTabBasedApp({
tabs: [
{
label: 'One',
screen: 'user.home',
icon: require('./assets/one.png'),
selectedIcon: require('./assets/one_selected.png'),
navigatorStyle: {},
},
{
label: 'Two',
screen: 'user.home',
icon: require('./assets/two.png'),
selectedIcon: require('./assets/two_selected.png'),
title: 'Screen Two',
navigatorStyle: {},
}
],
animationType: 'slide-down',
});
return;
default:
console.error('Unknown app root');
}
}
例如 - App.js
Navigation.startSingleScreenApp({
screen: {
screen: root,
title: 'Login',
navigatorStyle: {
screenBackgroundColor: colors.BACKGROUND,
statusBarColor: colors.BACKGROUND
},
navigatorButtons: {}
}
})
主页.js
<Tabs>
<Tab
titleStyle={{fontWeight: 'bold', fontSize: 10}}
selectedTitleStyle={{marginTop: -1, marginBottom: 6}}
selected={true}
renderIcon={() => <Icon containerStyle={{justifyContent: 'center', alignItems: 'center', marginTop: 12}} color={'#5e6977'} name='whatshot' size={33} />}
renderSelectedIcon={() => <Icon color={'#6296f9'} name='whatshot' size={30} />}
>
<Feed />
</Tab>
<Tab
titleStyle={{fontWeight: 'bold', fontSize: 10}}
selectedTitleStyle={{marginTop: -1, marginBottom: 6}}
selected={selectedTab === 'profile'}
title={selectedTab === 'profile' ? 'PROFILE' : null}
renderIcon={() => <Icon containerStyle={{justifyContent: 'center', alignItems: 'center', marginTop: 12}} color={'#5e6977'} name='person' size={33} />}
renderSelectedIcon={() => <Icon color={'#6296f9'} name='person' size={30} />}
onPress={() => this.changeTab('profile')}>
<Profile />
</Tab>
</Tabs>
在 react-native 中管理选项卡的最佳实践是什么?
在我的用例中,我应该使用哪种方法?
最佳答案
要实现顶部选项卡,您需要启动一个单屏应用程序,然后定义顶部选项卡。你可以在下面做这样的事情。
Navigation.startSingleScreenApp({
screen: 'FirstScreen'
title: 'FirstScreenTitle'
topTabs: [
{
screen:'FirstTabScreen'
},
{
screen:'SecondTabScreen'
}
]
});
首先将每个选项卡注册为单独的屏幕。
关于react-native - 如何使用 react-native-navigation 将单屏应用程序转换为基于选项卡的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43777731/