我知道已经有一个类似的问题,但是没有分享的代码.
原文链接:https://www.f2er.com/react/301225.html在navbarChanged()>如果条件,我正在做一个this.setState.这是HoMetab的类型,但setState似乎没有工作.
任何线索/指针?
class HoMetab extends React.Component { constructor() { super() this.setState({ isNavBarHidden: false }); } updatePosition(lastPosition) { } navbarChanged() { console.log("received navbar changed event",AppStore.navbarVisible()); if (AppStore.navbarVisible()) { StatusBarIOS.setHidden(false) this.setState({ isNavBarHidden: false}) // this.state.isNavbarHidden is still true here this.render(); } else { StatusBarIOS.setHidden(true); this.setState({ isNavBarHidden: true}); this.render(); } } componentDidMount() { AppStore.addNavbarChangeListener( this.navbarChanged.bind(this) ); } componentWillMount() { StatusBarIOS.setHidden(false) this.setState({ isNavBarHidden: false }); } }
这里是我的render()代码:
render() { return ( <NavigatorIOS style={styles.container} navigationBarHidden={this.state.isNavBarHidden} ref="navigator" initialRoute={{ title: 'Foo',component: HomeScreen,passProps: { parent: this } }} /> ) }