0
我試圖在按下NavigatorIOS React Native組件上的通知按鈕時打開一個側面菜單,但子組件似乎不是當父母的狀態改變時更新。因此,按通知按鈕並沒有做我想做的事情。父母和孩子的組成如下。如何使用NavigatorIOS在父狀態更改時更新子組件?React Native NavigatorIOS子組件在父狀態更改時不更新
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
rightMenuOpen: false
}
this.rightButtonPress = this.rightButtonPress.bind(this);
}
rightButtonPress() {
this.setState({rightMenuOpen: true});
}
render() {
return (
<NavigatorIOS
initialRoute={{
component: Home,
rightButtonIcon: source=require('./img/notifications.png'),
onRightButtonPress: this.rightButtonPress,
passProps: {index: 1, rightMenuOpen: this.state.rightMenuOpen},
}}
style={{flex: 1}}
/>
)
}
}
class Home extends React.Component {
constructor(props) {
super(props);
}
render() {
const menu = <Switch/>
return (
<View style={styles.body}>
<SideMenu
menu={infoText}
menuPosition="right"
disableGestures={true}
isOpen={this.props.rightMenuOpen}
>
<WebView
source={{uri: 'https://www.michigandaily.com/'}}
bounces={false}
/>
</SideMenu>
</View>
);
}
}