2015-03-25 02:34:12 +00:00
|
|
|
/**
|
2015-03-26 18:24:15 +00:00
|
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
|
|
* evaluation purposes only.
|
2015-03-25 02:34:12 +00:00
|
|
|
*
|
2015-03-26 18:24:15 +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-25 02:34:12 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-03-26 13:32:01 +00:00
|
|
|
var React = require('react-native');
|
|
|
|
var {
|
2015-03-27 18:46:17 +00:00
|
|
|
PixelRatio,
|
2015-03-26 13:32:01 +00:00
|
|
|
Navigator,
|
|
|
|
StyleSheet,
|
2015-03-27 18:46:17 +00:00
|
|
|
ScrollView,
|
2015-03-26 13:32:01 +00:00
|
|
|
Text,
|
|
|
|
TouchableHighlight,
|
2015-03-27 18:46:17 +00:00
|
|
|
TouchableOpacity,
|
|
|
|
View,
|
2015-03-26 13:32:01 +00:00
|
|
|
} = React;
|
2015-03-25 02:34:12 +00:00
|
|
|
|
|
|
|
var _getRandomRoute = function() {
|
|
|
|
return {
|
2015-03-27 18:46:17 +00:00
|
|
|
title: '#' + Math.ceil(Math.random() * 1000),
|
2015-03-25 02:34:12 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-03-27 18:46:17 +00:00
|
|
|
class NavButton extends React.Component {
|
|
|
|
render() {
|
2015-03-25 02:34:12 +00:00
|
|
|
return (
|
2015-03-26 13:32:01 +00:00
|
|
|
<TouchableHighlight
|
2015-03-27 18:46:17 +00:00
|
|
|
style={styles.button}
|
|
|
|
underlayColor="#B5B5B5"
|
|
|
|
onPress={this.props.onPress}>
|
|
|
|
<Text style={styles.buttonText}>{this.props.text}</Text>
|
2015-03-26 13:32:01 +00:00
|
|
|
</TouchableHighlight>
|
2015-03-25 02:34:12 +00:00
|
|
|
);
|
|
|
|
}
|
2015-03-27 18:46:17 +00:00
|
|
|
}
|
2015-03-25 02:34:12 +00:00
|
|
|
|
|
|
|
var BreadcrumbNavSample = React.createClass({
|
|
|
|
|
2015-03-27 18:46:17 +00:00
|
|
|
componentWillMount: function() {
|
|
|
|
this._navBarRouteMapper = {
|
|
|
|
rightContentForRoute: function(route, navigator) {
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
titleContentForRoute: function(route, navigator) {
|
|
|
|
return (
|
|
|
|
<TouchableOpacity
|
|
|
|
onPress={() => navigator.push(_getRandomRoute())}>
|
2015-07-20 23:29:40 +00:00
|
|
|
<Text style={styles.titleText}>{route.title}</Text>
|
2015-03-27 18:46:17 +00:00
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
iconForRoute: function(route, navigator) {
|
|
|
|
return (
|
2015-07-20 23:29:40 +00:00
|
|
|
<TouchableOpacity
|
|
|
|
onPress={() => { navigator.popToRoute(route); }}
|
|
|
|
style={styles.crumbIconPlaceholder}
|
|
|
|
/>
|
2015-03-27 18:46:17 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
separatorForRoute: function(route, navigator) {
|
|
|
|
return (
|
2015-07-20 23:29:40 +00:00
|
|
|
<TouchableOpacity
|
|
|
|
onPress={navigator.pop}
|
|
|
|
style={styles.crumbSeparatorPlaceholder}
|
|
|
|
/>
|
2015-03-27 18:46:17 +00:00
|
|
|
);
|
|
|
|
}
|
2015-03-25 02:34:12 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-03-27 18:46:17 +00:00
|
|
|
_renderScene: function(route, navigator) {
|
|
|
|
return (
|
|
|
|
<ScrollView style={styles.scene}>
|
|
|
|
<NavButton
|
|
|
|
onPress={() => { navigator.push(_getRandomRoute()) }}
|
|
|
|
text="Push"
|
|
|
|
/>
|
|
|
|
<NavButton
|
|
|
|
onPress={() => { navigator.immediatelyResetRouteStack([_getRandomRoute(), _getRandomRoute()]) }}
|
|
|
|
text="Reset w/ 2 scenes"
|
|
|
|
/>
|
|
|
|
<NavButton
|
|
|
|
onPress={() => { navigator.popToTop() }}
|
|
|
|
text="Pop to top"
|
|
|
|
/>
|
|
|
|
<NavButton
|
|
|
|
onPress={() => { navigator.replace(_getRandomRoute()) }}
|
|
|
|
text="Replace"
|
|
|
|
/>
|
|
|
|
<NavButton
|
|
|
|
onPress={() => { this.props.navigator.pop(); }}
|
|
|
|
text="Close breadcrumb example"
|
|
|
|
/>
|
|
|
|
</ScrollView>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-03-25 02:34:12 +00:00
|
|
|
render: function() {
|
|
|
|
return (
|
2015-03-27 18:46:17 +00:00
|
|
|
<Navigator
|
|
|
|
style={styles.container}
|
|
|
|
initialRoute={_getRandomRoute()}
|
|
|
|
renderScene={this._renderScene}
|
|
|
|
navigationBar={
|
|
|
|
<Navigator.BreadcrumbNavigationBar
|
2015-04-02 01:37:03 +00:00
|
|
|
routeMapper={this._navBarRouteMapper}
|
2015-03-25 02:34:12 +00:00
|
|
|
/>
|
2015-03-27 18:46:17 +00:00
|
|
|
}
|
|
|
|
/>
|
2015-03-25 02:34:12 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-03-27 18:46:17 +00:00
|
|
|
|
2015-03-25 02:34:12 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
scene: {
|
|
|
|
paddingTop: 50,
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
button: {
|
2015-03-27 18:46:17 +00:00
|
|
|
backgroundColor: 'white',
|
|
|
|
padding: 15,
|
|
|
|
borderBottomWidth: 1 / PixelRatio.get(),
|
|
|
|
borderBottomColor: '#CDCDCD',
|
2015-03-25 02:34:12 +00:00
|
|
|
},
|
|
|
|
buttonText: {
|
2015-03-27 18:46:17 +00:00
|
|
|
fontSize: 17,
|
|
|
|
fontWeight: '500',
|
2015-03-25 02:34:12 +00:00
|
|
|
},
|
2015-03-27 18:46:17 +00:00
|
|
|
container: {
|
2015-03-25 02:34:12 +00:00
|
|
|
overflow: 'hidden',
|
|
|
|
backgroundColor: '#dddddd',
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
titleText: {
|
|
|
|
fontSize: 18,
|
|
|
|
color: '#666666',
|
|
|
|
textAlign: 'center',
|
2015-03-27 18:46:17 +00:00
|
|
|
fontWeight: 'bold',
|
2015-03-25 02:34:12 +00:00
|
|
|
lineHeight: 32,
|
|
|
|
},
|
|
|
|
crumbIconPlaceholder: {
|
|
|
|
flex: 1,
|
|
|
|
backgroundColor: '#666666',
|
|
|
|
},
|
|
|
|
crumbSeparatorPlaceholder: {
|
|
|
|
flex: 1,
|
|
|
|
backgroundColor: '#aaaaaa',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = BreadcrumbNavSample;
|