react-native-navigation的迁移库

FirstTabScreen.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import React, {Component} from 'react';
  2. import {
  3. Text,
  4. View,
  5. TouchableOpacity,
  6. StyleSheet,
  7. Alert,
  8. Platform
  9. } from 'react-native';
  10. import {Navigation} from 'react-native-navigation';
  11. export default class FirstTabScreen extends Component {
  12. static navigatorButtons = {
  13. leftButtons: [{
  14. icon: require('../../img/navicon_menu.png'),
  15. id: 'menu'
  16. }],
  17. rightButtons: [
  18. {
  19. title: 'Edit',
  20. id: 'edit'
  21. },
  22. {
  23. icon: require('../../img/navicon_add.png'),
  24. id: 'add'
  25. }
  26. ]
  27. };
  28. static navigatorStyle = {
  29. navBarBackgroundColor: '#4dbce9',
  30. navBarTextColor: '#ffff00',
  31. navBarSubtitleTextColor: '#ff0000',
  32. navBarButtonColor: '#ffffff',
  33. statusBarTextColorScheme: 'light',
  34. tabBarBackgroundColor: '#4dbce9',
  35. tabBarButtonColor: '#ffffff',
  36. tabBarSelectedButtonColor: '#ffff00'
  37. };
  38. constructor(props) {
  39. super(props);
  40. // if you want to listen on navigator events, set this up
  41. this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
  42. }
  43. onNavigatorEvent(event) {
  44. if (event.id === 'menu') {
  45. this.props.navigator.toggleDrawer({
  46. side: 'left',
  47. animated: true
  48. });
  49. }
  50. if (event.id === 'edit') {
  51. Alert.alert('NavBar', 'Edit button pressed');
  52. }
  53. if (event.id === 'add') {
  54. Alert.alert('NavBar', 'Add button pressed');
  55. }
  56. }
  57. render() {
  58. return (
  59. <View style={{flex: 1, padding: 20}}>
  60. <TouchableOpacity onPress={ this.onPushPress.bind(this) }>
  61. <Text style={styles.button}>Push Plain Screen</Text>
  62. </TouchableOpacity>
  63. <TouchableOpacity onPress={ this.onPushStyledPress.bind(this) }>
  64. <Text style={styles.button}>Push Styled Screen</Text>
  65. </TouchableOpacity>
  66. <TouchableOpacity onPress={ this.onModalPress.bind(this) }>
  67. <Text style={styles.button}>Show Modal Screen</Text>
  68. </TouchableOpacity>
  69. {
  70. Platform.OS === 'ios' ?
  71. <TouchableOpacity onPress={ this.onLightBoxPress.bind(this) }>
  72. <Text style={styles.button}>Show LightBox</Text>
  73. </TouchableOpacity> : false
  74. }
  75. {
  76. Platform.OS === 'ios' ?
  77. <TouchableOpacity onPress={ this.onInAppNotificationPress.bind(this) }>
  78. <Text style={styles.button}>Show In-App Notification</Text>
  79. </TouchableOpacity> : false
  80. }
  81. <TouchableOpacity onPress={ this.onStartSingleScreenApp.bind(this) }>
  82. <Text style={styles.button}>Show Single Screen App</Text>
  83. </TouchableOpacity>
  84. </View>
  85. );
  86. }
  87. onPushPress() {
  88. this.props.navigator.push({
  89. title: "More",
  90. screen: "example.PushedScreen"
  91. });
  92. }
  93. onPushStyledPress() {
  94. this.props.navigator.push({
  95. title: "Styled",
  96. screen: "example.StyledScreen"
  97. });
  98. }
  99. onModalPress() {
  100. this.props.navigator.showModal({
  101. title: "Modal",
  102. screen: "example.ModalScreen"
  103. });
  104. }
  105. onLightBoxPress() {
  106. this.props.navigator.showLightBox({
  107. screen: "example.LightBoxScreen",
  108. style: {
  109. backgroundBlur: "dark"
  110. },
  111. passProps: {
  112. greeting: 'hey there'
  113. },
  114. });
  115. }
  116. onInAppNotificationPress() {
  117. this.props.navigator.showInAppNotification({
  118. screen: "example.NotificationScreen"
  119. });
  120. }
  121. onStartSingleScreenApp() {
  122. Navigation.startSingleScreenApp({
  123. screen: {
  124. screen: 'example.FirstTabScreen'
  125. },
  126. drawer: {
  127. left: {
  128. screen: 'example.SideMenu'
  129. }
  130. }
  131. });
  132. }
  133. }
  134. const styles = StyleSheet.create({
  135. button: {
  136. textAlign: 'center',
  137. fontSize: 18,
  138. marginBottom: 10,
  139. marginTop: 10,
  140. color: 'blue'
  141. }
  142. });