react-native-navigation的迁移库

OptionsScreen.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. render() {
  31. return (
  32. <Root componentId={this.props.componentId}>
  33. <Button label='Change title' testID={CHANGE_TITLE_BTN} onPress={this.changeTitle} />
  34. <Button label='Hide TopBar' testID={HIDE_TOP_BAR_BTN} onPress={this.hideTopBar} />
  35. <Button label='Show TopBar' testID={SHOW_TOP_BAR_BTN} onPress={this.showTopBar} />
  36. <Button label='Push' testID={PUSH_BTN} onPress={this.push} />
  37. <Button label='Hide TopBar in DefaultOptions' testID={HIDE_TOPBAR_DEFAULT_OPTIONS} onPress={this.hideTopBarInDefaultOptions} />
  38. <Button label='Set React Title View' testID={SET_REACT_TITLE_VIEW} onPress={this.setReactTitleView} />
  39. <Button label='Show Yellow Box' testID={SHOW_YELLOW_BOX_BTN} onPress={() => console.warn('Yellow Box')} />
  40. <Button label='StatusBar' onPress={this.statusBarScreen} />
  41. <Button label='Buttons Screen' testID={GOTO_BUTTONS_SCREEN} onPress={this.goToButtonsScreen} />
  42. </Root>
  43. );
  44. }
  45. changeTitle = () => Navigation.mergeOptions(this, {
  46. topBar: {
  47. title: {
  48. text: 'Title Changed'
  49. }
  50. }
  51. });
  52. hideTopBar = () => Navigation.mergeOptions(this, {
  53. topBar: {
  54. visible: false
  55. }
  56. });
  57. showTopBar = () => Navigation.mergeOptions(this, {
  58. topBar: {
  59. visible: true
  60. }
  61. });
  62. push = () => Navigation.push(this, {
  63. component: {
  64. name: Screens.Pushed,
  65. passProps: {
  66. previousScreenIds: [this.props.componentId]
  67. }
  68. }
  69. });
  70. hideTopBarInDefaultOptions = () => {
  71. Navigation.setDefaultOptions({
  72. topBar: {
  73. visible: false,
  74. title: {
  75. text: 'Default Title'
  76. }
  77. }
  78. });
  79. }
  80. setReactTitleView = () => Navigation.mergeOptions(this, {
  81. topBar: {
  82. title: {
  83. component: {
  84. name: Screens.ReactTitleView,
  85. alignment: 'center',
  86. passProps: {
  87. text: 'Press Me'
  88. }
  89. }
  90. }
  91. }
  92. });
  93. statusBarScreen = () => Navigation.showModal(Screens.StatusBar);
  94. goToButtonsScreen = () => Navigation.push(this, Screens.Buttons);
  95. }
  96. module.exports = Options;