i在 StackNavigator
内有一个 TabNavigator
(在 StackNavigator
中,i具有 login
视图和 TabNavigator
,其中包含其他屏幕)。问题在于,我必须在标签上使用" Logout
"按钮之类的东西,该选项卡将其重定向到Login
视图。如果我尝试简单地重定向到LoginView
,则TabBar
仍然出现在屏幕底部,这不是我想要的。有什么方法可以单击TabBar
按钮并返回到初始StackNavigator
?(例如OnPress
属性或类似的属性)。
这是我的路由器
const tab_bar = TabNavigator({
Home: {
screen: HomeScreen
},
Logout: {
screen: LoginView // this just show the view but the tabBar still appearing
},
});
const Login = StackNavigator({
login: {
screen: LoginView,
},
List: {
screen: tab_bar
,navigationOptions: {header:null}
}
},
{
initialRouteName: 'login'
});
完成!使用TABBARONPRESS属性和导航操作。
const tab_bar = TabNavigator({ // This tabNavigator is inside a stackNavigator, wich contains the 'login' view
Home: {
screen: Home
},
Logout: {
screen: Logout // Empty screen, useless in this specific case
,navigationOptions: ({navigation}) => ({
tabBarOnPress: (scene, jumpToIndex) => {
return Alert.alert( // Shows up the alert without redirecting anywhere
'Confirmation required'
,'Do you really want to logout?'
,[
{text: 'Accept', onPress: () => { navigation.dispatch(NavigationActions.navigate({ routeName: 'login' }))}},
{text: 'Cancel'}
]
);
},
})
},
});
用户单击tabar上的logout
按钮时,请显示警报以确认操作,则如果用户接受重定向到登录视图。
注意(22/09/2017):使用TABBARONPRESS属性下载Master Branch版本(不是NPM的版本)。