|
2 | 2 | import React from 'react'; |
3 | 3 | import type { |
4 | 4 | NavigationAction, |
5 | | - NavigationNavigatorProps, |
6 | 5 | NavigationState, |
7 | | - NavigationDispatch, |
8 | | - SupportedThemes, |
| 6 | + NavigationContainer, |
| 7 | + NavigationContainerProps, |
9 | 8 | } from 'react-navigation'; |
10 | 9 |
|
11 | | -type ReduxContainerProps = { |
12 | | - ...$Diff<NavigationNavigatorProps<{ ... }, NavigationState>, { navigation: mixed }>, |
13 | | - state: NavigationState, |
14 | | - dispatch: NavigationDispatch, |
15 | | - theme: SupportedThemes | 'no-preference', |
16 | | -}; |
17 | | - |
18 | | -// Should mimic return type of react-navigation-redux-helpers's |
19 | | -// `createReduxContainer`. |
20 | | -type ReduxContainer = React$Component<ReduxContainerProps>; |
21 | | - |
22 | | -// TODO: This will eventually be a ref to the component instance |
23 | | -// created by React Navigation's `createAppContainer`, not |
24 | | -// react-navigation-redux-helpers's `createReduxContainer`. |
25 | | -const reduxContainerRef = React.createRef<ReduxContainer>(); |
| 10 | +/* prettier-ignore */ |
| 11 | +const appContainerRef = React.createRef< |
| 12 | + React$ElementRef< |
| 13 | + NavigationContainer< |
| 14 | + NavigationState, |
| 15 | + { ... }, |
| 16 | + NavigationContainerProps<{ ... }, NavigationState>>> |
| 17 | +>(); |
26 | 18 |
|
27 | 19 | const getState = (): NavigationState => { |
28 | | - if (reduxContainerRef.current === null) { |
29 | | - throw new Error('Tried to use NavigationService before reduxContainerRef was set.'); |
| 20 | + if (appContainerRef.current === null) { |
| 21 | + throw new Error('Tried to use NavigationService before appContainerRef was set.'); |
30 | 22 | } |
31 | | - return ( |
32 | | - reduxContainerRef.current |
33 | | - // $FlowFixMe - how to tell Flow about this method? |
34 | | - .getCurrentNavigation().state |
35 | | - ); |
| 23 | + return appContainerRef.current.state.nav; |
36 | 24 | }; |
37 | 25 |
|
38 | 26 | const dispatch = (navigationAction: NavigationAction): boolean => { |
39 | | - if (reduxContainerRef.current === null) { |
40 | | - throw new Error('Tried to use NavigationService before reduxContainerRef was set.'); |
| 27 | + if (appContainerRef.current === null) { |
| 28 | + throw new Error('Tried to use NavigationService before appContainerRef was set.'); |
41 | 29 | } |
42 | | - return ( |
43 | | - reduxContainerRef.current |
44 | | - // $FlowFixMe - how to tell Flow about this method? |
45 | | - .getCurrentNavigation() |
46 | | - .dispatch(navigationAction) |
47 | | - ); |
| 30 | + return appContainerRef.current.dispatch(navigationAction); |
48 | 31 | }; |
49 | 32 |
|
50 | 33 | export default { |
51 | 34 | getState, |
52 | 35 | dispatch, |
53 | | - reduxContainerRef, |
| 36 | + appContainerRef, |
54 | 37 | }; |
0 commit comments