如何在React Native中的抽屉式导航中将收到的数据显示为用户名?

时间:2018-06-28 10:01:25

标签: reactjs react-native navigation-drawer react-native-android react-native-navigation

1 个答案:

答案 0 :(得分:2)

您可以按以下方式制作自定义抽屉组件。 首先,像这样初始化DrawerNavigator

const AppScreens = DrawerNavigator(
{
    Screen1: Screen1,
    Screen2: Screen2,
},{
    contentComponent: CustomDrawerComponent,
    'drawerOpenRoute': 'DrawerOpen',
    'drawerCloseRoute': 'DrawerClose',
    'drawerToggleRoute': 'DrawerToggle',
    navigationOptions: {
        gesturesEnabled: false,
    },
});

然后,在此处制作您的自定义抽屉

const CustomDrawerComponent = (props) => {
    return (
        <View>
            <Image source={{uri: 'path/to/image'}} style={{width: 100, height: 50}}/>
            <Text>Your name</Text>
        </View>
    );
}

如果要从缓存中获取名称,则可以在此处使用AsyncStorage,并可以使用props.navigation找到导航道具。