2015-03-25 02:34:12 +00:00
|
|
|
/**
|
2015-03-26 13:32:01 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
2015-03-25 02:34:12 +00:00
|
|
|
*
|
2015-03-26 13:32:01 +00: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-25 02:34:12 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2015-03-26 13:32:01 +00:00
|
|
|
var React = require('react-native');
|
|
|
|
var {
|
|
|
|
Navigator,
|
|
|
|
ScrollView,
|
|
|
|
StyleSheet,
|
|
|
|
TabBarIOS,
|
|
|
|
Text,
|
|
|
|
View,
|
|
|
|
TouchableHighlight,
|
|
|
|
} = React;
|
2015-03-25 02:34:12 +00:00
|
|
|
|
|
|
|
var SAMPLE_TEXT = 'Top Pushes. Middle Replaces. Bottom Pops.';
|
|
|
|
|
|
|
|
var _getRandomRoute = function() {
|
|
|
|
return {
|
|
|
|
backButtonTitle: 'Back' + ('' + 10 * Math.random()).substr(0, 1),
|
|
|
|
content:
|
|
|
|
SAMPLE_TEXT + '\nHere\'s a random number ' + Math.random(),
|
|
|
|
title: Math.random() > 0.5 ? 'Hello' : 'There',
|
|
|
|
rightButtonTitle: Math.random() > 0.5 ? 'Right' : 'Button',
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var SampleNavigationBarRouteMapper = {
|
|
|
|
rightContentForRoute: function(route, navigator) {
|
|
|
|
if (route.rightButtonTitle) {
|
|
|
|
return (
|
|
|
|
<Text style={[styles.titleText, styles.filterText]}>
|
|
|
|
{route.rightButtonTitle}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
titleContentForRoute: function(route, navigator) {
|
|
|
|
return (
|
2015-03-26 13:32:01 +00:00
|
|
|
<TouchableHighlight
|
2015-03-25 02:34:12 +00:00
|
|
|
onPress={() => navigator.push(_getRandomRoute())}>
|
|
|
|
<View>
|
|
|
|
<Text style={styles.titleText}>{route.title}</Text>
|
|
|
|
</View>
|
2015-03-26 13:32:01 +00:00
|
|
|
</TouchableHighlight>
|
2015-03-25 02:34:12 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
iconForRoute: function(route, navigator) {
|
|
|
|
var onPress =
|
|
|
|
navigator.popToRoute.bind(navigator, route);
|
|
|
|
return (
|
2015-03-26 13:32:01 +00:00
|
|
|
<TouchableHighlight onPress={onPress}>
|
2015-03-25 02:34:12 +00:00
|
|
|
<View style={styles.crumbIconPlaceholder} />
|
2015-03-26 13:32:01 +00:00
|
|
|
</TouchableHighlight>
|
2015-03-25 02:34:12 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
separatorForRoute: function(route, navigator) {
|
|
|
|
return (
|
2015-03-26 13:32:01 +00:00
|
|
|
<TouchableHighlight onPress={navigator.pop}>
|
2015-03-25 02:34:12 +00:00
|
|
|
<View style={styles.crumbSeparatorPlaceholder} />
|
2015-03-26 13:32:01 +00:00
|
|
|
</TouchableHighlight>
|
2015-03-25 02:34:12 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var _delay = 400; // Just to test for race conditions with native nav.
|
|
|
|
|
|
|
|
var renderScene = function(route, navigator) {
|
|
|
|
var content = route.content;
|
|
|
|
return (
|
|
|
|
<ScrollView>
|
|
|
|
<View style={styles.scene}>
|
2015-03-26 13:32:01 +00:00
|
|
|
<TouchableHighlight
|
2015-03-25 02:34:12 +00:00
|
|
|
onPress={_pushRouteLater(navigator.push)}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text style={styles.buttonText}>request push soon</Text>
|
|
|
|
</View>
|
2015-03-26 13:32:01 +00:00
|
|
|
</TouchableHighlight>
|
|
|
|
<TouchableHighlight
|
2015-03-25 02:34:12 +00:00
|
|
|
onPress={_pushRouteLater(navigator.replace)}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>{content}</Text>
|
|
|
|
</View>
|
2015-03-26 13:32:01 +00:00
|
|
|
</TouchableHighlight>
|
|
|
|
<TouchableHighlight
|
2015-03-25 02:34:12 +00:00
|
|
|
onPress={_pushRouteLater(navigator.replace)}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>{content}</Text>
|
|
|
|
</View>
|
2015-03-26 13:32:01 +00:00
|
|
|
</TouchableHighlight>
|
|
|
|
<TouchableHighlight
|
2015-03-25 02:34:12 +00:00
|
|
|
onPress={_pushRouteLater(navigator.replace)}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>{content}</Text>
|
|
|
|
</View>
|
2015-03-26 13:32:01 +00:00
|
|
|
</TouchableHighlight>
|
|
|
|
<TouchableHighlight
|
2015-03-25 02:34:12 +00:00
|
|
|
onPress={_pushRouteLater(navigator.replace)}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>{content}</Text>
|
|
|
|
</View>
|
2015-03-26 13:32:01 +00:00
|
|
|
</TouchableHighlight>
|
|
|
|
<TouchableHighlight
|
2015-03-25 02:34:12 +00:00
|
|
|
onPress={_pushRouteLater(navigator.replace)}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text>{content}</Text>
|
|
|
|
</View>
|
2015-03-26 13:32:01 +00:00
|
|
|
</TouchableHighlight>
|
|
|
|
<TouchableHighlight
|
2015-03-25 02:34:12 +00:00
|
|
|
onPress={_popRouteLater(navigator.pop)}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text style={styles.buttonText}>request pop soon</Text>
|
|
|
|
</View>
|
2015-03-26 13:32:01 +00:00
|
|
|
</TouchableHighlight>
|
|
|
|
<TouchableHighlight
|
2015-03-25 02:34:12 +00:00
|
|
|
onPress={
|
|
|
|
_immediatelySetTwoItemsLater(
|
|
|
|
navigator.immediatelyResetRouteStack
|
|
|
|
)
|
|
|
|
}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text style={styles.buttonText}>Immediate set two routes</Text>
|
|
|
|
</View>
|
2015-03-26 13:32:01 +00:00
|
|
|
</TouchableHighlight>
|
|
|
|
<TouchableHighlight
|
2015-03-25 02:34:12 +00:00
|
|
|
onPress={_popToTopLater(navigator.popToTop)}>
|
|
|
|
<View style={styles.button}>
|
|
|
|
<Text style={styles.buttonText}>pop to top soon</Text>
|
|
|
|
</View>
|
2015-03-26 13:32:01 +00:00
|
|
|
</TouchableHighlight>
|
2015-03-25 02:34:12 +00:00
|
|
|
</View>
|
|
|
|
</ScrollView>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
var _popToTopLater = function(popToTop) {
|
|
|
|
return () => setTimeout(popToTop, _delay);
|
|
|
|
};
|
|
|
|
|
|
|
|
var _pushRouteLater = function(push) {
|
|
|
|
return () => setTimeout(
|
|
|
|
() => push(_getRandomRoute()),
|
|
|
|
_delay
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
var _immediatelySetTwoItemsLater = function(immediatelyResetRouteStack) {
|
|
|
|
return () => setTimeout(
|
|
|
|
() => immediatelyResetRouteStack([
|
|
|
|
_getRandomRoute(),
|
|
|
|
_getRandomRoute(),
|
|
|
|
])
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
var _popRouteLater = function(pop) {
|
|
|
|
return () => setTimeout(pop, _delay);
|
|
|
|
};
|
|
|
|
|
|
|
|
var BreadcrumbNavSample = React.createClass({
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
selectedTab: 0,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
var initialRoute = {
|
|
|
|
backButtonTitle: 'Start', // no back button for initial scene
|
|
|
|
content: SAMPLE_TEXT,
|
|
|
|
title: 'Campaigns',
|
|
|
|
rightButtonTitle: 'Filter',
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<TabBarIOS>
|
2015-03-26 13:32:01 +00:00
|
|
|
<TabBarIOS.Item
|
2015-03-25 02:34:12 +00:00
|
|
|
selected={this.state.selectedTab === 0}
|
|
|
|
onPress={this.onTabSelect.bind(this, 0)}
|
2015-03-26 13:32:01 +00:00
|
|
|
icon={require('image!tabnav_list')}
|
2015-03-25 02:34:12 +00:00
|
|
|
title="One">
|
2015-03-26 13:32:01 +00:00
|
|
|
<Navigator
|
2015-03-25 02:34:12 +00:00
|
|
|
debugOverlay={false}
|
|
|
|
style={[styles.appContainer]}
|
|
|
|
initialRoute={initialRoute}
|
|
|
|
renderScene={renderScene}
|
|
|
|
navigationBar={
|
2015-03-26 13:32:01 +00:00
|
|
|
<Navigator.BreadcrumbNavigationBar
|
2015-03-25 02:34:12 +00:00
|
|
|
navigationBarRouteMapper={SampleNavigationBarRouteMapper}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2015-03-26 13:32:01 +00:00
|
|
|
</TabBarIOS.Item>
|
|
|
|
<TabBarIOS.Item
|
2015-03-25 02:34:12 +00:00
|
|
|
selected={this.state.selectedTab === 1}
|
|
|
|
onPress={this.onTabSelect.bind(this, 1)}
|
2015-03-26 13:32:01 +00:00
|
|
|
icon={require('image!tabnav_notification')}
|
2015-03-25 02:34:12 +00:00
|
|
|
title="Two">
|
2015-03-26 13:32:01 +00:00
|
|
|
<Navigator
|
|
|
|
configureScene={() => Navigator.SceneConfigs.FloatFromBottom}
|
2015-03-25 02:34:12 +00:00
|
|
|
debugOverlay={false}
|
|
|
|
style={[styles.appContainer]}
|
|
|
|
initialRoute={initialRoute}
|
|
|
|
renderScene={renderScene}
|
|
|
|
navigationBar={
|
2015-03-26 13:32:01 +00:00
|
|
|
<Navigator.BreadcrumbNavigationBar
|
2015-03-25 02:34:12 +00:00
|
|
|
navigationBarRouteMapper={SampleNavigationBarRouteMapper}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2015-03-26 13:32:01 +00:00
|
|
|
</TabBarIOS.Item>
|
2015-03-25 02:34:12 +00:00
|
|
|
</TabBarIOS>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
onTabSelect: function(tab, event) {
|
|
|
|
if (this.state.selectedTab !== tab) {
|
|
|
|
this.setState({selectedTab: tab});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
navigationItem: {
|
|
|
|
backgroundColor: '#eeeeee',
|
|
|
|
},
|
|
|
|
scene: {
|
|
|
|
paddingTop: 50,
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
button: {
|
|
|
|
backgroundColor: '#cccccc',
|
|
|
|
margin: 50,
|
|
|
|
marginTop: 26,
|
|
|
|
padding: 10,
|
|
|
|
},
|
|
|
|
buttonText: {
|
|
|
|
fontSize: 12,
|
|
|
|
textAlign: 'center',
|
|
|
|
},
|
|
|
|
appContainer: {
|
|
|
|
overflow: 'hidden',
|
|
|
|
backgroundColor: '#dddddd',
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
titleText: {
|
|
|
|
fontSize: 18,
|
|
|
|
color: '#666666',
|
|
|
|
textAlign: 'center',
|
2015-03-26 01:19:28 +00:00
|
|
|
fontWeight: '500',
|
2015-03-25 02:34:12 +00:00
|
|
|
lineHeight: 32,
|
|
|
|
},
|
|
|
|
filterText: {
|
|
|
|
color: '#5577ff',
|
|
|
|
},
|
|
|
|
// TODO: Accept icons from route.
|
|
|
|
crumbIconPlaceholder: {
|
|
|
|
flex: 1,
|
|
|
|
backgroundColor: '#666666',
|
|
|
|
},
|
|
|
|
crumbSeparatorPlaceholder: {
|
|
|
|
flex: 1,
|
|
|
|
backgroundColor: '#aaaaaa',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = BreadcrumbNavSample;
|