1

ナビゲーションバーの右ボタンを押したときに、シーンのコンポーネント内の関数を呼び出す必要があります。親でネイティブルータフラックスに反応する - シーンのメソッドを呼び出す方法

:子で

<Router 
     style={routerStyle.router} 
     navigationBarStyle={navBarStyle.navBar} 
     titleStyle={navBarStyle.navTitle} 
     leftButtonStyle={navBarStyle.leftButtonStyle} 
     drawerImage={hamburgerIcon}> 
    <Scene 
     key='History' 
     component={History} 
     title='History' 
     type='reset' 
     rightButtonImage={mailIcon} 
     onRight={this.sendMail} <-- ON THIS 
     rightButtonStyle={navBarStyle.rightButtonStyle} 
     rightButtonIconStyle={navBarStyle.rightButtonIconStyle} /> 
</Router> 

(History.js):

openModal() { 
    this.setState({modalVisible: true}); <-- DO THIS 
} 
closeModal() { 
    this.setState({modalVisible: false}); 
} 
+1

Actions.History({modalVisible:true})またはActions.refresh({modalVisible:true})を使用するのはどうでしょう。次に、componentWillReceivePropsの変更を監視します。 –

+0

それは動作します!特に私は で修正しました。 'sendMail(){ Actions.refresh(); } '私のルータで、 ' componentWillReceiveProps(){ this.toggleModal(); } toggleModal(){ this.setState({modalVisible:!this.state.modalVisible}); } ' のシーンで、私はそれを受け入れることができるように答えを投稿してください:) – Haruspik

答えて

2

あなたがアクティブなシーンの小道具をリフレッシュするためにActions.refreshを使用することができます。私はこのルータパッケージについているときにエスケープハッチとして使用しました。

componentWillReceivePropsの理由と時期を知っておくと、意図的にtoggleModalを呼び出さないようにします。

関連する問題