【发布时间】:2019-11-18 17:02:23
【问题描述】:
我有一个设计,其中导航标题样式颜色应根据状态而变化。
第一次安装组件时可以更改样式。但是,我看不到在后续状态更改时更改它的方法。
const mapStateToProps = state => {
return {
stuff: state.stuff,
}
}
const mapDispatchToProps = dispatch => ({
// stuff
})
class Test extends React.Component {
static navigationOptions = ({ navigation }) => {
// need to set barcolor to this.props.state.stuff.headerColor
return {
...
headerStyle: {
backgroundColor: ???,
}
...
}
}
componentDidMount() {
// could do it here, but only works on mount
// this.props.navigation.setParams({ headerColor: this.props.state.stuff.headerColor });
// then access params from navigation state in navigationOptions
}
render() {
//
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Test);
这在 React Native 中可行吗?
【问题讨论】:
标签: reactjs navigation native