Using Static on Methods with HOCs
This is just a helpful tip for anyone who use the onExit/onEnter methods as a static method in their Component Class. Please refer to this link https://reactjs.org/docs/higher-order-components.html.
If your Scene Components are Wrapped in Custom HOCs/ Decorators, then the static onExit/onEnter methods will not work as your Custom HOCs will not copy the static methods over to your Enhanced Component.
Use this npm package called hoist-non-react-statics to copy your Component level static methods over to your Enhanced Component.
Implement onBack from your Scene and not while declaring the Scene
If you have a Scene where in you want to make some changes to your Component State when Back button is pressed, then doing this <Scene key={...} component={...} onBack={()=>/*code*/}/> will not help.
<Scene key={...} component={...} onBack={()=>/*code*/} back={true}/> Make sure back = true is passed to your scene, now in your Component's lifecycle add this
componentDidMount(){
setTimeout(()=> {
Actions.refresh({onBack:()=>this.changeSomethingInYourComponent()})
})
}
I want to create the private scene which redirects User to the login page
Can you make an example, please?
In case of animations and refresh props, it's better to use
const params = { onBack: this.onBack, onRight: this.onRight }
InteractionManager.runAfterInteractions(() => {
Actions.refresh(params);
});
because
InteractionManager allows long-running work to be scheduled after any interactions/animations have completed
Yes InteracionManager is a better way to do it than setTimeout
@shubhang93 Great tips, thanks! It would be great if you can submit documentation PR
@shubhang93 Great tips, thanks! It would be great if you can submit documentation PR
PR submitted, please go through it.
@mahyar33 did you ever figure out how to do that?