我正在尝试使用library来启用本地化。在示例应用程序中,当我单击按钮时,出现错误:
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
}
}
}
})
我尝试用提议的代码替换代码,但它没有用。你能帮我解决这个问题吗?
答案 0 :(得分:1)
react-navigation StackNavigator title
prop expects a string value.
title
String that can be used as a fallback for
headerTitle
. Additionally, will be used as a fallback for tabBarLabel (if nested in aTabNavigator
) ordrawerLabel
(if nested in aDrawerNavigator
)
If you want to set title dynamically you can try to implement below code.
Settings: {
screen: SettingsContainer,
navigationOptions: ({navigation}) => ({
title: navigation.state.params.title
})
}