2015-06-08 11:28:27 +00:00
|
|
|
/**
|
|
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
|
|
* evaluation purposes only.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @providesModule UIExplorerApp
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-02-20 00:55:07 +00:00
|
|
|
const React = require('react-native');
|
|
|
|
const {
|
2015-09-14 14:35:58 +00:00
|
|
|
AppRegistry,
|
|
|
|
BackAndroid,
|
2015-07-01 01:44:02 +00:00
|
|
|
Dimensions,
|
2015-09-14 14:35:58 +00:00
|
|
|
DrawerLayoutAndroid,
|
2016-02-23 00:15:35 +00:00
|
|
|
NavigationExperimental,
|
2015-06-08 11:28:27 +00:00
|
|
|
StyleSheet,
|
2015-09-14 14:35:58 +00:00
|
|
|
ToolbarAndroid,
|
2015-06-08 11:28:27 +00:00
|
|
|
View,
|
2016-02-03 14:40:39 +00:00
|
|
|
StatusBar,
|
2015-06-08 11:28:27 +00:00
|
|
|
} = React;
|
2016-02-23 00:15:35 +00:00
|
|
|
const {
|
|
|
|
RootContainer: NavigationRootContainer,
|
|
|
|
} = NavigationExperimental;
|
|
|
|
const UIExplorerActions = require('./UIExplorerActions');
|
|
|
|
const UIExplorerExampleList = require('./UIExplorerExampleList');
|
|
|
|
const UIExplorerList = require('./UIExplorerList');
|
|
|
|
const UIExplorerNavigationReducer = require('./UIExplorerNavigationReducer');
|
|
|
|
const UIExplorerStateTitleMap = require('./UIExplorerStateTitleMap');
|
2015-06-08 11:28:27 +00:00
|
|
|
|
2016-02-23 00:15:35 +00:00
|
|
|
var DRAWER_WIDTH_LEFT = 56;
|
2015-06-08 11:28:27 +00:00
|
|
|
|
2016-02-20 00:55:07 +00:00
|
|
|
class UIExplorerApp extends React.Component {
|
|
|
|
componentWillMount() {
|
2016-02-23 00:15:35 +00:00
|
|
|
BackAndroid.addEventListener('hardwareBackPress', this._handleBackButtonPress.bind(this));
|
2016-02-20 00:55:07 +00:00
|
|
|
}
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2016-02-20 00:55:07 +00:00
|
|
|
render() {
|
2016-02-23 00:15:35 +00:00
|
|
|
return (
|
|
|
|
<NavigationRootContainer
|
|
|
|
persistenceKey="UIExplorerStateNavState"
|
|
|
|
ref={navRootRef => { this._navigationRootRef = navRootRef; }}
|
|
|
|
reducer={UIExplorerNavigationReducer}
|
|
|
|
renderNavigation={this._renderApp.bind(this)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_renderApp(navigationState, onNavigate) {
|
|
|
|
if (!navigationState) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-06-08 11:28:27 +00:00
|
|
|
return (
|
|
|
|
<DrawerLayoutAndroid
|
|
|
|
drawerPosition={DrawerLayoutAndroid.positions.Left}
|
|
|
|
drawerWidth={Dimensions.get('window').width - DRAWER_WIDTH_LEFT}
|
2015-09-14 14:35:58 +00:00
|
|
|
keyboardDismissMode="on-drag"
|
2016-02-23 00:15:35 +00:00
|
|
|
onDrawerOpen={() => {
|
|
|
|
this._overrideBackPressForDrawerLayout = true;
|
|
|
|
}}
|
|
|
|
onDrawerClose={() => {
|
|
|
|
this._overrideBackPressForDrawerLayout = false;
|
|
|
|
}}
|
2015-06-08 11:28:27 +00:00
|
|
|
ref={(drawer) => { this.drawer = drawer; }}
|
2016-02-23 00:15:35 +00:00
|
|
|
renderNavigationView={this._renderDrawerContent.bind(this, onNavigate)}>
|
|
|
|
{this._renderNavigation(navigationState, onNavigate)}
|
2015-06-08 11:28:27 +00:00
|
|
|
</DrawerLayoutAndroid>
|
2016-02-20 00:55:07 +00:00
|
|
|
);
|
|
|
|
}
|
2015-06-08 11:28:27 +00:00
|
|
|
|
2016-02-23 00:15:35 +00:00
|
|
|
_renderDrawerContent(onNavigate) {
|
2015-06-08 11:28:27 +00:00
|
|
|
return (
|
2016-02-23 00:15:35 +00:00
|
|
|
<UIExplorerExampleList
|
|
|
|
list={UIExplorerList}
|
|
|
|
displayTitleRow={true}
|
|
|
|
disableSearch={true}
|
|
|
|
onNavigate={(action) => {
|
|
|
|
this.drawer && this.drawer.closeDrawer();
|
|
|
|
onNavigate(action);
|
|
|
|
}}
|
2015-06-08 11:28:27 +00:00
|
|
|
/>
|
|
|
|
);
|
2016-02-20 00:55:07 +00:00
|
|
|
}
|
2015-06-08 11:28:27 +00:00
|
|
|
|
2016-02-23 00:15:35 +00:00
|
|
|
_renderNavigation(navigationState, onNavigate) {
|
|
|
|
if (navigationState.externalExample) {
|
|
|
|
var Component = UIExplorerList.Modules[navigationState.externalExample];
|
|
|
|
return (
|
|
|
|
<Component
|
|
|
|
onExampleExit={() => {
|
|
|
|
onNavigate(NavigationRootContainer.getBackAction());
|
|
|
|
}}
|
|
|
|
ref={(example) => { this._exampleRef = example; }}
|
|
|
|
/>
|
|
|
|
);
|
2015-06-08 11:28:27 +00:00
|
|
|
}
|
2016-02-23 00:15:35 +00:00
|
|
|
const {stack} = navigationState;
|
|
|
|
const title = UIExplorerStateTitleMap(stack.children[stack.index]);
|
2016-03-07 11:03:41 +00:00
|
|
|
const index = stack.children.length <= 1 ? 1 : stack.index;
|
|
|
|
|
|
|
|
if (stack && stack.children[index]) {
|
|
|
|
const {key} = stack.children[index];
|
2016-02-23 00:15:35 +00:00
|
|
|
const ExampleModule = UIExplorerList.Modules[key];
|
|
|
|
const ExampleComponent = UIExplorerExampleList.makeRenderable(ExampleModule);
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
<StatusBar
|
|
|
|
backgroundColor="#589c90"
|
2015-06-08 11:28:27 +00:00
|
|
|
/>
|
2016-02-23 00:15:35 +00:00
|
|
|
<ToolbarAndroid
|
|
|
|
logo={require('image!launcher_icon')}
|
|
|
|
navIcon={require('image!ic_menu_black_24dp')}
|
|
|
|
onIconClicked={() => this.drawer.openDrawer()}
|
|
|
|
style={styles.toolbar}
|
|
|
|
title={title}
|
|
|
|
/>
|
|
|
|
<ExampleComponent
|
|
|
|
ref={(example) => { this._exampleRef = example; }}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2015-06-08 11:28:27 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
2016-02-03 14:40:39 +00:00
|
|
|
<StatusBar
|
|
|
|
backgroundColor="#589c90"
|
|
|
|
/>
|
2015-06-08 11:28:27 +00:00
|
|
|
<ToolbarAndroid
|
|
|
|
logo={require('image!launcher_icon')}
|
|
|
|
navIcon={require('image!ic_menu_black_24dp')}
|
|
|
|
onIconClicked={() => this.drawer.openDrawer()}
|
|
|
|
style={styles.toolbar}
|
2016-02-23 00:15:35 +00:00
|
|
|
title={title}
|
2015-06-08 11:28:27 +00:00
|
|
|
/>
|
2016-02-23 00:15:35 +00:00
|
|
|
<UIExplorerExampleList
|
|
|
|
list={UIExplorerList}
|
|
|
|
{...stack.children[0]}
|
2016-02-09 04:02:45 +00:00
|
|
|
/>
|
2015-06-08 11:28:27 +00:00
|
|
|
</View>
|
|
|
|
);
|
2016-02-20 00:55:07 +00:00
|
|
|
}
|
2015-06-08 11:28:27 +00:00
|
|
|
|
2016-02-20 00:55:07 +00:00
|
|
|
_handleBackButtonPress() {
|
2016-02-23 00:15:35 +00:00
|
|
|
if (this._overrideBackPressForDrawerLayout) {
|
|
|
|
// This hack is necessary because drawer layout provides an imperative API
|
|
|
|
// with open and close methods. This code would be cleaner if the drawer
|
|
|
|
// layout provided an `isOpen` prop and allowed us to pass a `onDrawerClose` handler.
|
|
|
|
this.drawer && this.drawer.closeDrawer();
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-09 04:02:45 +00:00
|
|
|
if (
|
|
|
|
this._exampleRef &&
|
|
|
|
this._exampleRef.handleBackAction &&
|
|
|
|
this._exampleRef.handleBackAction()
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-23 00:15:35 +00:00
|
|
|
if (this._navigationRootRef) {
|
|
|
|
return this._navigationRootRef.handleNavigation(
|
|
|
|
NavigationRootContainer.getBackAction()
|
|
|
|
);
|
2015-09-14 14:35:58 +00:00
|
|
|
}
|
|
|
|
return false;
|
2016-02-20 00:55:07 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-08 11:28:27 +00:00
|
|
|
|
2016-02-20 00:55:07 +00:00
|
|
|
const styles = StyleSheet.create({
|
2015-06-08 11:28:27 +00:00
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
toolbar: {
|
|
|
|
backgroundColor: '#E9EAED',
|
|
|
|
height: 56,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2015-09-14 14:35:58 +00:00
|
|
|
AppRegistry.registerComponent('UIExplorerApp', () => UIExplorerApp);
|
|
|
|
|
2015-06-08 11:28:27 +00:00
|
|
|
module.exports = UIExplorerApp;
|