2015-01-30 01:10:49 +00:00
|
|
|
/**
|
2016-03-24 22:48:27 +00:00
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
2015-03-26 18:24:15 +00:00
|
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
|
|
* evaluation purposes only.
|
2015-03-23 22:07:33 +00:00
|
|
|
*
|
2015-03-26 18:24:15 +00:00
|
|
|
* Facebook reserves all rights not expressly granted.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2015-01-30 01:10:49 +00:00
|
|
|
*
|
|
|
|
* @providesModule UIExplorerApp
|
2016-02-23 00:15:35 +00:00
|
|
|
* @flow
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-05-05 23:51:34 +00:00
|
|
|
const AsyncStorage = require('AsyncStorage');
|
2017-03-07 05:41:51 +00:00
|
|
|
const BackHandler = require('BackHandler');
|
2016-05-05 23:51:34 +00:00
|
|
|
const Linking = require('Linking');
|
2016-04-09 03:36:40 +00:00
|
|
|
const React = require('react');
|
|
|
|
const ReactNative = require('react-native');
|
2017-02-28 23:39:24 +00:00
|
|
|
const UIExplorerActions = require('./UIExplorerActions');
|
2016-09-02 21:42:38 +00:00
|
|
|
const UIExplorerExampleContainer = require('./UIExplorerExampleContainer');
|
2016-02-23 00:15:35 +00:00
|
|
|
const UIExplorerExampleList = require('./UIExplorerExampleList');
|
2017-02-09 22:14:56 +00:00
|
|
|
const UIExplorerList = require('./UIExplorerList.ios');
|
2016-02-23 00:15:35 +00:00
|
|
|
const UIExplorerNavigationReducer = require('./UIExplorerNavigationReducer');
|
2016-04-04 13:04:54 +00:00
|
|
|
const URIActionMap = require('./URIActionMap');
|
2016-02-23 00:15:35 +00:00
|
|
|
|
2016-02-20 00:55:07 +00:00
|
|
|
const {
|
2017-02-28 23:39:24 +00:00
|
|
|
Button,
|
2015-02-19 14:57:05 +00:00
|
|
|
AppRegistry,
|
2016-02-23 00:15:35 +00:00
|
|
|
SnapshotViewIOS,
|
2015-01-30 01:10:49 +00:00
|
|
|
StyleSheet,
|
2017-02-28 23:39:24 +00:00
|
|
|
Text,
|
2016-02-03 14:40:39 +00:00
|
|
|
View,
|
2016-04-09 03:36:40 +00:00
|
|
|
} = ReactNative;
|
2016-02-29 21:21:43 +00:00
|
|
|
|
|
|
|
import type { UIExplorerExample } from './UIExplorerList.ios';
|
2017-02-28 23:39:24 +00:00
|
|
|
import type { UIExplorerAction } from './UIExplorerActions';
|
|
|
|
import type { UIExplorerNavigationState } from './UIExplorerNavigationReducer';
|
2016-02-23 00:15:35 +00:00
|
|
|
|
2016-04-04 13:04:54 +00:00
|
|
|
type Props = {
|
|
|
|
exampleFromAppetizeParams: string,
|
|
|
|
};
|
2016-02-23 00:15:44 +00:00
|
|
|
|
2017-02-28 23:39:24 +00:00
|
|
|
const APP_STATE_KEY = 'UIExplorerAppState.v2';
|
2016-02-23 00:15:44 +00:00
|
|
|
|
2017-02-28 23:39:24 +00:00
|
|
|
const Header = ({ onBack, title}) => (
|
|
|
|
<View style={styles.header}>
|
|
|
|
<View style={styles.headerCenter}>
|
|
|
|
<Text style={styles.title}>{title}</Text>
|
|
|
|
</View>
|
|
|
|
{onBack && <View style={styles.headerLeft}>
|
|
|
|
<Button title="Back" onPress={onBack} />
|
|
|
|
</View>}
|
|
|
|
</View>
|
|
|
|
);
|
2016-05-27 22:30:59 +00:00
|
|
|
|
2016-02-23 00:15:35 +00:00
|
|
|
class UIExplorerApp extends React.Component {
|
2017-02-28 23:39:24 +00:00
|
|
|
props: Props;
|
|
|
|
state: UIExplorerNavigationState;
|
2016-05-05 23:51:34 +00:00
|
|
|
|
2017-03-07 05:41:51 +00:00
|
|
|
componentWillMount() {
|
|
|
|
BackHandler.addEventListener('hardwareBackPress', this._handleBack);
|
|
|
|
}
|
|
|
|
|
2016-04-04 13:04:54 +00:00
|
|
|
componentDidMount() {
|
2016-05-05 23:51:34 +00:00
|
|
|
Linking.getInitialURL().then((url) => {
|
2016-05-27 22:30:59 +00:00
|
|
|
AsyncStorage.getItem(APP_STATE_KEY, (err, storedString) => {
|
2016-05-05 23:51:34 +00:00
|
|
|
const exampleAction = URIActionMap(this.props.exampleFromAppetizeParams);
|
|
|
|
const urlAction = URIActionMap(url);
|
|
|
|
const launchAction = exampleAction || urlAction;
|
|
|
|
if (err || !storedString) {
|
|
|
|
const initialAction = launchAction || {type: 'InitialAction'};
|
2017-02-28 23:39:24 +00:00
|
|
|
this.setState(UIExplorerNavigationReducer(undefined, initialAction));
|
2016-05-05 23:51:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const storedState = JSON.parse(storedString);
|
|
|
|
if (launchAction) {
|
|
|
|
this.setState(UIExplorerNavigationReducer(storedState, launchAction));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setState(storedState);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
Linking.addEventListener('url', (url) => {
|
|
|
|
this._handleAction(URIActionMap(url));
|
|
|
|
});
|
2016-02-23 00:15:35 +00:00
|
|
|
}
|
2016-05-05 23:51:34 +00:00
|
|
|
|
2017-02-28 23:39:24 +00:00
|
|
|
_handleBack = () => {
|
|
|
|
this._handleAction(UIExplorerActions.Back());
|
|
|
|
}
|
|
|
|
|
|
|
|
_handleAction = (action: ?UIExplorerAction) => {
|
2016-05-05 23:51:34 +00:00
|
|
|
if (!action) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const newState = UIExplorerNavigationReducer(this.state, action);
|
|
|
|
if (this.state !== newState) {
|
2017-02-09 22:14:56 +00:00
|
|
|
this.setState(
|
|
|
|
newState,
|
|
|
|
() => AsyncStorage.setItem(APP_STATE_KEY, JSON.stringify(this.state))
|
|
|
|
);
|
2016-04-04 13:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-05 23:51:34 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
if (!this.state) {
|
2016-02-23 00:15:35 +00:00
|
|
|
return null;
|
|
|
|
}
|
2017-02-28 23:39:24 +00:00
|
|
|
if (this.state.openExample) {
|
|
|
|
const Component = UIExplorerList.Modules[this.state.openExample];
|
|
|
|
if (Component.external) {
|
|
|
|
return (
|
|
|
|
<Component
|
|
|
|
onExampleExit={this._handleBack}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<View style={styles.exampleContainer}>
|
|
|
|
<Header onBack={this._handleBack} title={Component.title} />
|
|
|
|
<UIExplorerExampleContainer module={Component} />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-02-23 00:15:35 +00:00
|
|
|
|
2017-02-28 23:39:24 +00:00
|
|
|
}
|
2016-03-24 22:48:27 +00:00
|
|
|
return (
|
2017-02-28 23:39:24 +00:00
|
|
|
<View style={styles.exampleContainer}>
|
|
|
|
<Header title="UIExplorer" />
|
2016-02-23 00:15:35 +00:00
|
|
|
<UIExplorerExampleList
|
2016-05-05 23:51:34 +00:00
|
|
|
onNavigate={this._handleAction}
|
2016-02-23 00:15:35 +00:00
|
|
|
list={UIExplorerList}
|
|
|
|
/>
|
2017-02-28 23:39:24 +00:00
|
|
|
</View>
|
|
|
|
);
|
2016-02-23 00:15:35 +00:00
|
|
|
}
|
2016-02-20 00:55:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2017-02-28 23:39:24 +00:00
|
|
|
header: {
|
|
|
|
height: 60,
|
|
|
|
borderBottomWidth: StyleSheet.hairlineWidth,
|
|
|
|
borderBottomColor: '#96969A',
|
|
|
|
backgroundColor: '#F5F5F6',
|
|
|
|
flexDirection: 'row',
|
|
|
|
paddingTop: 20,
|
|
|
|
},
|
|
|
|
headerLeft: {
|
|
|
|
},
|
|
|
|
headerCenter: {
|
2015-01-30 01:10:49 +00:00
|
|
|
flex: 1,
|
2017-02-28 23:39:24 +00:00
|
|
|
position: 'absolute',
|
|
|
|
top: 27,
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
fontSize: 19,
|
|
|
|
fontWeight: '600',
|
|
|
|
textAlign: 'center',
|
2015-01-30 01:10:49 +00:00
|
|
|
},
|
2016-02-23 00:15:35 +00:00
|
|
|
exampleContainer: {
|
|
|
|
flex: 1,
|
2015-01-30 01:10:49 +00:00
|
|
|
},
|
2015-11-12 19:40:02 +00:00
|
|
|
});
|
|
|
|
|
2016-02-23 00:15:35 +00:00
|
|
|
AppRegistry.registerComponent('SetPropertiesExampleApp', () => require('./SetPropertiesExampleApp'));
|
|
|
|
AppRegistry.registerComponent('RootViewSizeFlexibilityExampleApp', () => require('./RootViewSizeFlexibilityExampleApp'));
|
2015-02-19 14:57:05 +00:00
|
|
|
AppRegistry.registerComponent('UIExplorerApp', () => UIExplorerApp);
|
2016-02-23 00:15:35 +00:00
|
|
|
|
|
|
|
// Register suitable examples for snapshot tests
|
|
|
|
UIExplorerList.ComponentExamples.concat(UIExplorerList.APIExamples).forEach((Example: UIExplorerExample) => {
|
|
|
|
const ExampleModule = Example.module;
|
|
|
|
if (ExampleModule.displayName) {
|
2016-07-26 08:00:02 +00:00
|
|
|
class Snapshotter extends React.Component {
|
|
|
|
render() {
|
2016-02-23 00:15:35 +00:00
|
|
|
return (
|
|
|
|
<SnapshotViewIOS>
|
2016-09-02 21:42:38 +00:00
|
|
|
<UIExplorerExampleContainer module={ExampleModule} />
|
2016-02-23 00:15:35 +00:00
|
|
|
</SnapshotViewIOS>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-23 00:15:35 +00:00
|
|
|
AppRegistry.registerComponent(ExampleModule.displayName, () => Snapshotter);
|
|
|
|
}
|
|
|
|
});
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
module.exports = UIExplorerApp;
|