react-native-navigation的迁移库

OptionsScreen.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 {
  8. CHANGE_TITLE_BTN,
  9. HIDE_TOP_BAR_BTN,
  10. SHOW_TOP_BAR_BTN,
  11. TOP_BAR,
  12. PUSH_BTN,
  13. HIDE_TOPBAR_DEFAULT_OPTIONS,
  14. SHOW_YELLOW_BOX_BTN,
  15. SET_REACT_TITLE_VIEW,
  16. GOTO_BUTTONS_SCREEN,
  17. } = require('../testIDs');
  18. class Options extends Component {
  19. static options() {
  20. return {
  21. topBar: {
  22. visible: true,
  23. testID: TOP_BAR,
  24. title: {
  25. text: 'Styling Options'
  26. }
  27. }
  28. };
  29. }
  30. state = {
  31. isAndroidNavigationBarVisible: true
  32. };
  33. render() {
  34. return (
  35. <Root componentId={this.props.componentId}>
  36. <Button label='Change title' testID={CHANGE_TITLE_BTN} onPress={this.changeTitle} />
  37. <Button label='Hide TopBar' testID={HIDE_TOP_BAR_BTN} onPress={this.hideTopBar} />
  38. <Button label='Show TopBar' testID={SHOW_TOP_BAR_BTN} onPress={this.showTopBar} />
  39. <Button label='Push' testID={PUSH_BTN} onPress={this.push} />
  40. <Button label='Hide TopBar in DefaultOptions' testID={HIDE_TOPBAR_DEFAULT_OPTIONS} onPress={this.hideTopBarInDefaultOptions} />
  41. <Button label='Set React Title View' testID={SET_REACT_TITLE_VIEW} onPress={this.setReactTitleView} />
  42. <Button label='Show Yellow Box' testID={SHOW_YELLOW_BOX_BTN} onPress={() => console.warn('Yellow Box')} />
  43. <Button label='StatusBar' onPress={this.statusBarScreen} />
  44. <Button label='Buttons Screen' testID={GOTO_BUTTONS_SCREEN} onPress={this.pushButtonsScreen} />
  45. <Button label='Toggle Navigation bar visibility' platform='android' onPress={this.toggleAndroidNavigationBar}/>
  46. </Root>
  47. );
  48. }
  49. changeTitle = () => Navigation.mergeOptions(this, {
  50. topBar: {
  51. title: {
  52. text: 'Title Changed'
  53. }
  54. }
  55. });
  56. hideTopBar = () => Navigation.mergeOptions(this, {
  57. topBar: {
  58. visible: false
  59. }
  60. });
  61. showTopBar = () => Navigation.mergeOptions(this, {
  62. topBar: {
  63. visible: true
  64. }
  65. });
  66. toggleAndroidNavigationBar = () => {
  67. this.setState({isAndroidNavigationBarVisible: !this.state.isAndroidNavigationBarVisible});
  68. Navigation.mergeOptions(this, {
  69. navigationBar: {
  70. visible: !this.state.isAndroidNavigationBarVisible
  71. }
  72. })
  73. };
  74. push = () => Navigation.push(this, {
  75. component: {
  76. name: Screens.Pushed,
  77. passProps: {
  78. previousScreenIds: [this.props.componentId]
  79. }
  80. }
  81. });
  82. hideTopBarInDefaultOptions = () => {
  83. Navigation.setDefaultOptions({
  84. topBar: {
  85. visible: false,
  86. title: {
  87. text: 'Default Title'
  88. }
  89. }
  90. });
  91. }
  92. setReactTitleView = () => Navigation.mergeOptions(this, {
  93. topBar: {
  94. title: {
  95. component: {
  96. name: Screens.ReactTitleView,
  97. alignment: 'center',
  98. passProps: {
  99. text: 'Press Me'
  100. }
  101. }
  102. }
  103. }
  104. });
  105. statusBarScreen = () => Navigation.showModal(Screens.StatusBar);
  106. pushButtonsScreen = () => Navigation.push(this, Screens.Buttons, {
  107. animations: {
  108. push: {
  109. waitForRender: true
  110. }
  111. }
  112. });
  113. }
  114. module.exports = Options;