react-native-navigation的迁移库

OptionsScreen.js 3.0KB

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