2015-03-24 16:55:38 +00:00
|
|
|
/**
|
2015-03-28 05:18:47 +00:00
|
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
|
|
* evaluation purposes only.
|
2015-03-26 07:41:30 +00:00
|
|
|
*
|
2015-03-28 05:18:47 +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-03-24 16:55:38 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-03-26 07:41:30 +00:00
|
|
|
var React = require('react-native');
|
|
|
|
var {
|
|
|
|
Navigator,
|
2015-03-26 13:08:03 +00:00
|
|
|
PixelRatio,
|
2015-03-26 07:41:30 +00:00
|
|
|
ScrollView,
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
TouchableHighlight,
|
|
|
|
} = React;
|
2015-03-24 16:55:38 +00:00
|
|
|
var BreadcrumbNavSample = require('./BreadcrumbNavSample');
|
|
|
|
var NavigationBarSample = require('./NavigationBarSample');
|
|
|
|
var JumpingNavSample = require('./JumpingNavSample');
|
|
|
|
|
2015-03-26 13:08:03 +00:00
|
|
|
class NavButton extends React.Component {
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<TouchableHighlight
|
|
|
|
style={styles.button}
|
|
|
|
underlayColor="#B5B5B5"
|
|
|
|
onPress={this.props.onPress}>
|
|
|
|
<Text style={styles.buttonText}>{this.props.text}</Text>
|
|
|
|
</TouchableHighlight>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 16:55:38 +00:00
|
|
|
class NavMenu extends React.Component {
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<ScrollView style={styles.scene}>
|
2015-03-26 13:08:03 +00:00
|
|
|
<Text style={styles.messageText}>{this.props.message}</Text>
|
|
|
|
<NavButton
|
|
|
|
onPress={() => {
|
|
|
|
this.props.navigator.push({
|
|
|
|
message: 'Swipe right to dismiss',
|
|
|
|
sceneConfig: Navigator.SceneConfigs.FloatFromRight,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
text="Float in from right"
|
|
|
|
/>
|
|
|
|
<NavButton
|
|
|
|
onPress={() => {
|
|
|
|
this.props.navigator.push({
|
|
|
|
message: 'Swipe down to dismiss',
|
|
|
|
sceneConfig: Navigator.SceneConfigs.FloatFromBottom,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
text="Float in from bottom"
|
|
|
|
/>
|
|
|
|
<NavButton
|
|
|
|
onPress={() => {
|
|
|
|
this.props.navigator.pop();
|
|
|
|
}}
|
|
|
|
text="Pop"
|
|
|
|
/>
|
|
|
|
<NavButton
|
|
|
|
onPress={() => {
|
|
|
|
this.props.navigator.popToTop();
|
|
|
|
}}
|
|
|
|
text="Pop to top"
|
|
|
|
/>
|
|
|
|
<NavButton
|
|
|
|
onPress={() => {
|
|
|
|
this.props.navigator.push({ id: 'navbar' });
|
|
|
|
}}
|
|
|
|
text="Navbar Example"
|
|
|
|
/>
|
|
|
|
<NavButton
|
|
|
|
onPress={() => {
|
|
|
|
this.props.navigator.push({ id: 'jumping' });
|
|
|
|
}}
|
|
|
|
text="Jumping Example"
|
|
|
|
/>
|
|
|
|
<NavButton
|
|
|
|
onPress={() => {
|
|
|
|
this.props.navigator.push({ id: 'breadcrumbs' });
|
|
|
|
}}
|
|
|
|
text="Breadcrumbs Example"
|
|
|
|
/>
|
|
|
|
<NavButton
|
|
|
|
onPress={() => {
|
|
|
|
this.props.onExampleExit();
|
|
|
|
}}
|
|
|
|
text="Exit <Navigator> Example"
|
|
|
|
/>
|
2015-03-24 16:55:38 +00:00
|
|
|
</ScrollView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var TabBarExample = React.createClass({
|
|
|
|
|
|
|
|
statics: {
|
2015-03-26 04:10:04 +00:00
|
|
|
title: '<Navigator>',
|
2015-03-24 16:55:38 +00:00
|
|
|
description: 'JS-implemented navigation',
|
|
|
|
},
|
|
|
|
|
2015-03-24 18:43:54 +00:00
|
|
|
renderScene: function(route, nav) {
|
2015-03-24 16:55:38 +00:00
|
|
|
switch (route.id) {
|
2015-03-26 13:08:03 +00:00
|
|
|
case 'navbar':
|
|
|
|
return <NavigationBarSample navigator={nav} />;
|
|
|
|
case 'breadcrumbs':
|
|
|
|
return <BreadcrumbNavSample navigator={nav} />;
|
|
|
|
case 'jumping':
|
|
|
|
return <JumpingNavSample navigator={nav} />;
|
|
|
|
default:
|
2015-03-24 16:55:38 +00:00
|
|
|
return (
|
|
|
|
<NavMenu
|
2015-03-26 13:08:03 +00:00
|
|
|
message={route.message}
|
2015-03-24 16:55:38 +00:00
|
|
|
navigator={nav}
|
|
|
|
onExampleExit={this.props.onExampleExit}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
return (
|
2015-03-26 04:10:04 +00:00
|
|
|
<Navigator
|
2015-06-16 16:08:16 +00:00
|
|
|
ref={this._setNavigatorRef}
|
2015-03-24 16:55:38 +00:00
|
|
|
style={styles.container}
|
2015-03-26 13:08:03 +00:00
|
|
|
initialRoute={{ message: "First Scene", }}
|
2015-03-24 18:43:54 +00:00
|
|
|
renderScene={this.renderScene}
|
2015-03-26 13:08:03 +00:00
|
|
|
configureScene={(route) => {
|
|
|
|
if (route.sceneConfig) {
|
|
|
|
return route.sceneConfig;
|
|
|
|
}
|
|
|
|
return Navigator.SceneConfigs.FloatFromBottom;
|
|
|
|
}}
|
2015-03-24 16:55:38 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-06-16 16:08:16 +00:00
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
this._listeners && this._listeners.forEach(listener => listener.remove());
|
|
|
|
},
|
|
|
|
|
|
|
|
_setNavigatorRef: function(navigator) {
|
|
|
|
if (navigator !== this._navigator) {
|
|
|
|
this._navigator = navigator;
|
|
|
|
|
|
|
|
if (navigator) {
|
|
|
|
var callback = (event) => {
|
|
|
|
console.log(
|
|
|
|
`TabBarExample: event ${event.type}`,
|
|
|
|
{
|
|
|
|
route: JSON.stringify(event.data.route),
|
|
|
|
target: event.target,
|
|
|
|
type: event.type,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
// Observe focus change events from the owner.
|
|
|
|
this._listeners = [
|
|
|
|
navigator.navigationContext.addListener('willfocus', callback),
|
|
|
|
navigator.navigationContext.addListener('didfocus', callback),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2015-03-24 16:55:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
2015-03-26 13:08:03 +00:00
|
|
|
messageText: {
|
|
|
|
fontSize: 17,
|
|
|
|
fontWeight: '500',
|
|
|
|
padding: 15,
|
|
|
|
marginTop: 50,
|
|
|
|
marginLeft: 15,
|
|
|
|
},
|
2015-03-24 16:55:38 +00:00
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
button: {
|
|
|
|
backgroundColor: 'white',
|
|
|
|
padding: 15,
|
2015-03-26 13:08:03 +00:00
|
|
|
borderBottomWidth: 1 / PixelRatio.get(),
|
|
|
|
borderBottomColor: '#CDCDCD',
|
2015-03-24 16:55:38 +00:00
|
|
|
},
|
|
|
|
buttonText: {
|
2015-03-26 13:08:03 +00:00
|
|
|
fontSize: 17,
|
|
|
|
fontWeight: '500',
|
2015-03-24 16:55:38 +00:00
|
|
|
},
|
|
|
|
scene: {
|
|
|
|
flex: 1,
|
2015-03-26 13:08:03 +00:00
|
|
|
paddingTop: 20,
|
|
|
|
backgroundColor: '#EAEAEA',
|
2015-03-24 16:55:38 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-23 13:22:16 +00:00
|
|
|
TabBarExample.external = true;
|
|
|
|
|
2015-03-24 16:55:38 +00:00
|
|
|
module.exports = TabBarExample;
|