react-native-navigation的迁移库

TextScreen.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. const React = require('react');
  2. const { Component } = require('react');
  3. const { View, Text, Button } = require('react-native');
  4. const { Navigation } = require('react-native-navigation');
  5. const testIDs = require('../testIDs');
  6. class TextScreen extends Component {
  7. static get options() {
  8. return {
  9. bottomTabs: {
  10. drawBehind: true,
  11. testID: testIDs.BOTTOM_TABS_ELEMENT
  12. },
  13. topBar: {
  14. testID: testIDs.TOP_BAR_ELEMENT
  15. }
  16. };
  17. }
  18. render() {
  19. return (
  20. <View style={styles.root}>
  21. <Text style={styles.h1} testID={testIDs.CENTERED_TEXT_HEADER}>{this.props.text || 'Text Screen'}</Text>
  22. {this.renderTextFromFunctionInProps()}
  23. <Text style={styles.footer}>{`this.props.componentId = ${this.props.componentId}`}</Text>
  24. <Button title={'Set Tab Badge'} testID={testIDs.SET_TAB_BADGE_BUTTON} onPress={() => this.onClickSetBadge()} />
  25. <Button title={'Switch To Tab 2'} testID={testIDs.SWITCH_SECOND_TAB_BUTTON} onPress={() => this.onClickSwitchToTab()} />
  26. <Button title={'Switch To Tab 1 by componentID'} testID={testIDs.SWITCH_FIRST_TAB_BUTTON} onPress={() => this.onClickSwitchToTabByComponentID()} />
  27. <Button title='Hide Tab Bar' testID={testIDs.HIDE_BOTTOM_TABS_BUTTON} onPress={() => this.hideTabBar(false)} />
  28. <Button title='Show Tab Bar' testID={testIDs.SHOW_BOTTOM_TABS_BUTTON} onPress={() => this.hideTabBar(true)} />
  29. <Button title='Hide Tab Bar on Push' testID={testIDs.HIDE_BOTTOM_TABS_ON_PUSH_BUTTON} onPress={() => this.hideTabBarOnPush()} />
  30. <Button title='Show Left Side Menu' testID={testIDs.SHOW_LEFT_SIDE_MENU_BUTTON} onPress={() => this.showSideMenu('left')} />
  31. <Button title='Show Right Side Menu' testID={testIDs.SHOW_RIGHT_SIDE_MENU_BUTTON} onPress={() => this.showSideMenu('right')} />
  32. <Button title='Push' testID={testIDs.PUSH_BUTTON} onPress={this.onClickPush} />
  33. <Button title='Pop' testID={testIDs.POP_BUTTON} onPress={this.onClickPop} />
  34. </View>
  35. );
  36. }
  37. onClickPush = async () => {
  38. await Navigation.push(this.props.componentId, {
  39. component: {
  40. name: 'navigation.playground.PushedScreen'
  41. }
  42. });
  43. }
  44. onClickPop = async () => {
  45. await Navigation.pop(this.props.componentId);
  46. }
  47. renderTextFromFunctionInProps() {
  48. if (!this.props.myFunction) {
  49. return undefined;
  50. }
  51. return (
  52. <Text style={styles.h1}>{this.props.myFunction()}</Text>
  53. );
  54. }
  55. onClickSetBadge() {
  56. Navigation.mergeOptions(this.props.componentId, {
  57. bottomTab: {
  58. badge: `TeSt`
  59. }
  60. });
  61. }
  62. onClickSwitchToTab() {
  63. Navigation.mergeOptions(this.props.componentId, {
  64. bottomTabs: {
  65. currentTabIndex: 1,
  66. visible: false,
  67. drawBehind: true,
  68. animate: true
  69. }
  70. });
  71. }
  72. onClickSwitchToTabByComponentID() {
  73. Navigation.mergeOptions(this.props.componentId, {
  74. bottomTabs: {
  75. currentTabId: 'TAB1_ID'
  76. }
  77. });
  78. }
  79. hideTabBar(visible) {
  80. Navigation.mergeOptions(this.props.componentId, {
  81. bottomTabs: {
  82. visible,
  83. drawBehind: true,
  84. animate: true
  85. }
  86. });
  87. }
  88. hideTabBarOnPush() {
  89. Navigation.push(this.props.componentId, {
  90. component: {
  91. name: 'navigation.playground.PushedScreen'
  92. }
  93. });
  94. }
  95. showSideMenu(side) {
  96. Navigation.mergeOptions(this.props.componentId, {
  97. sideMenu: {
  98. [side]: {
  99. visible: true
  100. }
  101. }
  102. });
  103. }
  104. onClickPop() {
  105. Navigation.pop(this.props.componentId);
  106. }
  107. }
  108. module.exports = TextScreen;
  109. const styles = {
  110. root: {
  111. flexGrow: 1,
  112. justifyContent: 'center',
  113. alignItems: 'center',
  114. backgroundColor: '#E3DCC3'
  115. },
  116. h1: {
  117. fontSize: 24,
  118. textAlign: 'center',
  119. margin: 10
  120. },
  121. h2: {
  122. fontSize: 12,
  123. textAlign: 'center',
  124. margin: 10
  125. },
  126. footer: {
  127. fontSize: 10,
  128. color: '#888',
  129. marginTop: 10
  130. }
  131. };