4
我有以下結構:重置TabNavigator的歷史與反應導航
const routeConfiguration = {
Login: { screen: Login },
Home: { screen: TabBar },
};
const stackNavigatorConfiguration = {
headerMode: 'screen',
navigationOptions: {
header: { visible: false }
}
};
export const RootNav = StackNavigator(routeConfiguration, stackNavigatorConfiguration);
我的TabBar其中每個標籤都有它自己的StackNavigator:
const routeConfiguration = {
TabOneNavigation: { screen: TabOneNavigation },
TabTwoNavigation: { screen: TabTwoNavigation },
TabThreeNavigation: { screen: TabThreeNavigation },
};
const tabBarConfiguration = {
tabBarOptions: {
activeTintColor: 'white',
inactiveTintColor: 'lightgray',
labelStyle: {
fontSize: 10,
fontFamily: Fonts.book
},
style: {
backgroundColor: Colors.greenLightGradient,
borderTopWidth: 1,
borderTopColor: Colors.tabGreenLine
},
}
};
export const TabBar = TabNavigator(routeConfiguration, tabBarConfiguration);
當應用程序第一次加載它進入登錄界面。成功登錄後,我使用actionTypes.TO_HOME進入主頁。在那裏我有3個標籤(Feed,Suggestion,Profile)。在「配置文件」選項卡中,我具有註銷按鈕,可以重置導航歷史記錄,然後再次登錄(迄今爲止這麼好)。但是,當我再次登錄並返回首頁時,它會顯示第一個標籤,然後導航到最後一個(Profile),看起來像TabNavigator的歷史記錄未重置。我應該做一些特別的事情,以便TabNavigator的歷史也重新設置?
這是我重置歷史,要在登錄屏幕減速器:
export const navReducer = (state = initialState, action = {}) => {
let nextState;
switch (action.type) {
case actionTypes.TO_LOGIN:
nextState = RootNav.router.getStateForAction(
NavigationActions.reset({
index: 0,
actions: [NavigationActions.navigate({ type: NavigationActions.NAVIGATE, routeName: actionTypes.TO_LOGIN })],
key: null
}), state);
break;
case actionTypes.TO_HOME:
nextState = RootNav.router.getStateForAction(
NavigationActions.reset({
index: 0,
actions: [NavigationActions.navigate({ type: NavigationActions.NAVIGATE, routeName: actionTypes.TO_HOME })],
}), state);
break;
default:
nextState = RootNav.router.getStateForAction(action, state);
break;
}
return nextState || state;
};
它不工作。效果是一樣的。我用更多的信息和代碼更新了我的問題。 – jazzdle