在抽屉式导航中无法响应AsyncStorage数据

时间:2018-06-30 22:01:18

标签: react-native react-router react-native-android react-navigation react-native-ios

如何从导航页面获取AsyncStorage的数据,如下所示 作为lang或用户名或图像 to add image and username like this and make the drawer from the right or left depending on the language that stored in AsyncStorage app.js

    import React from 'react';
    import TeaApp from './Pages/navigation';


    export default class App extends React.Component {
      constructor(){
        super();
        this.state = {
          name : '',
        };

      }

      render() {
        return (

            <TeaApp/>

        );
      }
    }

Navigation.js

            import React,{ Component } from 'react';
            import { AsyncStorage, View, Text, Image, StyleSheet, Button, SafeAreaView} from 'react-native';
            import { StackNavigator , SwitchNavigator, DrawerNavigator, DrawerItems,TouchableOpacity} from 'react-navigation';
            import Login from './login';
            import Mainpage from './mainPage';
            import Menu from './menu';
            import CustomizeOrder from './customizeOrder';
            import Intro from './intro';
            import PreviewOrder from './previewOrder';
            import ViewOrder from './viewOrder';
            import ChangePassword from './changePassword';
            import KitchenPage from './kitchenPage';
            import ChangeLanguage from './changeLanguage';



            const INTRO = StackNavigator({ Intro:{screen: Intro} });
            const LOGIN = StackNavigator({ Login:{screen: Login} });
            const VIEWORDER = StackNavigator({ ViewOrder:{screen: ViewOrder} });

            const REST = StackNavigator({ 
                UserHome:{screen: Mainpage,navigationOptions:({navigation})=>({drawerLockMode:"locked-closed"})},
                Menu:{screen: Menu,navigationOptions:({navigation})=>({drawerLockMode:"locked-closed"})},
                customizeOrder:{screen: CustomizeOrder,navigationOptions:({navigation})=>({drawerLockMode:"locked-closed"})},
                previewOrder:{screen: PreviewOrder,navigationOptions:({navigation})=>({drawerLockMode:"locked-closed"})}, 
            });

            export default SwitchNavigator(
                {
                    intro:{screen: INTRO},
                    login:{screen: LOGIN},
                    rest:{screen: REST},
                    viewOrder:{screen: VIEWORDER},
                },
                {
                    initialRouteName: 'intro'
                }
            );

登录时,我将语言存储在名称为“ lang”的AsyncStorage中,此后,操作系统将直接转到UserHome屏幕,并且将启用抽屉导航,现在我需要检查“ lang”是否===“ en”使抽屉在左侧,在右侧,但是当我在“ navigation.js”中创建该条件时,AsyncStorage中没有任何数据

0 个答案:

没有答案