You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 18, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+120-3Lines changed: 120 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,20 @@
1
1
# react-navigation-redux-helpers
2
2
3
-
This repo contains Redux middleware and utils for React Navigation.
3
+
This package allows the user to manage their React Navigation state from within Redux.
4
+
5
+
## How it works
6
+
7
+
1. Any navigator can be passed a `navigation` prop to turn it into a "controlled" component, which defers state management to its parent. This mechanism is used in React Navigation to nest navigators, but it can also be used to customize state management.
8
+
2. A Redux middleware is used so that any events that mutate the navigation state properly trigger React Navigation's event listeners.
9
+
3. Finally, a reducer enables React Navigation actions to mutate the Redux state.
10
+
11
+
## Motivation
12
+
13
+
Most projects that are using both Redux and React Navigation don't need this library. And passing `navigation` to the root navigator means that you will have to handle state persistance and `BackHandler` behavior yourself. However, there are some things you can do with this library that you can't do without:
14
+
15
+
1. It's possible to implement [custom actions](https://github.com/Ashoat/squadcal/blob/4ce900481bbfd1681d568edc669b66b1ae9555f0/native/navigation/navigation-setup.js#L384-L395), allowing you to manipulate the navigation state in ways that aren't possible with the stock React Navigation actions. (If you want animations to run on your action, [make sure](https://github.com/Ashoat/squadcal/blob/4ce900481bbfd1681d568edc669b66b1ae9555f0/native/navigation/navigation-setup.js#L633) to set `isTransitioning` to true!)
16
+
2. This library allows the user to customize the persistance of their navigation state. For instance, you could choose to persist your navigation state in encrypted storage. Most users don't need this, as there are no practical downsides to handling persistance of navigation state and Redux state separately.
17
+
3. You can implement [custom reducer behavior](https://github.com/Ashoat/squadcal/blob/4ce900481bbfd1681d568edc669b66b1ae9555f0/native/navigation/navigation-setup.js#L341-L352) to validate state and maintain consistency between navigation state and other application state.
4
18
5
19
## Installation
6
20
@@ -14,9 +28,60 @@ This repo contains Redux middleware and utils for React Navigation.
14
28
npm install --save react-navigation-redux-helpers
15
29
```
16
30
17
-
## Use
31
+
## Example
18
32
19
-
Consult the [React Navigation](https://reactnavigation.org/docs/redux-integration.html) docs for how to use this library.
@@ -58,3 +123,55 @@ function createNavigationReducer(navigator: Navigator): Reducer<*, *>;
58
123
* This basically just wraps `navigator.router.getStateForAction`, which you can call directly if you'd prefer.
59
124
* Param `navigator` is your root navigator (React component).
60
125
* Call this reducer from your master reducer, or combine using `combineReducers`.
126
+
127
+
## Miscellaneous
128
+
129
+
### Mocking tests
130
+
131
+
To make Jest tests work with your React Navigation app, you need to [change the Jest preset](https://jestjs.io/docs/en/tutorial-react-native) in your `package.json`:
0 commit comments