2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-06-23 15:27:29 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-06-23 15:27:29 +00:00
|
|
|
*
|
2018-05-11 20:32:37 +00:00
|
|
|
* @format
|
2015-03-23 18:36:57 +00:00
|
|
|
* @flow
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
const React = require('react');
|
|
|
|
const ReactNative = require('react-native');
|
2016-02-19 05:55:52 +00:00
|
|
|
const ViewExample = require('./ViewExample');
|
2016-11-23 05:01:36 +00:00
|
|
|
|
2016-02-19 05:55:52 +00:00
|
|
|
const createExamplePage = require('./createExamplePage');
|
2016-11-23 05:01:36 +00:00
|
|
|
const nativeImageSource = require('nativeImageSource');
|
2016-02-19 05:55:52 +00:00
|
|
|
const {
|
2015-05-07 14:16:59 +00:00
|
|
|
AlertIOS,
|
2016-02-19 05:55:52 +00:00
|
|
|
NavigatorIOS,
|
2015-02-20 04:10:52 +00:00
|
|
|
ScrollView,
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
TouchableHighlight,
|
|
|
|
View,
|
2016-04-09 03:36:40 +00:00
|
|
|
} = ReactNative;
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class EmptyPage extends React.Component<$FlowFixMeProps> {
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-02-20 04:10:52 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.emptyPage}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text style={styles.emptyPageText}>{this.props.text}</Text>
|
2015-02-20 04:10:52 +00:00
|
|
|
</View>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class NavigatorIOSExamplePage extends React.Component<$FlowFixMeProps> {
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-02-20 04:10:52 +00:00
|
|
|
var recurseTitle = 'Recurse Navigation';
|
2016-02-19 05:55:52 +00:00
|
|
|
if (!this.props.depth || this.props.depth === 1) {
|
2015-02-20 04:10:52 +00:00
|
|
|
recurseTitle += ' - more examples here';
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<ScrollView style={styles.list}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<View style={styles.line} />
|
2015-02-20 04:10:52 +00:00
|
|
|
<View style={styles.group}>
|
|
|
|
{this._renderRow(recurseTitle, () => {
|
|
|
|
this.props.navigator.push({
|
|
|
|
title: NavigatorIOSExample.title,
|
2016-02-19 05:55:52 +00:00
|
|
|
component: NavigatorIOSExamplePage,
|
2015-02-20 04:10:52 +00:00
|
|
|
backButtonTitle: 'Custom Back',
|
2016-02-19 05:55:52 +00:00
|
|
|
passProps: {depth: this.props.depth ? this.props.depth + 1 : 1},
|
2015-02-20 04:10:52 +00:00
|
|
|
});
|
|
|
|
})}
|
|
|
|
{this._renderRow('Push View Example', () => {
|
|
|
|
this.props.navigator.push({
|
|
|
|
title: 'Very Long Custom View Example Title',
|
2015-04-03 17:02:49 +00:00
|
|
|
component: createExamplePage(null, ViewExample),
|
2015-02-20 04:10:52 +00:00
|
|
|
});
|
|
|
|
})}
|
2016-06-23 15:27:29 +00:00
|
|
|
{this._renderRow('Custom title image Example', () => {
|
|
|
|
this.props.navigator.push({
|
|
|
|
title: 'Custom title image Example',
|
|
|
|
titleImage: require('./relay.png'),
|
|
|
|
component: createExamplePage(null, ViewExample),
|
|
|
|
});
|
|
|
|
})}
|
2015-02-20 04:10:52 +00:00
|
|
|
{this._renderRow('Custom Right Button', () => {
|
|
|
|
this.props.navigator.push({
|
|
|
|
title: NavigatorIOSExample.title,
|
|
|
|
component: EmptyPage,
|
|
|
|
rightButtonTitle: 'Cancel',
|
|
|
|
onRightButtonPress: () => this.props.navigator.pop(),
|
|
|
|
passProps: {
|
|
|
|
text: 'This page has a right button in the nav bar',
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-02-20 04:10:52 +00:00
|
|
|
});
|
|
|
|
})}
|
2016-09-09 00:53:55 +00:00
|
|
|
{this._renderRow('Custom Right System Button', () => {
|
|
|
|
this.props.navigator.push({
|
|
|
|
title: NavigatorIOSExample.title,
|
|
|
|
component: EmptyPage,
|
|
|
|
rightButtonSystemIcon: 'bookmarks',
|
|
|
|
onRightButtonPress: () => this.props.navigator.pop(),
|
|
|
|
passProps: {
|
|
|
|
text: 'This page has a right system button in the nav bar',
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2016-09-09 00:53:55 +00:00
|
|
|
});
|
|
|
|
})}
|
2015-05-07 14:16:59 +00:00
|
|
|
{this._renderRow('Custom Left & Right Icons', () => {
|
|
|
|
this.props.navigator.push({
|
|
|
|
title: NavigatorIOSExample.title,
|
|
|
|
component: EmptyPage,
|
|
|
|
leftButtonTitle: 'Custom Left',
|
|
|
|
onLeftButtonPress: () => this.props.navigator.pop(),
|
2016-11-23 05:01:36 +00:00
|
|
|
rightButtonIcon: nativeImageSource({
|
|
|
|
ios: 'NavBarButtonPlus',
|
|
|
|
width: 17,
|
2018-05-11 20:32:37 +00:00
|
|
|
height: 17,
|
2016-11-23 05:01:36 +00:00
|
|
|
}),
|
2015-05-07 14:16:59 +00:00
|
|
|
onRightButtonPress: () => {
|
|
|
|
AlertIOS.alert(
|
|
|
|
'Bar Button Action',
|
|
|
|
'Recognized a tap on the bar button icon',
|
|
|
|
[
|
|
|
|
{
|
|
|
|
text: 'OK',
|
|
|
|
onPress: () => console.log('Tapped OK'),
|
2016-09-09 00:53:55 +00:00
|
|
|
},
|
2018-05-11 20:32:37 +00:00
|
|
|
],
|
2016-09-09 00:53:55 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
passProps: {
|
2018-05-11 20:32:37 +00:00
|
|
|
text:
|
|
|
|
'This page has an icon for the right button in the nav bar',
|
|
|
|
},
|
2016-09-09 00:53:55 +00:00
|
|
|
});
|
|
|
|
})}
|
|
|
|
{this._renderRow('Custom Left & Right System Icons', () => {
|
|
|
|
this.props.navigator.push({
|
|
|
|
title: NavigatorIOSExample.title,
|
|
|
|
component: EmptyPage,
|
|
|
|
leftButtonSystemIcon: 'cancel',
|
|
|
|
onLeftButtonPress: () => this.props.navigator.pop(),
|
|
|
|
rightButtonSystemIcon: 'search',
|
|
|
|
onRightButtonPress: () => {
|
|
|
|
AlertIOS.alert(
|
|
|
|
'Bar Button Action',
|
|
|
|
'Recognized a tap on the bar button icon',
|
|
|
|
[
|
|
|
|
{
|
|
|
|
text: 'OK',
|
|
|
|
onPress: () => console.log('Tapped OK'),
|
2015-05-07 14:16:59 +00:00
|
|
|
},
|
2018-05-11 20:32:37 +00:00
|
|
|
],
|
2015-05-07 14:16:59 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
passProps: {
|
2018-05-11 20:32:37 +00:00
|
|
|
text:
|
|
|
|
'This page has an icon for the right button in the nav bar',
|
|
|
|
},
|
2015-05-07 14:16:59 +00:00
|
|
|
});
|
|
|
|
})}
|
2015-02-20 04:10:52 +00:00
|
|
|
{this._renderRow('Pop', () => {
|
|
|
|
this.props.navigator.pop();
|
|
|
|
})}
|
|
|
|
{this._renderRow('Pop to top', () => {
|
|
|
|
this.props.navigator.popToTop();
|
|
|
|
})}
|
2016-02-19 05:55:52 +00:00
|
|
|
{this._renderReplace()}
|
2015-02-20 04:10:52 +00:00
|
|
|
{this._renderReplacePrevious()}
|
|
|
|
{this._renderReplacePreviousAndPop()}
|
2018-05-11 20:32:37 +00:00
|
|
|
{this._renderRow(
|
|
|
|
'Exit NavigatorIOS Example',
|
|
|
|
this.props.onExampleExit,
|
|
|
|
)}
|
2015-02-20 04:10:52 +00:00
|
|
|
</View>
|
2018-05-11 20:32:37 +00:00
|
|
|
<View style={styles.line} />
|
2015-02-20 04:10:52 +00:00
|
|
|
</ScrollView>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_renderReplace = () => {
|
2016-02-19 05:55:52 +00:00
|
|
|
if (!this.props.depth) {
|
|
|
|
// this is to avoid replacing the top of the stack
|
2015-02-20 04:10:52 +00:00
|
|
|
return null;
|
|
|
|
}
|
2016-02-19 05:55:52 +00:00
|
|
|
return this._renderRow('Replace here', () => {
|
|
|
|
var prevRoute = this.props.route;
|
|
|
|
this.props.navigator.replace({
|
|
|
|
title: 'New Navigation',
|
|
|
|
component: EmptyPage,
|
|
|
|
rightButtonTitle: 'Undo',
|
|
|
|
onRightButtonPress: () => this.props.navigator.replace(prevRoute),
|
|
|
|
passProps: {
|
2018-05-11 20:32:37 +00:00
|
|
|
text:
|
|
|
|
'The component is replaced, but there is currently no ' +
|
2016-02-19 05:55:52 +00:00
|
|
|
'way to change the right button or title of the current route',
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2016-02-19 05:55:52 +00:00
|
|
|
});
|
2015-02-20 04:10:52 +00:00
|
|
|
});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_renderReplacePrevious = () => {
|
2016-02-19 05:55:52 +00:00
|
|
|
if (!this.props.depth || this.props.depth < 2) {
|
|
|
|
// this is to avoid replacing the top of the stack
|
2015-02-20 04:10:52 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return this._renderRow('Replace previous', () => {
|
|
|
|
this.props.navigator.replacePrevious({
|
|
|
|
title: 'Replaced',
|
|
|
|
component: EmptyPage,
|
|
|
|
passProps: {
|
|
|
|
text: 'This is a replaced "previous" page',
|
|
|
|
},
|
|
|
|
wrapperStyle: styles.customWrapperStyle,
|
|
|
|
});
|
|
|
|
});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_renderReplacePreviousAndPop = () => {
|
2016-02-19 05:55:52 +00:00
|
|
|
if (!this.props.depth || this.props.depth < 2) {
|
|
|
|
// this is to avoid replacing the top of the stack
|
2015-02-20 04:10:52 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return this._renderRow('Replace previous and pop', () => {
|
|
|
|
this.props.navigator.replacePreviousAndPop({
|
|
|
|
title: 'Replaced and Popped',
|
|
|
|
component: EmptyPage,
|
|
|
|
passProps: {
|
|
|
|
text: 'This is a replaced "previous" page',
|
|
|
|
},
|
|
|
|
wrapperStyle: styles.customWrapperStyle,
|
|
|
|
});
|
|
|
|
});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
_renderRow = (title: string, onPress: Function) => {
|
2015-02-20 04:10:52 +00:00
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<TouchableHighlight onPress={onPress}>
|
|
|
|
<View style={styles.row}>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text style={styles.rowText}>{title}</Text>
|
2015-02-20 04:10:52 +00:00
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
|
|
|
<View style={styles.separator} />
|
|
|
|
</View>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
|
|
|
}
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class NavigatorIOSExample extends React.Component<$FlowFixMeProps> {
|
2016-07-26 08:00:02 +00:00
|
|
|
static title = '<NavigatorIOS>';
|
|
|
|
static description = 'iOS navigation capabilities';
|
|
|
|
static external = true;
|
2016-02-19 05:55:52 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2016-02-19 05:55:52 +00:00
|
|
|
const {onExampleExit} = this.props;
|
|
|
|
return (
|
|
|
|
<NavigatorIOS
|
|
|
|
style={styles.container}
|
|
|
|
initialRoute={{
|
|
|
|
title: NavigatorIOSExample.title,
|
|
|
|
component: NavigatorIOSExamplePage,
|
|
|
|
passProps: {onExampleExit},
|
|
|
|
}}
|
|
|
|
tintColor="#008888"
|
|
|
|
/>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-19 05:55:52 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
2015-02-20 04:10:52 +00:00
|
|
|
customWrapperStyle: {
|
|
|
|
backgroundColor: '#bbdddd',
|
|
|
|
},
|
|
|
|
emptyPage: {
|
|
|
|
flex: 1,
|
|
|
|
paddingTop: 64,
|
|
|
|
},
|
|
|
|
emptyPageText: {
|
|
|
|
margin: 10,
|
|
|
|
},
|
|
|
|
list: {
|
|
|
|
backgroundColor: '#eeeeee',
|
|
|
|
marginTop: 10,
|
|
|
|
},
|
|
|
|
group: {
|
|
|
|
backgroundColor: 'white',
|
|
|
|
},
|
|
|
|
groupSpace: {
|
|
|
|
height: 15,
|
|
|
|
},
|
|
|
|
line: {
|
|
|
|
backgroundColor: '#bbbbbb',
|
2016-01-15 13:14:27 +00:00
|
|
|
height: StyleSheet.hairlineWidth,
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
row: {
|
|
|
|
backgroundColor: 'white',
|
|
|
|
justifyContent: 'center',
|
|
|
|
paddingHorizontal: 15,
|
|
|
|
paddingVertical: 15,
|
|
|
|
},
|
|
|
|
separator: {
|
2016-01-15 13:14:27 +00:00
|
|
|
height: StyleSheet.hairlineWidth,
|
2015-02-20 04:10:52 +00:00
|
|
|
backgroundColor: '#bbbbbb',
|
|
|
|
marginLeft: 15,
|
|
|
|
},
|
|
|
|
rowNote: {
|
|
|
|
fontSize: 17,
|
|
|
|
},
|
|
|
|
rowText: {
|
|
|
|
fontSize: 17,
|
2015-03-25 23:22:59 +00:00
|
|
|
fontWeight: '500',
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = NavigatorIOSExample;
|