Skip to content

Commit 2ea2245

Browse files
committed
fix(UIExplorer): Remove NavigationExperimental from Windows UIExplorer
1 parent bd47a3e commit 2ea2245

File tree

2 files changed

+58
-69
lines changed

2 files changed

+58
-69
lines changed

UIExplorer/js/UIExplorerApp.windows.js

Lines changed: 58 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -33,55 +33,52 @@ const React = require('react');
3333
const StatusBar = require('StatusBar');
3434
const StyleSheet = require('StyleSheet');
3535
const ToolbarAndroid = require('ToolbarAndroid');
36+
const UIExplorerActions = require('./UIExplorerActions');
3637
const UIExplorerExampleContainer = require('./UIExplorerExampleContainer');
3738
const UIExplorerExampleList = require('./UIExplorerExampleList');
3839
const UIExplorerList = require('./UIExplorerList');
3940
const UIExplorerNavigationReducer = require('./UIExplorerNavigationReducer');
40-
const UIExplorerStateTitleMap = require('./UIExplorerStateTitleMap');
4141
const UIExplorerHeaderWindows = require('./UIExplorerHeaderWindows');
42+
const UIManager = require('UIManager');
4243
const URIActionMap = require('./URIActionMap');
4344
const View = require('View');
4445

45-
import type {UIExplorerNavigationState} from './UIExplorerNavigationReducer';
46+
import type { UIExplorerNavigationState } from './UIExplorerNavigationReducer';
4647

4748
const DRAWER_WIDTH_LEFT = 56;
4849

4950
type Props = {
5051
exampleFromAppetizeParams: string,
5152
};
5253

53-
type State = UIExplorerNavigationState & {
54-
externalExample: ?string,
55-
};
54+
const APP_STATE_KEY = 'UIExplorerAppState.v2';
5655

5756
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;
6659

6760
componentWillMount() {
6861
BackAndroid.addEventListener('hardwareBackPress', this._handleBackButtonPress.bind(this));
6962
}
7063

7164
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+
});
8582
});
8683
}
8784

@@ -108,7 +105,7 @@ class UIExplorerApp extends React.Component {
108105
);
109106
}
110107

111-
_renderPaneContent() {
108+
_renderPaneContent = () => {
112109
return (
113110
<View style={styles.paneContentWrapper}>
114111
<UIExplorerExampleList
@@ -119,72 +116,68 @@ class UIExplorerApp extends React.Component {
119116
/>
120117
</View>
121118
);
122-
}
119+
};
123120

124121
_renderApp() {
125122
const {
126-
externalExample,
127-
stack,
123+
openExample,
128124
} = 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+
}}
155134
ref={(example) => { this._exampleRef = example; }}
156135
/>
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+
}
159152
}
153+
160154
return (
161155
<View style={styles.container}>
162156
<UIExplorerHeaderWindows
163157
onPress={() => this.splitView.openPane()}
164-
title={title}
158+
title="UIExplorer"
165159
style={styles.header}
166160
/>
167161
<UIExplorerExampleList
168162
onNavigate={this._handleAction}
169163
list={UIExplorerList}
170-
{...stack.routes[0]}
171164
/>
172165
</View>
173166
);
174167
}
175168

176-
_handleAction(action: Object): boolean {
169+
_handleAction = (action: Object): boolean => {
177170
this.splitView && this.splitView.closePane();
178171
const newState = UIExplorerNavigationReducer(this.state, action);
179172
if (this.state !== newState) {
180173
this.setState(
181174
newState,
182-
() => AsyncStorage.setItem('UIExplorerAppState', JSON.stringify(this.state))
175+
() => AsyncStorage.setItem(APP_STATE_KEY, JSON.stringify(this.state))
183176
);
184177
return true;
185178
}
186179
return false;
187-
}
180+
};
188181

189182
_handleBackButtonPress() {
190183
if (this._overrideBackPressForPane) {
@@ -201,8 +194,8 @@ class UIExplorerApp extends React.Component {
201194
) {
202195
return true;
203196
}
204-
return this._handleAction({ type: 'BackAction' });
205-
}
197+
return this._handleAction(UIExplorerActions.Back());
198+
};
206199
}
207200

208201
const styles = StyleSheet.create({

UIExplorer/js/UIExplorerList.windows.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,6 @@ const APIExamples = [
140140
key: 'NativeAnimationsExample',
141141
module: require('./NativeAnimationsExample'),
142142
},
143-
{
144-
key: 'NavigationExperimentalExample',
145-
module: require('./NavigationExperimental/NavigationExperimentalExample'),
146-
},
147143
{
148144
key: 'NetInfoExample',
149145
module: require('./NetInfoExample'),

0 commit comments

Comments
 (0)