react-native-navigation的迁移库

StyledScreen.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import React, {Component} from 'react';
  2. import {
  3. Text,
  4. View,
  5. ScrollView,
  6. TouchableOpacity,
  7. Image,
  8. StyleSheet,
  9. Alert,
  10. Platform
  11. } from 'react-native';
  12. export default class StyledScreen extends Component {
  13. static navigatorStyle = {
  14. drawUnderNavBar: true,
  15. drawUnderTabBar: true,
  16. navBarTranslucent: true
  17. };
  18. static navigatorButtons = {
  19. rightButtons: [{
  20. icon: require('../../img/navicon_edit.png'),
  21. id: 'compose',
  22. testID: 'e2e_is_awesome'
  23. }]
  24. };
  25. constructor(props) {
  26. super(props);
  27. // if you want to listen on navigator events, set this up
  28. this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
  29. }
  30. render() {
  31. return (
  32. <ScrollView style={styles.container}>
  33. <Image style={{width: undefined, height: 100}} source={require('../../img/colors.png')} />
  34. <View style={{padding: 20}}>
  35. <TouchableOpacity onPress={ this.onPushPress.bind(this) }>
  36. <Text style={styles.button}>Push Plain Screen</Text>
  37. </TouchableOpacity>
  38. <TouchableOpacity onPress={ this.onPushStyledPress.bind(this) }>
  39. <Text style={styles.button}>Push Styled Screen</Text>
  40. </TouchableOpacity>
  41. <TouchableOpacity onPress={ this.onPopPress.bind(this) }>
  42. <Text style={styles.button}>Pop Screen</Text>
  43. </TouchableOpacity>
  44. <TouchableOpacity onPress={ this.onSetSubtitlePress.bind(this) }>
  45. <Text style={styles.button}>Set Subtitle</Text>
  46. </TouchableOpacity>
  47. <TouchableOpacity onPress={ this.onSetTitleImagePress.bind(this) }>
  48. <Text style={styles.button}>Set Title Image</Text>
  49. </TouchableOpacity>
  50. </View>
  51. </ScrollView>
  52. );
  53. }
  54. onNavigatorEvent(event) {
  55. if (event.id == 'compose') {
  56. Alert.alert('NavBar', 'Compose button pressed');
  57. }
  58. }
  59. onPushPress() {
  60. this.props.navigator.push({
  61. title: "More",
  62. screen: "com.example.PushedScreen"
  63. });
  64. }
  65. onPushStyledPress() {
  66. this.props.navigator.push({
  67. title: "More",
  68. screen: "com.example.StyledScreen"
  69. });
  70. }
  71. onPopPress() {
  72. this.props.navigator.pop();
  73. }
  74. onSetSubtitlePress() {
  75. if (Platform.OS === 'android') {
  76. this.props.navigator.setSubTitle({
  77. subtitle: 'Subtitle'
  78. });
  79. } else {
  80. this.props.navigator.setTitle({
  81. title: 'title',
  82. subtitle: 'subtitle',
  83. navigatorStyle: {
  84. navBarSubtitleTextColor: '#ff00ff',
  85. navBarTextColor: '#ffff00'
  86. }
  87. })
  88. }
  89. }
  90. onSetTitleImagePress() {
  91. this.props.navigator.setTitle({
  92. title: 'title',
  93. titleImage: require('../../img/one.png'),
  94. })
  95. }
  96. }
  97. const styles = StyleSheet.create({
  98. container: {
  99. flex: 1,
  100. backgroundColor: 'white'
  101. },
  102. button: {
  103. textAlign: 'center',
  104. fontSize: 18,
  105. marginBottom: 10,
  106. marginTop:10,
  107. color: 'blue'
  108. }
  109. });