React-native-router-flux: is there any way to listen onRight event in scene component?

Created on 26 Aug 2016  路  7Comments  路  Source: aksonov/react-native-router-flux

Version

Tell us which versions you are using:

  • react-native-router-flux v3.34.0
  • react-native v0.30.0

Expected behaviour

I want to do something after onRight event in scene's component. I think it is not suitable to do component logic in root scene. use action? can i override onRight in subcomponent?

Actual behaviour

question

Most helpful comment

try this:

<Scene
  component={CustomerCheckListView}
  title="test" rightTitle="confirm" onRight={(scene, proxy) => {
    scene.component.WrappedComponent.prototype.confirm();
  }}
/>

and have confirm method in your component.

All 7 comments

Yes this can be overrided at scene level.

var tabSceneMenu = {
      onLeft :()=>{ MenuActions.openMenu() },
      leftButtonImage:leftImage,
      getLeftTitle:this.getLeftTitle, 
      getRightTitle:this.getRightTitle,
      onRight :()=>{MenuActions.openRightMenu();} 
    }

<Scene key="newTab" {...tabSceneMenu} passProps={true} component={YourComponent} title="Title" ></Scene>

How can you use MenuActions inside YourComponent?

try this:

<Scene
  component={CustomerCheckListView}
  title="test" rightTitle="confirm" onRight={(scene, proxy) => {
    scene.component.WrappedComponent.prototype.confirm();
  }}
/>

and have confirm method in your component.

scene.component.WrappedComponent.prototype.confirm() - worked, but the props of the component are not visible in the called component method, any suggestions!!

many developers call Actions.refresh() method in componentWillMount to override onRight/onLeft/onCancel method.

Actions.refresh({rightTitle: "foo", onRight: this._save});

u can refer to this issue: https://github.com/aksonov/react-native-router-flux/issues/634

Given current Renderer of Scene is stateless, I think this is the only way to get component context in onRight/onLeft method.
someone said this workaround might have side effects like double render?? I haven't tested it since everything works fine and performance is not affected at all...

Thanks zichong.

Calling Actions.refresh({rightTitle: "foo", onRight: this._save}) method in componentWillMount works but if in your app will you call Actions.NAME_SCENE this will cause calling scene componentWillMount over and over

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wootwoot1234 picture wootwoot1234  路  3Comments

booboothefool picture booboothefool  路  3Comments

VictorK1902 picture VictorK1902  路  3Comments

llgoer picture llgoer  路  3Comments

jgibbons picture jgibbons  路  3Comments