react-native-navigation的迁移库

TextScreen.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. let globalFirstComponentID;
  7. class TextScreen extends Component {
  8. static get options() {
  9. return {
  10. bottomTabs: {
  11. testID: testIDs.BOTTOM_TABS_ELEMENT
  12. }
  13. };
  14. }
  15. constructor(props) {
  16. super(props);
  17. globalFirstComponentID = (props.text === 'This is tab 1') ? props.componentId : globalFirstComponentID;
  18. this.onClickPop = this.onClickPop.bind(this);
  19. }
  20. render() {
  21. return (
  22. <View style={styles.root}>
  23. <Text style={styles.h1} testID={testIDs.CENTERED_TEXT_HEADER}>{this.props.text || 'Text Screen'}</Text>
  24. {this.renderTextFromFunctionInProps()}
  25. <Text style={styles.footer}>{`this.props.componentId = ${this.props.componentId}`}</Text>
  26. <Button title={'Set Tab Badge'} testID={testIDs.SET_TAB_BADGE_BUTTON} onPress={() => this.onButtonPress()} />
  27. <Button title={'Switch To Tab 2'} testID={testIDs.SWITCH_SECOND_TAB_BUTTON} onPress={() => this.onClickSwitchToTab()} />
  28. <Button title={'Switch To Tab 1 by componentID'} testID={testIDs.SWITCH_FIRST_TAB_BUTTON} onPress={() => this.onClickSwitchToTabByComponentID()} />
  29. <Button title='Hide Tab Bar' testID={testIDs.HIDE_BOTTOM_TABS_BUTTON} onPress={() => this.hideTabBar(true)} />
  30. <Button title='Show Tab Bar' testID={testIDs.SHOW_BOTTOM_TABS_BUTTON} onPress={() => this.hideTabBar(false)} />
  31. <Button title='Show Left Side Menu' testID={testIDs.SHOW_LEFT_SIDE_MENU_BUTTON} onPress={() => this.showSideMenu('left')} />
  32. <Button title='Show Right Side Menu' testID={testIDs.SHOW_RIGHT_SIDE_MENU_BUTTON} onPress={() => this.showSideMenu('right')} />
  33. <Button title='Pop' testID={testIDs.POP_BUTTON} onPress={this.onClickPop} />
  34. </View>
  35. );
  36. }
  37. async onClickPop() {
  38. await Navigation.pop(this.props.componentId);
  39. }
  40. renderTextFromFunctionInProps() {
  41. if (!this.props.myFunction) {
  42. return undefined;
  43. }
  44. return (
  45. <Text style={styles.h1}>{this.props.myFunction()}</Text>
  46. );
  47. }
  48. onButtonPress() {
  49. Navigation.setOptions(this.props.componentId, {
  50. bottomTab: {
  51. badge: `TeSt`
  52. }
  53. });
  54. }
  55. onClickSwitchToTab() {
  56. Navigation.setOptions(this.props.componentId, {
  57. bottomTabs: {
  58. currentTabIndex: 1,
  59. hidden: true,
  60. animateHide: true
  61. }
  62. });
  63. }
  64. onClickSwitchToTabByComponentID() {
  65. Navigation.setOptions(this.props.componentId, {
  66. bottomTabs: {
  67. currentTabId: globalFirstComponentID
  68. }
  69. });
  70. }
  71. hideTabBar(hidden) {
  72. Navigation.setOptions(this.props.componentId, {
  73. bottomTabs: {
  74. hidden
  75. }
  76. });
  77. }
  78. showSideMenu(side) {
  79. Navigation.setOptions(this.props.componentId, {
  80. sideMenu: {
  81. [side]: {
  82. visible: true
  83. }
  84. }
  85. });
  86. }
  87. }
  88. module.exports = TextScreen;
  89. const styles = {
  90. root: {
  91. flexGrow: 1,
  92. justifyContent: 'center',
  93. alignItems: 'center',
  94. backgroundColor: '#f5fcff'
  95. },
  96. h1: {
  97. fontSize: 24,
  98. textAlign: 'center',
  99. margin: 10
  100. },
  101. h2: {
  102. fontSize: 12,
  103. textAlign: 'center',
  104. margin: 10
  105. },
  106. footer: {
  107. fontSize: 10,
  108. color: '#888',
  109. marginTop: 10
  110. }
  111. };