react-native-navigation的迁移库

TextScreen.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 navigationOptions() {
  8. return {
  9. bottomTabs: {
  10. testID: testIDs.BOTTOM_TABS_ELEMENT
  11. }
  12. };
  13. }
  14. render() {
  15. return (
  16. <View style={styles.root}>
  17. <Text style={styles.h1} testID={testIDs.CENTERED_TEXT_HEADER}>{this.props.text || 'Text Screen'}</Text>
  18. {this.renderTextFromFunctionInProps()}
  19. <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
  20. <Button title={'Set Tab Badge'} testID={testIDs.SET_TAB_BADGE_BUTTON} onPress={() => this.onButtonPress()} />
  21. <Button title={'Switch To Tab 2'} testID={testIDs.SWITCH_SECOND_TAB_BUTTON} onPress={() => this.onClickSwitchToTab()} />
  22. <Button title="Hide Tab Bar" testID={testIDs.HIDE_BOTTOM_TABS_BUTTON} onPress={() => this.hideTabBar(true)} />
  23. <Button title="Show Tab Bar" testID={testIDs.SHOW_BOTTOM_TABS_BUTTON} onPress={() => this.hideTabBar(false)} />
  24. <Button title="Show Left Side Menu" testID={testIDs.SHOW_LEFT_SIDE_MENU_BUTTON} onPress={() => this.showSideMenu('left')} />
  25. <Button title="Show Right Side Menu" testID={testIDs.SHOW_RIGHT_SIDE_MENU_BUTTON} onPress={() => this.showSideMenu('right')} />
  26. </View>
  27. );
  28. }
  29. renderTextFromFunctionInProps() {
  30. if (!this.props.myFunction) {
  31. return undefined;
  32. }
  33. return (
  34. <Text style={styles.h1}>{this.props.myFunction()}</Text>
  35. );
  36. }
  37. onButtonPress() {
  38. Navigation.setOptions(this.props.containerId, {
  39. bottomTab: {
  40. badge: `TeSt`
  41. }
  42. });
  43. }
  44. onClickSwitchToTab() {
  45. Navigation.setOptions(this.props.containerId, {
  46. bottomTabs: {
  47. currentTabIndex: 1,
  48. hidden: true,
  49. animateHide: true
  50. }
  51. });
  52. }
  53. hideTabBar(hidden) {
  54. Navigation.setOptions(this.props.containerId, {
  55. bottomTabs: {
  56. hidden
  57. }
  58. });
  59. }
  60. showSideMenu(side) {
  61. Navigation.setOptions(this.props.containerId, {
  62. sideMenu: {
  63. [side]: {
  64. visible: true
  65. }
  66. }
  67. });
  68. }
  69. }
  70. module.exports = TextScreen;
  71. const styles = {
  72. root: {
  73. flexGrow: 1,
  74. justifyContent: 'center',
  75. alignItems: 'center',
  76. backgroundColor: '#f5fcff'
  77. },
  78. h1: {
  79. fontSize: 24,
  80. textAlign: 'center',
  81. margin: 10
  82. },
  83. h2: {
  84. fontSize: 12,
  85. textAlign: 'center',
  86. margin: 10
  87. },
  88. footer: {
  89. fontSize: 10,
  90. color: '#888',
  91. marginTop: 10
  92. }
  93. };