在我的React Native项目中,我想动态更新BottomTabNavigator的标题和tabBarLabel。在我的应用中,当用户触摸按钮时,它会切换语言并将其存储在商店中(我正在使用Redux)。据我了解,我可以将screenProps传递给导航器,所以我已经尝试过了:
const MainTab = createBottomTabNavigator({
Home: HomeStack,
Search: SearchStack,
User: UserStack,
})
const AppSwitchNavigator = createSwitchNavigator({
Auth: LoginScreen,
Main: MainTab,
})
const AppContainer = createAppContainer(AppSwitchNavigator)
const myComponent = () => (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<AppContainer screenProps={ {language: store.getState().user.language} } />
</PersistGate>
</Provider>
)
然后在我的用户屏幕中:
class UserScreen extends Component {
static navigationOptions = ({screenProps}) => {
console.log(screenProps.language)
.....
)}
但是即使我的商店的状态正在改变,screenProps也不会改变。有提示吗?