react-native-navigation的迁移库

SecondTabScreen.android.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import React, {Component} from 'react';
  2. import {
  3. Text,
  4. View,
  5. ScrollView,
  6. TouchableOpacity,
  7. StyleSheet
  8. } from 'react-native';
  9. export default class SecondTabScreen extends Component {
  10. static navigatorStyle = {
  11. drawUnderTabBar: true
  12. };
  13. constructor(props) {
  14. super(props);
  15. this.buttonsCounter = 0;
  16. // if you want to listen on navigator events, set this up
  17. // this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
  18. }
  19. render() {
  20. return (
  21. <View style={{flex: 1, padding: 20}}>
  22. <TouchableOpacity onPress={ this.onChangeButtonsPress.bind(this) }>
  23. <Text style={styles.button}>Change Buttons</Text>
  24. </TouchableOpacity>
  25. <TouchableOpacity onPress={ this.onChangeTitlePress.bind(this) }>
  26. <Text style={styles.button}>Change Title</Text>
  27. </TouchableOpacity>
  28. <TouchableOpacity onPress={ this.onSwitchTabPress.bind(this) }>
  29. <Text style={styles.button}>Switch To Tab#1</Text>
  30. </TouchableOpacity>
  31. <TouchableOpacity onPress={ this.onSetTabBadgePress.bind(this) }>
  32. <Text style={styles.button}>Set Tab Badge</Text>
  33. </TouchableOpacity>
  34. <TouchableOpacity onPress={ this.onToggleTabsPress.bind(this) }>
  35. <Text style={styles.button}>Toggle Tabs</Text>
  36. </TouchableOpacity>
  37. </View>
  38. );
  39. }
  40. onChangeTitlePress() {
  41. this.props.navigator.setTitle({
  42. title: Math.round(Math.random() * 100000).toString()
  43. });
  44. }
  45. onChangeButtonsPress() {
  46. let buttons;
  47. if (this.buttonsCounter % 3 == 0) {
  48. buttons = [
  49. {
  50. title: 'Edit',
  51. id: 'edit',
  52. disabled: true
  53. },
  54. {
  55. icon: require('../../img/navicon_add.png'),
  56. id: 'add'
  57. }
  58. ];
  59. } else if (this.buttonsCounter % 3 == 1) {
  60. buttons = [{
  61. title: 'Save',
  62. id: 'save'
  63. }];
  64. } else {
  65. buttons = [];
  66. }
  67. this.buttonsCounter++;
  68. this.props.navigator.setButtons({
  69. rightButtons: buttons,
  70. animated: true
  71. });
  72. }
  73. onSwitchTabPress() {
  74. this.props.navigator.switchToTab({
  75. tabIndex: 0
  76. });
  77. }
  78. onSetTabBadgePress() {
  79. this.props.navigator.setTabBadge({
  80. badge: 12
  81. });
  82. }
  83. onToggleTabsPress() {
  84. this.props.navigator.toggleTabs({
  85. to: this.tabsHidden ? 'shown' : 'hidden'
  86. });
  87. this.tabsHidden = !this.tabsHidden;
  88. }
  89. onNavigatorEvent(event) {
  90. // handle a deep link
  91. if (event.type == 'DeepLink') {
  92. const parts = event.link.split('/');
  93. if (parts[0] == 'tab2') {
  94. this.props.navigator.resetTo({
  95. title: "Replaced Root",
  96. screen: parts[1],
  97. animated: true
  98. });
  99. this.props.navigator.switchToTab();
  100. }
  101. }
  102. // handle a button press
  103. // if (event.type == 'NavBarButtonPress') {
  104. // if (event.id == 'edit') {
  105. // AlertIOS.alert('NavBar', 'Dynamic Edit button pressed');
  106. // }
  107. // if (event.id == 'add') {
  108. // AlertIOS.alert('NavBar', 'Dynamic Add button pressed');
  109. // }
  110. // if (event.id == 'save') {
  111. // AlertIOS.alert('NavBar', 'Dynamic Save button pressed');
  112. // }
  113. // }
  114. }
  115. }
  116. const styles = StyleSheet.create({
  117. button: {
  118. textAlign: 'center',
  119. fontSize: 18,
  120. marginBottom: 10,
  121. marginTop:10,
  122. color: 'blue'
  123. }
  124. });