我正在尝试使用库来启用本地化。在示例应用中,当我单击按钮时,出现错误:
Unhandled JS Exception: `title` cannot be defined as a function in navigation options for `Settings` screen.
Try replacing the following:
{
title: ({ state }) => state...
}
with:
({ navigation }) => ({
title: navigation.state...
})
我不确定问题出在哪里,但我认为这是在代码的平静上
const AppNavigator = StackNavigator({
Home: {
screen: WelcomeContainer,
navigationOptions: {
title: 'Multi Language Sample App' // we advice using something static like your app's name or company name on the startup screen
}
},
Settings: {
screen: SettingsContainer,
navigationOptions: {
title: (navigation) => {
return navigation.state.params.title
}
}
},
About:{
screen: About,
navigationOptions: {
title: (navigation) => {
return navigation.state.params.title
}
}
}
})
我试图用建议的代码替换代码,但它没有奏效。你能帮我解决问题吗?
react-navigation StackNavigator title
prop 需要一个字符串值。
标题
可用作
headerTitle
的回退的字符串。此外,将用作 tabBarLabel 的回退(如果嵌套在TabNavigator
) 或drawerLabel
(如果嵌套在DrawerNavigator
中)
如果要动态设置标题,可以尝试实现以下代码。
Settings: {
screen: SettingsContainer,
navigationOptions: ({navigation}) => ({
title: navigation.state.params.title
})
}