【发布时间】:2018-11-19 15:11:08
【问题描述】:
我需要将主题设置传递给每个屏幕的导航选项。设置存储在 redux 中。在旧版本中,我会写这样的东西:
const AppNavigator = StackNavigator({
Home: { screen: MainList },
Settings: { screen: Settings },
NewEvent: { screen: NewEvent },
Contacts: { screen: Contacts },
Map: { screen: Map},
})
在渲染函数中...
<AppNavigator
screenProps={{
settings: this.props.settings,
headerTintColor: '#ffffff'
}}
/>
...props.settings 是 redux 状态的一部分。 Wich 在 navigationOptions 中使用
static navigationOptions = ({ navigation, screenProps }) => {
let settings = screenProps.settings;
let theme = settings? settings.theme: null;
return {
title: strings.account,
headerTintColor: screenProps.headerTintColor,
headerStyle: {backgroundColor: theme? theme.def.primaryColor: null}
};
};
但是当我必须用 createAppContainer 包装我的导航器时,我现在应该怎么做呢?使用 navigation.setParams 会在模拟器中造成明显的延迟,所以它对我来说不是一个合适的解决方案......请记住,主题可以随时更改!
【问题讨论】:
标签: reactjs react-native redux react-navigation