13
13
14
14
const AsyncStorage = require ( 'AsyncStorage' ) ;
15
15
const Linking = require ( 'Linking' ) ;
16
+ const NavigationPropTypes = require ( 'NavigationPropTypes' ) ;
17
+ const NavigationStateUtils = require ( 'NavigationStateUtils' ) ;
16
18
const Platform = require ( 'Platform' ) ;
17
19
const React = require ( 'React' ) ;
18
- const NavigationPropTypes = require ( 'NavigationPropTypes' ) ;
19
20
20
21
import type {
21
22
NavigationAction ,
23
+ NavigationParentState ,
22
24
NavigationReducer ,
23
25
NavigationRenderer ,
24
26
} from 'NavigationTypeDefinition' ;
@@ -27,10 +29,6 @@ export type BackAction = {
27
29
type : 'BackAction' ,
28
30
} ;
29
31
30
- function getBackAction ( ) : BackAction {
31
- return { type : 'BackAction' } ;
32
- }
33
-
34
32
type Props = {
35
33
/*
36
34
* The default action to be passed into the reducer when getting the first
@@ -65,39 +63,56 @@ type Props = {
65
63
renderNavigation : NavigationRenderer ,
66
64
} ;
67
65
68
- const { PropTypes} = React ;
69
-
70
- const propTypes = {
71
- initialAction : NavigationPropTypes . action . isRequired ,
72
- linkingActionMap : PropTypes . func ,
73
- persistenceKey : PropTypes . string ,
74
- reducer : PropTypes . func . isRequired ,
75
- renderNavigation : PropTypes . func . isRequired ,
66
+ type State = {
67
+ navState : ?NavigationParentState ,
76
68
} ;
77
69
78
- const defaultProps = {
79
- initialAction : {
80
- type : 'RootContainerInitialAction' ,
81
- } ,
82
- } ;
70
+ function getBackAction ( ) : BackAction {
71
+ return { type : 'BackAction' } ;
72
+ }
73
+
74
+ const { PropTypes } = React ;
83
75
84
- class NavigationRootContainer extends React . Component {
76
+ class NavigationRootContainer extends React . Component < any , Props , State > {
85
77
_handleOpenURLEvent : Function ;
86
78
87
79
props : Props ;
80
+ state : State ;
81
+
82
+ static propTypes = {
83
+ initialAction : NavigationPropTypes . action . isRequired ,
84
+ linkingActionMap : PropTypes . func ,
85
+ persistenceKey : PropTypes . string ,
86
+ reducer : PropTypes . func . isRequired ,
87
+ renderNavigation : PropTypes . func . isRequired ,
88
+ } ;
89
+
90
+ static defaultProps = {
91
+ initialAction : { type : 'RootContainerInitialAction' } ,
92
+ } ;
93
+
94
+ static childContextTypes = {
95
+ onNavigate : PropTypes . func ,
96
+ } ;
88
97
89
98
constructor ( props : Props ) {
90
99
super ( props ) ;
91
- this . handleNavigation = this . handleNavigation . bind ( this ) ;
92
- this . _handleOpenURLEvent = this . _handleOpenURLEvent . bind ( this ) ;
100
+
93
101
let navState = null ;
94
102
if ( ! this . props . persistenceKey ) {
95
- navState = this . props . reducer ( null , props . initialAction ) ;
103
+ navState = NavigationStateUtils . getParent (
104
+ this . props . reducer ( null , props . initialAction )
105
+ ) ;
96
106
}
97
107
this . state = { navState } ;
98
108
}
99
109
100
- componentDidMount ( ) {
110
+ componentWillMount ( ) : void {
111
+ this .handleNavigation = this . handleNavigation . bind ( this ) ;
112
+ this . _handleOpenURLEvent = this . _handleOpenURLEvent . bind ( this ) ;
113
+ }
114
+
115
+ componentDidMount ( ) : void {
101
116
if ( this . props . LinkingActionMap ) {
102
117
Linking . getInitialURL ( ) . then ( this . _handleOpenURL . bind ( this ) ) ;
103
118
Platform . OS === 'ios' && Linking . addEventListener ( 'url' , this . _handleOpenURLEvent ) ;
@@ -117,15 +132,17 @@ class NavigationRootContainer extends React.Component {
117
132
}
118
133
}
119
134
120
- componentWillUnmount ( ) {
121
- Platform . OS === 'ios' && Linking . removeEventListener ( 'url' , this . _handleOpenURLEvent ) ;
135
+ componentWillUnmount ( ) : void {
136
+ if ( Platform . OS === 'ios' ) {
137
+ Linking . removeEventListener ( 'url' , this . _handleOpenURLEvent ) ;
138
+ }
122
139
}
123
140
124
- _handleOpenURLEvent ( event : { url : string } ) {
141
+ _handleOpenURLEvent ( event : { url : string } ) : void {
125
142
this . _handleOpenURL ( event . url ) ;
126
143
}
127
144
128
- _handleOpenURL ( url : ?string ) {
145
+ _handleOpenURL ( url : ?string ) : void {
129
146
if ( ! this . props . LinkingActionMap ) {
130
147
return ;
131
148
}
@@ -166,12 +183,6 @@ class NavigationRootContainer extends React.Component {
166
183
}
167
184
}
168
185
169
- NavigationRootContainer . childContextTypes = {
170
- onNavigate : PropTypes . func ,
171
- } ;
172
-
173
- NavigationRootContainer . propTypes = propTypes ;
174
- NavigationRootContainer . defaultProps = defaultProps ;
175
186
NavigationRootContainer . getBackAction = getBackAction ;
176
187
177
188
module . exports = NavigationRootContainer ;
0 commit comments