1- <img alt =" React Navigation Helpers " src =" https://github.com/WrathChaos/react-navigation-helpers/blob/master/ assets/logo.png" width =" 1050 " />
1+ <img alt =" React Navigation Helpers " src =" assets/logo.png " width =" 1050 " />
22
3- Helpers for React Navigation.
3+ [ ![ Battle Tested ✅] ( https://img.shields.io/badge/-Battle--Tested%20%E2%9C%85-03666e?style=for-the-badge )] ( https://github.com/WrathChaos/react-navigation-helpers )
4+
5+ [ ![ Helpers for React Navigation] ( https://img.shields.io/badge/-Helpers%20for%20React%20Navigation-orange?style=for-the-badge )] ( https://github.com/WrathChaos/react-navigation-helpers )
46
57[ ![ npm version] ( https://img.shields.io/npm/v/react-navigation-helpers.svg?style=for-the-badge )] ( https://www.npmjs.com/package/react-navigation-helpers )
68[ ![ npm] ( https://img.shields.io/npm/dt/react-navigation-helpers.svg?style=for-the-badge )] ( https://www.npmjs.com/package/react-navigation-helpers )
@@ -20,96 +22,121 @@ npm i react-navigation-helpers
2022
2123## Peer Dependencies
2224
23- ###### IMPORTANT! You need install them.
25+ < i >< b > IMPORTANT!</ b > You need install them.</ i >
2426
25- ```
27+ ``` json
2628"react" : " >= 16.x.x" ,
27- "react-navigation": ">= 3 .x.x"
29+ "react-navigation" : " >= 5 .x.x"
2830```
2931
32+ ## React Navigation Versions
33+
34+ - Use ** v0.2.0+** for ReactNavigation ** v5**
35+ - Use ** v0.1.0+** for ReactNavigation ** v4**
36+
3037## Usage
3138
3239### Global Level Navigator
3340
34- < b >Firstly</ b > set the global level navigator reference
41+ Set the global level navigation reference into the ` NavigationContainer `
3542
3643``` js
3744import NavigationService from " react-navigation-helpers" ;
38-
39-
40- < MainNavigator
41- ref= {navigatorRef =>
42- NavigationService .setGlobalLevelNavigator (navigatorRef)
43- }
44- / >
45+ import { isReadyRef , navigationRef } from " react-navigation-helpers" ;
46+
47+ React .useEffect (() => {
48+ return () => (isReadyRef .current = false );
49+ }, []);
50+
51+ < NavigationContainer
52+ ref= {navigationRef}
53+ onReady= {() => {
54+ isReadyRef .current = true ;
55+ }}
56+ >
57+ {/* ... */ }
58+ < / NavigationContainer> ;
4559```
4660
47- ### NavigationService Usage
61+ ## NavigationService Usage
4862
49- #### Navigate Example
63+ ### Navigate Example
5064
5165``` js
52- NavigationService .navigate (" home" )
66+ import * as NavigationService from " react-navigation-helpers" ;
67+
68+ NavigationService .navigate (" home" );
5369```
5470
55- #### Push Example
71+ ### Push Example
5672
5773``` js
58- NavigationService .push (" home" )
74+ import * as NavigationService from " react-navigation-helpers" ;
75+
76+ NavigationService .push (" home" );
5977```
6078
61- #### Pop Example
79+ ### Pop Example
6280
6381``` js
64- NavigationService .pop ()
82+ import * as NavigationService from " react-navigation-helpers" ;
83+
84+ NavigationService .pop ();
6585```
6686
67- #### PopToTop Example
87+ ### PopToTop Example
6888
6989``` js
70- NavigationService .popToTop ()
90+ import * as NavigationService from " react-navigation-helpers" ;
91+
92+ NavigationService .popToTop ();
7193```
7294
73- #### Back Example
95+ ### Back Example
7496
7597``` js
76- NavigationService .back ()
98+ import * as NavigationService from " react-navigation-helpers" ;
99+
100+ NavigationService .back ();
77101```
78102
79103## How to pass prop with this library?
80104
81105The usage does not change. Simply put your prop as the secondary prop ** as same as React Navigation** itself.
82106
83- #### Navigate
107+ ### Navigate
108+
84109``` js
85- NavigationService .navigate (" home" , {data: myData, myId: " d1f01df1" })
110+ import * as NavigationService from " react-navigation-helpers" ;
111+
112+ NavigationService .navigate (" home" , { data: myData, myId: " d1f01df1" });
86113```
87114
88- #### Push
115+ ### Push
116+
89117``` js
90- NavigationService .push (" home" , {data: myData, myId: " d1f01df1" })
91- ```
118+ import * as NavigationService from " react-navigation-helpers" ;
92119
120+ NavigationService .push (" home" , { data: myData, myId: " d1f01df1" });
121+ ```
93122
94123## How to receive the passed props from navigation or push functions?
95124
96125``` js
97- const data = props .navigation .getParam (" data" , null ) // Second one is default value
98- const myId = props .navigation .getParam (" myId" , " " ) // Second one is default value
126+ const data = props .navigation .getParam (" data" , null ); // Second one is default value
127+ const myId = props .navigation .getParam (" myId" , " " ); // Second one is default value
99128```
100129
101130### Configuration - Props
102131
103- | Property | Type | Default | Description |
104- | ----------------------- | :------: | :------: | -------------------------------------- |
105- | setGlobalLevelNavigator | function | function | set your global level navigator (MUST) |
106- | navigate | function | function | navigate the selected screen |
107- | push | function | function | push the selected screen |
108- | back | function | function | back the previous screen |
109- | pop | function | function | pop the previous screen |
110- | popToTop | function | function | pop the top level of the screen |
111- | reset | function | function | reset the navigator |
112-
132+ | Property | Type | Default | Description |
133+ | -------- | :------: | :------: | ------------------------------- |
134+ | navigate | function | function | navigate the selected screen |
135+ | push | function | function | push the selected screen |
136+ | goBack | function | function | back the previous screen |
137+ | pop | function | function | pop the previous screen |
138+ | popToTop | function | function | pop the top level of the screen |
139+ | reset | function | function | reset the navigator |
113140
114141### ToDos
115142
0 commit comments