2015-03-24 09:55:38 -07:00
|
|
|
/**
|
2015-03-26 00:41:30 -07:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
2015-03-24 09:55:38 -07:00
|
|
|
*
|
2015-03-26 00:41:30 -07:00
|
|
|
* 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-24 09:55:38 -07:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2015-03-26 00:41:30 -07:00
|
|
|
|
|
|
|
var React = require('react-native');
|
|
|
|
var {
|
2015-03-26 06:08:03 -07:00
|
|
|
PixelRatio,
|
2015-03-26 00:41:30 -07:00
|
|
|
Navigator,
|
2015-03-26 06:08:03 -07:00
|
|
|
ScrollView,
|
2015-03-26 00:41:30 -07:00
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
TouchableHighlight,
|
2015-03-26 06:08:03 -07:00
|
|
|
TouchableOpacity,
|
2015-03-26 00:41:30 -07:00
|
|
|
View,
|
|
|
|
} = React;
|
2015-03-24 09:55:38 -07:00
|
|
|
|
|
|
|
var cssVar = require('cssVar');
|
|
|
|
|
2015-03-26 06:08:03 -07: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 09:55:38 -07:00
|
|
|
|
|
|
|
var NavigationBarRouteMapper = {
|
|
|
|
|
2015-03-24 15:40:48 -07:00
|
|
|
LeftButton: function(route, navigator, index, navState) {
|
2015-03-24 09:55:38 -07:00
|
|
|
if (index === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var previousRoute = navState.routeStack[index - 1];
|
|
|
|
return (
|
2015-03-26 06:08:03 -07:00
|
|
|
<TouchableOpacity
|
|
|
|
onPress={() => navigator.pop()}>
|
|
|
|
<View style={styles.navBarLeftButton}>
|
2015-03-24 09:55:38 -07:00
|
|
|
<Text style={[styles.navBarText, styles.navBarButtonText]}>
|
|
|
|
{previousRoute.title}
|
|
|
|
</Text>
|
|
|
|
</View>
|
2015-03-26 06:08:03 -07:00
|
|
|
</TouchableOpacity>
|
2015-03-24 09:55:38 -07:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-03-24 15:40:48 -07:00
|
|
|
RightButton: function(route, navigator, index, navState) {
|
2015-03-24 09:55:38 -07:00
|
|
|
return (
|
2015-03-26 06:08:03 -07:00
|
|
|
<TouchableOpacity
|
2015-03-24 15:40:48 -07:00
|
|
|
onPress={() => navigator.push(newRandomRoute())}>
|
2015-03-26 06:08:03 -07:00
|
|
|
<View style={styles.navBarRightButton}>
|
2015-03-24 09:55:38 -07:00
|
|
|
<Text style={[styles.navBarText, styles.navBarButtonText]}>
|
|
|
|
Next
|
|
|
|
</Text>
|
|
|
|
</View>
|
2015-03-26 06:08:03 -07:00
|
|
|
</TouchableOpacity>
|
2015-03-24 09:55:38 -07:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-03-24 15:40:48 -07:00
|
|
|
Title: function(route, navigator, index, navState) {
|
2015-03-24 09:55:38 -07:00
|
|
|
return (
|
|
|
|
<Text style={[styles.navBarText, styles.navBarTitleText]}>
|
|
|
|
{route.title} [{index}]
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
function newRandomRoute() {
|
|
|
|
return {
|
2015-03-26 06:08:03 -07:00
|
|
|
title: '#' + Math.ceil(Math.random() * 1000),
|
2015-03-24 09:55:38 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
var NavigationBarSample = React.createClass({
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
return (
|
2015-03-26 06:08:03 -07:00
|
|
|
<Navigator
|
|
|
|
debugOverlay={false}
|
|
|
|
style={styles.appContainer}
|
|
|
|
initialRoute={newRandomRoute()}
|
|
|
|
renderScene={(route, navigator) => (
|
|
|
|
<ScrollView style={styles.scene}>
|
|
|
|
<Text style={styles.messageText}>{route.content}</Text>
|
|
|
|
<NavButton
|
|
|
|
onPress={() => {
|
|
|
|
navigator.immediatelyResetRouteStack([
|
|
|
|
newRandomRoute(),
|
|
|
|
newRandomRoute(),
|
|
|
|
newRandomRoute(),
|
|
|
|
]);
|
|
|
|
}}
|
|
|
|
text="Reset w/ 3 scenes"
|
|
|
|
/>
|
|
|
|
<NavButton
|
|
|
|
onPress={() => {
|
|
|
|
this.props.navigator.pop();
|
|
|
|
}}
|
|
|
|
text="Exit NavigationBar Example"
|
2015-03-24 09:55:38 -07:00
|
|
|
/>
|
2015-03-26 06:08:03 -07:00
|
|
|
</ScrollView>
|
|
|
|
)}
|
|
|
|
navigationBar={
|
|
|
|
<Navigator.NavigationBar
|
|
|
|
navigationBarRouteMapper={NavigationBarRouteMapper}
|
|
|
|
navigationBarStyles={styles.navBar}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2015-03-24 09:55:38 -07:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
2015-03-26 06:08:03 -07:00
|
|
|
messageText: {
|
|
|
|
fontSize: 17,
|
|
|
|
fontWeight: '500',
|
|
|
|
padding: 15,
|
|
|
|
marginTop: 50,
|
|
|
|
marginLeft: 15,
|
2015-03-24 09:55:38 -07:00
|
|
|
},
|
2015-03-26 06:08:03 -07:00
|
|
|
button: {
|
|
|
|
backgroundColor: 'white',
|
|
|
|
padding: 15,
|
|
|
|
borderBottomWidth: 1 / PixelRatio.get(),
|
|
|
|
borderBottomColor: '#CDCDCD',
|
|
|
|
},
|
|
|
|
buttonText: {
|
|
|
|
fontSize: 17,
|
|
|
|
fontWeight: '500',
|
|
|
|
},
|
|
|
|
navBar: {
|
|
|
|
backgroundColor: 'white',
|
2015-03-24 09:55:38 -07:00
|
|
|
},
|
|
|
|
navBarText: {
|
|
|
|
fontSize: 16,
|
|
|
|
marginVertical: 10,
|
|
|
|
},
|
|
|
|
navBarTitleText: {
|
|
|
|
color: cssVar('fbui-bluegray-60'),
|
2015-03-25 16:22:59 -07:00
|
|
|
fontWeight: '500',
|
2015-03-24 09:55:38 -07:00
|
|
|
marginVertical: 9,
|
|
|
|
},
|
2015-03-26 06:08:03 -07:00
|
|
|
navBarLeftButton: {
|
|
|
|
paddingLeft: 10,
|
|
|
|
},
|
|
|
|
navBarRightButton: {
|
|
|
|
paddingRight: 10,
|
|
|
|
},
|
2015-03-24 09:55:38 -07:00
|
|
|
navBarButtonText: {
|
|
|
|
color: cssVar('fbui-accent-blue'),
|
|
|
|
},
|
2015-03-26 06:08:03 -07:00
|
|
|
scene: {
|
|
|
|
flex: 1,
|
|
|
|
paddingTop: 20,
|
|
|
|
backgroundColor: '#EAEAEA',
|
|
|
|
},
|
2015-03-24 09:55:38 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = NavigationBarSample;
|