@@ -33,55 +33,52 @@ const React = require('react');
33
33
const StatusBar = require ( 'StatusBar' ) ;
34
34
const StyleSheet = require ( 'StyleSheet' ) ;
35
35
const ToolbarAndroid = require ( 'ToolbarAndroid' ) ;
36
+ const UIExplorerActions = require ( './UIExplorerActions' ) ;
36
37
const UIExplorerExampleContainer = require ( './UIExplorerExampleContainer' ) ;
37
38
const UIExplorerExampleList = require ( './UIExplorerExampleList' ) ;
38
39
const UIExplorerList = require ( './UIExplorerList' ) ;
39
40
const UIExplorerNavigationReducer = require ( './UIExplorerNavigationReducer' ) ;
40
- const UIExplorerStateTitleMap = require ( './UIExplorerStateTitleMap' ) ;
41
41
const UIExplorerHeaderWindows = require ( './UIExplorerHeaderWindows' ) ;
42
+ const UIManager = require ( 'UIManager' ) ;
42
43
const URIActionMap = require ( './URIActionMap' ) ;
43
44
const View = require ( 'View' ) ;
44
45
45
- import type { UIExplorerNavigationState } from './UIExplorerNavigationReducer' ;
46
+ import type { UIExplorerNavigationState } from './UIExplorerNavigationReducer' ;
46
47
47
48
const DRAWER_WIDTH_LEFT = 56 ;
48
49
49
50
type Props = {
50
51
exampleFromAppetizeParams : string ,
51
52
} ;
52
53
53
- type State = UIExplorerNavigationState & {
54
- externalExample : ?string ,
55
- } ;
54
+ const APP_STATE_KEY = 'UIExplorerAppState.v2' ;
56
55
57
56
class UIExplorerApp extends React . Component {
58
- _handleAction : Function ;
59
- _renderPaneContent : Function ;
60
- state : State ;
61
- constructor ( props : Props ) {
62
- super ( props ) ;
63
- this . _handleAction = this . _handleAction . bind ( this ) ;
64
- this . _renderPaneContent = this . _renderPaneContent . bind ( this ) ;
65
- }
57
+ props : Props ;
58
+ state : UIExplorerNavigationState ;
66
59
67
60
componentWillMount ( ) {
68
61
BackAndroid . addEventListener ( 'hardwareBackPress' , this . _handleBackButtonPress . bind ( this ) ) ;
69
62
}
70
63
71
64
componentDidMount ( ) {
72
- AsyncStorage . getItem ( 'UIExplorerAppState' , ( err , storedString ) => {
73
- const exampleAction = URIActionMap ( this . props . exampleFromAppetizeParams ) ;
74
- if ( err || ! storedString ) {
75
- const initialAction = exampleAction || { type : 'InitialAction' } ;
76
- this . setState ( UIExplorerNavigationReducer ( null , initialAction ) ) ;
77
- return ;
78
- }
79
- const storedState = JSON . parse ( storedString ) ;
80
- if ( exampleAction ) {
81
- this . setState ( UIExplorerNavigationReducer ( storedState , exampleAction ) ) ;
82
- return ;
83
- }
84
- this . setState ( storedState ) ;
65
+ Linking . getInitialURL ( ) . then ( ( url ) => {
66
+ AsyncStorage . getItem ( APP_STATE_KEY , ( err , storedString ) => {
67
+ const exampleAction = URIActionMap ( this . props . exampleFromAppetizeParams ) ;
68
+ const urlAction = URIActionMap ( url ) ;
69
+ const launchAction = exampleAction || urlAction ;
70
+ if ( err || ! storedString ) {
71
+ const initialAction = launchAction || { type : 'InitialAction' } ;
72
+ this . setState ( UIExplorerNavigationReducer ( null , initialAction ) ) ;
73
+ return ;
74
+ }
75
+ const storedState = JSON . parse ( storedString ) ;
76
+ if ( launchAction ) {
77
+ this . setState ( UIExplorerNavigationReducer ( storedState , launchAction ) ) ;
78
+ return ;
79
+ }
80
+ this . setState ( storedState ) ;
81
+ } ) ;
85
82
} ) ;
86
83
}
87
84
@@ -108,7 +105,7 @@ class UIExplorerApp extends React.Component {
108
105
) ;
109
106
}
110
107
111
- _renderPaneContent ( ) {
108
+ _renderPaneContent = ( ) => {
112
109
return (
113
110
< View style = { styles . paneContentWrapper } >
114
111
< UIExplorerExampleList
@@ -119,72 +116,68 @@ class UIExplorerApp extends React.Component {
119
116
/>
120
117
</ View >
121
118
) ;
122
- }
119
+ } ;
123
120
124
121
_renderApp ( ) {
125
122
const {
126
- externalExample,
127
- stack,
123
+ openExample,
128
124
} = this . state ;
129
- if ( externalExample ) {
130
- const Component = UIExplorerList . Modules [ externalExample ] ;
131
- return (
132
- < Component
133
- onExampleExit = { ( ) => {
134
- this . _handleAction ( { type : 'BackAction' } ) ;
135
- } }
136
- ref = { ( example ) => { this . _exampleRef = example ; } }
137
- />
138
- ) ;
139
- }
140
- const title = UIExplorerStateTitleMap ( stack . routes [ stack . index ] ) ;
141
- const index = stack . routes . length <= 1 ? 1 : stack . index ;
142
-
143
- if ( stack && stack . routes [ index ] ) {
144
- const { key} = stack . routes [ index ] ;
145
- const ExampleModule = UIExplorerList . Modules [ key ] ;
146
- return (
147
- < View style = { styles . container } >
148
- < UIExplorerHeaderWindows
149
- onPress = { ( ) => this . splitView . openPane ( ) }
150
- title = { title }
151
- style = { styles . header }
152
- />
153
- < UIExplorerExampleContainer
154
- module = { ExampleModule }
125
+
126
+ if ( openExample ) {
127
+ const ExampleModule = UIExplorerList . Modules [ openExample ] ;
128
+ if ( ExampleModule . external ) {
129
+ return (
130
+ < ExampleModule
131
+ onExampleExit = { ( ) => {
132
+ this . _handleAction ( UIExplorerActions . Back ( ) ) ;
133
+ } }
155
134
ref = { ( example ) => { this . _exampleRef = example ; } }
156
135
/>
157
- </ View >
158
- ) ;
136
+ ) ;
137
+ } else if ( ExampleModule ) {
138
+ return (
139
+ < View style = { styles . container } >
140
+ < UIExplorerHeaderWindows
141
+ onPress = { ( ) => this . splitView . openPane ( ) }
142
+ title = { ExampleModule . title }
143
+ style = { styles . header }
144
+ />
145
+ < UIExplorerExampleContainer
146
+ module = { ExampleModule }
147
+ ref = { ( example ) => { this . _exampleRef = example ; } }
148
+ />
149
+ </ View >
150
+ ) ;
151
+ }
159
152
}
153
+
160
154
return (
161
155
< View style = { styles . container } >
162
156
< UIExplorerHeaderWindows
163
157
onPress = { ( ) => this . splitView . openPane ( ) }
164
- title = { title }
158
+ title = "UIExplorer"
165
159
style = { styles . header }
166
160
/>
167
161
< UIExplorerExampleList
168
162
onNavigate = { this . _handleAction }
169
163
list = { UIExplorerList }
170
- { ...stack . routes [ 0 ] }
171
164
/>
172
165
</ View >
173
166
) ;
174
167
}
175
168
176
- _handleAction ( action : Object ) : boolean {
169
+ _handleAction = ( action : Object ) : boolean => {
177
170
this . splitView && this . splitView . closePane ( ) ;
178
171
const newState = UIExplorerNavigationReducer ( this . state , action ) ;
179
172
if ( this . state !== newState ) {
180
173
this . setState (
181
174
newState ,
182
- ( ) => AsyncStorage . setItem ( 'UIExplorerAppState' , JSON . stringify ( this . state ) )
175
+ ( ) => AsyncStorage . setItem ( APP_STATE_KEY , JSON . stringify ( this . state ) )
183
176
) ;
184
177
return true ;
185
178
}
186
179
return false ;
187
- }
180
+ } ;
188
181
189
182
_handleBackButtonPress ( ) {
190
183
if ( this . _overrideBackPressForPane ) {
@@ -201,8 +194,8 @@ class UIExplorerApp extends React.Component {
201
194
) {
202
195
return true ;
203
196
}
204
- return this . _handleAction ( { type : 'BackAction' } ) ;
205
- }
197
+ return this . _handleAction ( UIExplorerActions . Back ( ) ) ;
198
+ } ;
206
199
}
207
200
208
201
const styles = StyleSheet . create ( {
0 commit comments