2015-01-30 01:10:49 +00:00
|
|
|
/**
|
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-02-20 00:55:07 +00:00
|
|
|
const React = require('react-native');
|
2016-02-23 00:15:35 +00:00
|
|
|
const UIExplorerActions = require('./UIExplorerActions');
|
2016-02-20 00:55:07 +00:00
|
|
|
const UIExplorerList = require('./UIExplorerList.ios');
|
2016-02-23 00:15:35 +00:00
|
|
|
const UIExplorerExampleList = require('./UIExplorerExampleList');
|
|
|
|
const UIExplorerNavigationReducer = require('./UIExplorerNavigationReducer');
|
|
|
|
const UIExplorerStateTitleMap = require('./UIExplorerStateTitleMap');
|
|
|
|
|
2016-02-20 00:55:07 +00:00
|
|
|
const {
|
2016-02-23 00:15:44 +00:00
|
|
|
Alert,
|
2016-02-23 00:15:43 +00:00
|
|
|
Animated,
|
2015-02-19 14:57:05 +00:00
|
|
|
AppRegistry,
|
2016-02-23 00:15:35 +00:00
|
|
|
NavigationExperimental,
|
|
|
|
SnapshotViewIOS,
|
2015-01-30 01:10:49 +00:00
|
|
|
StyleSheet,
|
2016-02-23 00:15:35 +00:00
|
|
|
Text,
|
|
|
|
TouchableHighlight,
|
2016-02-03 14:40:39 +00:00
|
|
|
View,
|
2015-01-30 01:10:49 +00:00
|
|
|
} = React;
|
2016-02-23 00:15:35 +00:00
|
|
|
const {
|
|
|
|
AnimatedView: NavigationAnimatedView,
|
|
|
|
Card: NavigationCard,
|
|
|
|
Header: NavigationHeader,
|
|
|
|
Reducer: NavigationReducer,
|
|
|
|
RootContainer: NavigationRootContainer,
|
|
|
|
} = NavigationExperimental;
|
|
|
|
const StackReducer = NavigationReducer.StackReducer;
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2016-02-23 00:15:35 +00:00
|
|
|
import type {
|
|
|
|
NavigationState,
|
|
|
|
} from 'NavigationStateUtils'
|
2015-03-12 19:51:44 +00:00
|
|
|
|
2016-02-23 00:15:35 +00:00
|
|
|
import type { Value } from 'Animated';
|
|
|
|
import type { Layout } from 'NavigationAnimatedView';
|
|
|
|
import type { UIExplorerNavigationState } from './UIExplorerNavigationReducer';
|
2015-03-25 02:34:12 +00:00
|
|
|
|
2016-02-23 00:15:35 +00:00
|
|
|
import type {
|
|
|
|
UIExplorerExample,
|
|
|
|
} from './UIExplorerList.ios'
|
|
|
|
|
2016-02-23 00:15:44 +00:00
|
|
|
function PathActionMap(path: string): ?Object {
|
|
|
|
// Warning! Hacky parsing for example code. Use a library for this!
|
|
|
|
const exampleParts = path.split('/example/');
|
|
|
|
const exampleKey = exampleParts[1];
|
|
|
|
if (exampleKey) {
|
|
|
|
if (!UIExplorerList.Modules[exampleKey]) {
|
|
|
|
Alert.alert(`${exampleKey} example could not be found!`);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return UIExplorerActions.ExampleAction(exampleKey);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function URIActionMap(uri: ?string): ?Object {
|
|
|
|
// Warning! Hacky parsing for example code. Use a library for this!
|
|
|
|
if (!uri) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const parts = uri.split('rnuiexplorer:/');
|
|
|
|
if (!parts[1]) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const path = parts[1];
|
|
|
|
return PathActionMap(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-23 00:15:35 +00:00
|
|
|
class UIExplorerApp extends React.Component {
|
2016-02-23 00:15:44 +00:00
|
|
|
_navigationRootRef: ?NavigationRootContainer;
|
2016-02-23 00:15:35 +00:00
|
|
|
_renderNavigation: Function;
|
|
|
|
componentWillMount() {
|
|
|
|
this._renderNavigation = this._renderNavigation.bind(this);
|
|
|
|
}
|
2016-02-20 00:55:07 +00:00
|
|
|
render() {
|
2016-02-23 00:15:35 +00:00
|
|
|
return (
|
|
|
|
<NavigationRootContainer
|
|
|
|
persistenceKey="UIExplorerState"
|
|
|
|
reducer={UIExplorerNavigationReducer}
|
2016-02-23 00:15:44 +00:00
|
|
|
ref={navRootRef => { this._navigationRootRef = navRootRef; }}
|
2016-02-23 00:15:35 +00:00
|
|
|
renderNavigation={this._renderNavigation}
|
2016-02-23 00:15:44 +00:00
|
|
|
linkingActionMap={URIActionMap}
|
2016-02-23 00:15:35 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
_renderNavigation(navigationState: UIExplorerNavigationState, onNavigate: Function) {
|
|
|
|
if (!navigationState) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (navigationState.externalExample) {
|
|
|
|
var Component = UIExplorerList.Modules[navigationState.externalExample];
|
2015-03-25 02:34:12 +00:00
|
|
|
return (
|
2016-02-23 00:15:35 +00:00
|
|
|
<Component
|
2015-03-25 02:34:12 +00:00
|
|
|
onExampleExit={() => {
|
2016-02-23 00:15:35 +00:00
|
|
|
onNavigate(NavigationRootContainer.getBackAction());
|
2015-03-25 02:34:12 +00:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2016-02-23 00:15:35 +00:00
|
|
|
const {stack} = navigationState;
|
|
|
|
return (
|
|
|
|
<NavigationAnimatedView
|
|
|
|
navigationState={stack}
|
|
|
|
style={styles.container}
|
|
|
|
renderOverlay={this._renderOverlay.bind(this, stack)}
|
|
|
|
renderScene={this._renderSceneContainer.bind(this, stack)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2015-07-02 16:34:34 +00:00
|
|
|
|
2016-02-23 00:15:35 +00:00
|
|
|
_renderOverlay(
|
|
|
|
navigationState: NavigationState,
|
|
|
|
position: Value,
|
|
|
|
layout: Layout
|
|
|
|
): ReactElement {
|
2015-07-02 16:34:34 +00:00
|
|
|
return (
|
2016-02-23 00:15:35 +00:00
|
|
|
<NavigationHeader
|
|
|
|
navigationState={navigationState}
|
|
|
|
position={position}
|
|
|
|
getTitle={UIExplorerStateTitleMap}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_renderSceneContainer(
|
|
|
|
navigationState: NavigationState,
|
|
|
|
scene: NavigationState,
|
|
|
|
index: number,
|
|
|
|
position: Value,
|
|
|
|
layout: Layout
|
|
|
|
): ReactElement {
|
|
|
|
return (
|
|
|
|
<NavigationCard
|
|
|
|
key={scene.key}
|
|
|
|
index={index}
|
|
|
|
navigationState={navigationState}
|
|
|
|
position={position}
|
|
|
|
layout={layout}>
|
|
|
|
{this._renderScene(scene)}
|
|
|
|
</NavigationCard>
|
2015-07-02 16:34:34 +00:00
|
|
|
);
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 00:15:35 +00:00
|
|
|
_renderScene(state: Object): ?ReactElement {
|
|
|
|
if (state.key === 'AppList') {
|
|
|
|
return (
|
|
|
|
<UIExplorerExampleList
|
|
|
|
list={UIExplorerList}
|
|
|
|
style={styles.exampleContainer}
|
|
|
|
{...state}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Example = UIExplorerList.Modules[state.key];
|
|
|
|
if (Example) {
|
|
|
|
const Component = UIExplorerExampleList.makeRenderable(Example);
|
|
|
|
return (
|
|
|
|
<View style={styles.exampleContainer}>
|
|
|
|
<Component />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2016-02-20 00:55:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2015-01-30 01:10:49 +00:00
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
2016-02-23 00:15:35 +00:00
|
|
|
exampleContainer: {
|
|
|
|
flex: 1,
|
|
|
|
paddingTop: 60,
|
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) {
|
|
|
|
var Snapshotter = React.createClass({
|
|
|
|
render: function() {
|
|
|
|
var Renderable = UIExplorerExampleList.makeRenderable(ExampleModule);
|
|
|
|
return (
|
|
|
|
<SnapshotViewIOS>
|
|
|
|
<Renderable />
|
|
|
|
</SnapshotViewIOS>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
AppRegistry.registerComponent(ExampleModule.displayName, () => Snapshotter);
|
|
|
|
}
|
|
|
|
});
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
module.exports = UIExplorerApp;
|