堆栈导航器中的React Native DrawerNavigator无法正常工作

时间:2018-01-10 05:42:45

标签: react-native react-native-android react-navigation drawer stack-navigator

我在使用带抽屉导航的堆栈导航等反应导航时遇到了麻烦

const Drawerstack = DrawerNavigator({
	updatesegregation : { screen: UpdateSegregation },
  listoffers : { screen: ListOffers },
  mypurse : { screen: MyPurse },
  myoffers : { screen: MyOffers },
  segregationhistory : { screen: SegregationHistory },
  ranking : { screen: Ranking },
  updates : { screen: Blogs },
  contactus : { screen: ContactUs },
  termsandconditions : { screen: TermsAndConditions },
  instruction : { screen: Instructions },
  profile : { screen: Profile },
  segregationtips : { screen: SegregationTips },
  faqs : {screen: Faqs },
},{
	contentComponent: NavigationDrawer,
})

const Index = StackNavigator({
  authcheck : { screen: AuthCheck },
  login: { screen: Login },
  registration : { screen: Registration },
  profileedit : { screen: ProfileEdit },
  socialregistration : { screen: SocialRegistration },
  forgotpassword : { screen: ForgotPassword },
  drawerstack: { screen: Drawerstack },
},
 {
    headerMode: 'none'
});

export default Index;

根页面是authcheck,它检查访问令牌并返回用户。

fetch(url.main + 'version' + url.transform, {
		method: 'GET',
		headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json'
        } 
	}).then((response) => response.json())
		.then((responseData) => {
			//alert(JSON.stringify(responseData))
			if(responseData.version[0].version_code == Version){
				AsyncStorage.getItem('User').then((value) => {
					//alert(JSON.parse(value));
					var tmpValue = JSON.parse(value);
					if (tmpValue !== null) {
					
						this.props.navigation.navigate("updatesegregation");
					}else{
						this.props.navigation.navigate('login');
					}
				})
			}else{
				this.PopupDialog.show();
			}
		})

但是当有可用的访问令牌时,它没有显示任何错误,也没有导航到请求的页面。

此导航不会将我重定向到我想要的DrawerNavigator页面......

如果有人知道请帮助......

1 个答案:

答案 0 :(得分:2)

这是由于参考

  

this.prop

创建一个全局函数

 onAuthentication = (screenName) =>{

this.props.navigation.navigate(screenName)

};

然后在ur fetch函数中调用此函数,如

this.onAuthentication('updatesegregation') or this.onAuthentication('login')