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';
|
|
|
|
|
|
|
|
var React = require('react-native');
|
|
|
|
var {
|
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,
|
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;
|
2015-09-14 14:35:58 +00:00
|
|
|
var UIExplorerList = require('./UIExplorerList.android');
|
2015-06-08 11:28:27 +00:00
|
|
|
|
|
|
|
var DRAWER_WIDTH_LEFT = 56;
|
|
|
|
|
|
|
|
var UIExplorerApp = React.createClass({
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2015-09-14 14:35:58 +00:00
|
|
|
example: this._getUIExplorerHome(),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
_getUIExplorerHome: function() {
|
|
|
|
return {
|
|
|
|
title: 'UIExplorer',
|
|
|
|
component: this._renderHome(),
|
2015-06-08 11:28:27 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-09-14 14:35:58 +00:00
|
|
|
componentWillMount: function() {
|
|
|
|
BackAndroid.addEventListener('hardwareBackPress', this._handleBackButtonPress);
|
|
|
|
},
|
|
|
|
|
2015-06-08 11:28:27 +00:00
|
|
|
render: function() {
|
|
|
|
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"
|
2015-06-08 11:28:27 +00:00
|
|
|
ref={(drawer) => { this.drawer = drawer; }}
|
|
|
|
renderNavigationView={this._renderNavigationView}>
|
|
|
|
{this._renderNavigation()}
|
|
|
|
</DrawerLayoutAndroid>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
_renderNavigationView: function() {
|
|
|
|
return (
|
|
|
|
<UIExplorerList
|
|
|
|
onSelectExample={this.onSelectExample}
|
|
|
|
isInDrawer={true}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
onSelectExample: function(example) {
|
|
|
|
this.drawer.closeDrawer();
|
2015-09-14 14:35:58 +00:00
|
|
|
if (example.title === this._getUIExplorerHome().title) {
|
|
|
|
example = this._getUIExplorerHome();
|
2015-06-08 11:28:27 +00:00
|
|
|
}
|
|
|
|
this.setState({
|
2015-09-14 14:35:58 +00:00
|
|
|
example: example,
|
2015-06-08 11:28:27 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_renderHome: function() {
|
|
|
|
var onSelectExample = this.onSelectExample;
|
|
|
|
return React.createClass({
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<UIExplorerList
|
|
|
|
onSelectExample={onSelectExample}
|
|
|
|
isInDrawer={false}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_renderNavigation: function() {
|
|
|
|
var Component = this.state.example.component;
|
|
|
|
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}
|
|
|
|
title={this.state.example.title}
|
|
|
|
/>
|
2016-02-09 04:02:45 +00:00
|
|
|
<Component
|
|
|
|
ref={(example) => { this._exampleRef = example; }}
|
|
|
|
/>
|
2015-06-08 11:28:27 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-09-14 14:35:58 +00:00
|
|
|
_handleBackButtonPress: function() {
|
2016-02-09 04:02:45 +00:00
|
|
|
if (
|
|
|
|
this._exampleRef &&
|
|
|
|
this._exampleRef.handleBackAction &&
|
|
|
|
this._exampleRef.handleBackAction()
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-09-14 14:35:58 +00:00
|
|
|
if (this.state.example.title !== this._getUIExplorerHome().title) {
|
|
|
|
this.onSelectExample(this._getUIExplorerHome());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2015-06-08 11:28:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
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;
|