【问题标题】:How do I change the name of titles that are inside a drawer in react navigation?如何更改反应导航中抽屉内的标题名称?
【发布时间】:2018-05-29 08:45:07
【问题描述】:

由于该应用程序适用于不同的语言,我希望抽屉中显示的标题以不同的语言显示。目前,它们默认为它们设置的路由。因此,我不想说“登录”,而是以“s'identifier”为例。

目前,抽屉设置如下所示:

const allDrawerOptions = {
    NotificationHistory: { screen: NotificationHistory, },
    CameraRegistration: { screen: CameraRegistration, },
    Settings: { screen: Settings, },
    Info: { screen: Info, }
};

const drawerForNotificationHistory = DrawerNavigator(
    allDrawerOptions,
    { initialRouteName: 'NotificationHistory' }
);

const hamburgerIcon = ({ navigation }) => ({
  headerLeft:
    <TouchableOpacity
        onPress={() => navigation.navigate('DrawerToggle')}
        style={{
            height: '100%',
            width: 60,
            // marginLeft: 10,
            justifyContent: 'center',
            alignItems: 'center',
            // borderWidth: 1, borderColor: 'red',
        }}
    >
        <Text
            style={{
                fontFamily: 'FontAwesome',
                fontSize: 25,
            }}
        ></Text>
    </TouchableOpacity>
});

我的 stacknavigator 看起来像这样:

const Navigation = StackNavigator(
    {
        Splash: { screen: Splash },
        Login: { screen: Login },
        SignUp: { screen: SignUp },
        HomeScreen: { screen: HomeScreen },
        Home: { screen: Home },
        NotificationHistory: {
            screen: drawerForNotificationHistory,
            navigationOptions: hamburgerIcon,

        },
     },
     initialRoute: 'HomeScreen'
     }
}

【问题讨论】:

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


    【解决方案1】:

    他们的关键是在 allDrawerOptions 中为每个屏幕添加 navigationOptions。

    所以 NotificationHistory 现在看起来像

    NotificationHistory: 
        { screen: NotificationHistory,
            navigationOptions: () => 
                ({
                    title: '알림 내역'
                }) 
        },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多