Open AlanSl opened 4 years ago
Another possibility is React Native Navigation, which is also endorsed by the official React Native docs. The main benefit of React Native Navigation is that it uses purely-native navigation with a thin JavaScript layer, whereas React Navigation does more in Javascript and React components.
As I see it that is probably more of a drawback than a benefit for us:
However with the approach of forking platforms in a hook, it should be possible that if a rare project did have very niche navigation needs, it should be possible to swap RNN in only changing the logic in the .native.ts
custom hook (after getting RNN working with the main infrastructure, which appears to be non-trivial).
Most other React Native navigation libraries appear to be simply opinionated layers on top of React Navigation.
React Router Native is different and interesting but appears to not help us get native transitions, which is the main thing we want.
React Native Screens looks like it might be worth using alongside React Navigation. It brings in more native components than React Navigation and appears to integrate well with the rest of our stack. I'll try it and see if it improves things. It's already integrated into React Navigation 5.X
React Navigation is bringing in web support, but it doesn't look ready for production yet. After just 5 minutes playing around with https://react-navigation-example.netlify.app/ I had got it in a state where the browser back button had stopped working.
The changes proposed here are to be implemented and tested in the Polaris Shopping demo app first, then, if they work as expected there, backported here.
The current approach to routing has been the same since the first commit to https://github.com/nearform/open-banking-reference-app-original-private in May 2019:
routing.web.ts
exports directly from React Router DOM androuting.native.ts
exports the same names, but directly from React Router Navigation.My proposal is to use an approach similar to what is described here - https://www.ythecombinator.space/posts/driving-towards-a-universal-navigation-strategy-in-react - based on a case very similar to ours, written on 2020.
Essentially the approach is:
navigate
function. Maybe call itusePlatformNav
, notuseNavigation
like in the article, because that is the name of a React Navigation hook.usePlatformNav.native.ts
would use React Navigation to its full potential without trying to make it look like a DOM router, andusePlatformNav.web.ts
would use React Router DOMusePlatformRoute
probably) that returns the same types on all platforms but gets it using the platform's own routing libraryBenefits of this approach:
We're using the recommended routing packages for both React web and React Native
We don't have any constraints in what platform-specific refinements we apply
Implementations of Polaris can modify these hooks for project-specific routing needs in just one location so long as it returns the same types
Components and hooks that use routing can continue to have one routing interface that works on all platforms
There's a documented case study of it working in production for an app with similar needs to ours
It's a good accelerator feature: a solution to a common problem that can be modified for project specific needs and doesn't add constraints
Drawbacks of this approach:
It requires a little work implementing the hooks, whereas the previous approach was almost out-of-the-box, but given the benefits, this gives us another small unique selling point for the accelerators
It will need documenting (but we should be documenting and explaining our approach to things like this anyway)
There are some reported issues with React Navigation (e.g. performance), but this appears to have improved in the last couple of years (especially with 5.X, released Feb 2020)