react-native-navigation的迁移库

OptionsScreen.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. const React = require('react');
  2. const {Component} = require('react');
  3. const Root = require('../components/Root');
  4. const Button = require('../components/Button')
  5. const Navigation = require('../services/Navigation');
  6. const Screens = require('./Screens');
  7. const Colors = require('../commons/Colors');
  8. const {
  9. CHANGE_TITLE_BTN,
  10. HIDE_TOP_BAR_BTN,
  11. SHOW_TOP_BAR_BTN,
  12. TOP_BAR,
  13. ROUND_BUTTON,
  14. BUTTON_ONE,
  15. LEFT_BUTTON,
  16. PUSH_BTN,
  17. HIDE_TOPBAR_DEFAULT_OPTIONS,
  18. SHOW_YELLOW_BOX_BTN,
  19. SET_REACT_TITLE_VIEW,
  20. RESET_BUTTONS,
  21. SHOW_LIFECYCLE_BTN
  22. } = require('../testIDs');
  23. class Options extends Component {
  24. static options() {
  25. return {
  26. topBar: {
  27. visible: true,
  28. testID: TOP_BAR,
  29. title: {
  30. text: 'Styling Options'
  31. },
  32. rightButtons: [
  33. {
  34. id: 'ONE',
  35. testID: BUTTON_ONE,
  36. text: 'One',
  37. color: Colors.primary
  38. },
  39. {
  40. id: 'ROUND',
  41. testID: ROUND_BUTTON,
  42. component: {
  43. name: Screens.RoundButton,
  44. passProps: {
  45. title: 'Two'
  46. }
  47. }
  48. }
  49. ],
  50. leftButtons: [
  51. {
  52. id: 'LEFT',
  53. testID: LEFT_BUTTON,
  54. icon: require('../../img/clear.png'),
  55. color: Colors.primary
  56. }
  57. ]
  58. }
  59. };
  60. }
  61. render() {
  62. return (
  63. <Root componentId={this.props.componentId}>
  64. <Button label='Change title' testID={CHANGE_TITLE_BTN} onPress={this.changeTitle} />
  65. <Button label='Hide TopBar' testID={HIDE_TOP_BAR_BTN} onPress={this.hideTopBar} />
  66. <Button label='Show TopBar' testID={SHOW_TOP_BAR_BTN} onPress={this.showTopBar} />
  67. <Button label='Push' testID={PUSH_BTN} onPress={this.push} />
  68. <Button label='Hide TopBar in DefaultOptions' testID={HIDE_TOPBAR_DEFAULT_OPTIONS} onPress={this.hideTopBarInDefaultOptions} />
  69. <Button label='Set React Title View' testID={SET_REACT_TITLE_VIEW} onPress={this.setReactTitleView} />
  70. <Button label='Show Yellow Box' testID={SHOW_YELLOW_BOX_BTN} onPress={() => console.warn('Yellow Box')} />
  71. <Button label='StatusBar' onPress={this.statusBarScreen} />
  72. <Button label='Show Lifecycle button' testID={SHOW_LIFECYCLE_BTN} onPress={this.showLifecycleButton} />
  73. <Button label='Remove all buttons' testID={RESET_BUTTONS} onPress={this.resetButtons} />
  74. </Root>
  75. );
  76. }
  77. showLifecycleButton = () => Navigation.mergeOptions(this, {
  78. topBar: {
  79. rightButtons: [
  80. {
  81. id: 'ROUND',
  82. testID: ROUND_BUTTON,
  83. component: {
  84. name: Screens.LifecycleButton,
  85. passProps: {
  86. title: 'Two'
  87. }
  88. }
  89. }
  90. ]
  91. }
  92. });
  93. resetButtons = () => Navigation.mergeOptions(this, {
  94. topBar: {
  95. rightButtons: [],
  96. leftButtons: []
  97. }
  98. });
  99. changeTitle = () => Navigation.mergeOptions(this, {
  100. topBar: {
  101. title: {
  102. text: 'Title Changed'
  103. }
  104. }
  105. });
  106. hideTopBar = () => Navigation.mergeOptions(this, {
  107. topBar: {
  108. visible: false
  109. }
  110. });
  111. showTopBar = () => Navigation.mergeOptions(this, {
  112. topBar: {
  113. visible: true
  114. }
  115. });
  116. push = () => Navigation.push(this, Screens.Pushed);
  117. hideTopBarInDefaultOptions = () => {
  118. Navigation.setDefaultOptions({
  119. topBar: {
  120. visible: false,
  121. title: {
  122. text: 'Default Title'
  123. }
  124. }
  125. });
  126. }
  127. setReactTitleView = () => Navigation.mergeOptions(this, {
  128. topBar: {
  129. title: {
  130. component: {
  131. name: Screens.ReactTitleView,
  132. alignment: 'center',
  133. passProps: {
  134. text: 'Press Me'
  135. }
  136. }
  137. }
  138. }
  139. });
  140. statusBarScreen = () => Navigation.showModal(Screens.StatusBar);
  141. }
  142. module.exports = Options;