Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible navigation issue in React Native/Redux app

During navigation in big React Native app with using Redux all visited scenes (scenes from navigation stack) are staying mounted. All these scenes receive props and get rendered in the order they were visited when any action is dispatched from last scene component. It causes freezes and visible delays between dispatching and last scene rendering.

For navigation I am using react-native-router-flux but same issue happens with original React Native Navigator too.

Video Possible navigation issues in React Native/Redux app

Code react-redux-navigation-test

Would be nice to know how to prevent passing props to not focused components from the navigation chain.

At the moment I am checking in shouldComponentUpdate of each component if this one is focused(visible) and return false in opposite case.

Is there any better solution?

like image 389
alexsh Avatar asked Aug 02 '16 18:08

alexsh


People also ask

Why my react navigation is not working?

A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native. ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication).

How do I get navigation back in React Native?

The header bar will automatically show a back button, but you can programmatically go back by calling navigation.goBack() .


1 Answers

I recommend that you calculate the scene distance between the current scene and scene being rendered using the navigation index in the scene and header rendering methods. If the distance > 1 return null.

This should prevent rendering the entire navigation history. It doesn't make any sense to me that this kind of behaviour is not available out of the box, but there it is.

like image 159
Marc Avatar answered Oct 03 '22 19:10

Marc