-
Notifications
You must be signed in to change notification settings - Fork 2
Navigation module
Basically, there are 2 main navigation libraries for bare react-native projects, react-navigation, and react-native-navigation. Each of them has its own benefits. If we shortly compare them, react-native-navigation provides us with the full native implementation of the navigation. All the navigation views and screens are implemented natively. On the other hand, react-navigation is implemented mostly on the JS side using a couple of native libraries in order to boost the performance. Of course, it's important to make the right choice, but simply put, react-navigation is more stable, more flexible, and configurable. In the future, it'll endure react-native-navigation. So, react-navigation is used in this project.
Try to decompose the stacks of the screens. For example, if your application has multiple roles, then each role should have its own stack. The authentication process could also have its own stack.
Try to follow the next recommendations in order to follow the best practices:
- Keep all the screens in the
screensfolder. - Try to keep the components that represent screens clean and simple. Don't implement any complex logic, these should be just simple files.
- Don't put any large objects to navigation params. These should be some primitive variables.
- Don't put navigation params to the child components. They can be obtained using the
useRoutehook in child components. - If a screen contains some title then send it through the navigation params and then display it in the stack navigator.
In order to add a new screen, follow the next steps:
- Add a new
constantthat represents the screen to theconfig.tsfile. You can check the example for countries module; - Add a new
navigation paramstype to thetypes.tsfile. Check the examples for countries module. It should beundefinedif the screen doesn't receive any params; - Add
navigationandroutetypes to thetypes.tsfile. Check the examples for countries module; - Create a new component that represents a screen and import it in the root
index.tsfile. You can use CountriesScreen as an example; - Import
screen nameandnavigation paramsto ApplicationParams; - Register a new screen in the
stack navigator. Check the example for ApplicationStack.ts.