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 {
|
|
|
|
Navigator,
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
TouchableHighlight,
|
|
|
|
View,
|
|
|
|
} = React;
|
2015-03-24 09:55:38 -07:00
|
|
|
|
|
|
|
var cssVar = require('cssVar');
|
|
|
|
|
|
|
|
|
|
|
|
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 00:41:30 -07:00
|
|
|
<TouchableHighlight onPress={() => navigator.pop()}>
|
2015-03-24 09:55:38 -07:00
|
|
|
<View>
|
|
|
|
<Text style={[styles.navBarText, styles.navBarButtonText]}>
|
|
|
|
{previousRoute.title}
|
|
|
|
</Text>
|
|
|
|
</View>
|
2015-03-26 00:41:30 -07:00
|
|
|
</TouchableHighlight>
|
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 00:41:30 -07:00
|
|
|
<TouchableHighlight
|
2015-03-24 15:40:48 -07:00
|
|
|
onPress={() => navigator.push(newRandomRoute())}>
|
2015-03-24 09:55:38 -07:00
|
|
|
<View>
|
|
|
|
<Text style={[styles.navBarText, styles.navBarButtonText]}>
|
|
|
|
Next
|
|
|
|
</Text>
|
|
|
|
</View>
|
2015-03-26 00:41:30 -07:00
|
|
|
</TouchableHighlight>
|
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 {
|
|
|
|
content: 'Hello World!',
|
|
|
|
title: 'Random ' + Math.round(Math.random() * 100),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
var NavigationBarSample = React.createClass({
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={styles.appContainer}>
|
2015-03-25 21:10:04 -07:00
|
|
|
<Navigator
|
2015-03-24 09:55:38 -07:00
|
|
|
debugOverlay={false}
|
|
|
|
style={styles.appContainer}
|
|
|
|
initialRoute={newRandomRoute()}
|
2015-03-24 15:40:48 -07:00
|
|
|
renderScene={(route, navigator) => (
|
2015-03-24 11:43:54 -07:00
|
|
|
<View style={styles.scene}>
|
|
|
|
<Text>{route.content}</Text>
|
|
|
|
</View>
|
|
|
|
)}
|
2015-03-24 09:55:38 -07:00
|
|
|
navigationBar={
|
2015-03-26 00:41:30 -07:00
|
|
|
<Navigator.NavigationBar
|
2015-03-24 09:55:38 -07:00
|
|
|
navigationBarRouteMapper={NavigationBarRouteMapper}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
appContainer: {
|
|
|
|
overflow: 'hidden',
|
|
|
|
backgroundColor: '#ffffff',
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
scene: {
|
|
|
|
paddingTop: 50,
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
navBarButtonText: {
|
|
|
|
color: cssVar('fbui-accent-blue'),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = NavigationBarSample;
|