使用React-Native-Router-Flux从navBar按钮传递道具

时间:2017-05-24 20:06:13

标签: javascript reactjs react-native react-native-router-flux

我使用react-native-router-flux进行了相当充实的项目,并尝试通过props传递对象。通常情况下,我可以致电Actions.someKey({ someProp: object })进行导航,但我尝试使用rightButtonImage进行导航,但无法访问该组件props

例如:

Router.js

<Router>
  <Scene1
    rightButtonImage={someImage}
    onRight={() => Actions.sceneTwo()}
  />
  <Scene2 key="sceneTwo" />
</Router>

当我移动到Scene2时,我想传递一个Scene1&#39组件有权访问的对象。

1 个答案:

答案 0 :(得分:1)

它对您有所帮助: 在每个组件中,即在componentDidMount中,您可以执行以下操作:

Actions.refresh({
 rightTitle: "Next",
 rightButtonTextStyle: {color: 'red'},
 onRight: this.goSomewhere, 
 rightButtonImage: someImage
})