react-native-navigation的迁移库

ButtonsScreen.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. PUSH_BTN,
  10. TOP_BAR,
  11. ROUND_BUTTON,
  12. BUTTON_ONE,
  13. LEFT_BUTTON,
  14. SHOW_LIFECYCLE_BTN,
  15. RESET_BUTTONS,
  16. CHANGE_BUTTON_PROPS
  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. rightButtons: [
  28. {
  29. id: 'ONE',
  30. testID: BUTTON_ONE,
  31. text: 'One',
  32. color: Colors.primary
  33. },
  34. {
  35. id: 'ROUND',
  36. testID: ROUND_BUTTON,
  37. component: {
  38. id: 'ROUND_COMPONENT',
  39. name: Screens.RoundButton,
  40. passProps: {
  41. title: 'Two'
  42. }
  43. }
  44. }
  45. ],
  46. leftButtons: [
  47. {
  48. id: 'LEFT',
  49. testID: LEFT_BUTTON,
  50. icon: require('../../img/clear.png'),
  51. color: Colors.primary
  52. }
  53. ]
  54. }
  55. };
  56. }
  57. render() {
  58. return (
  59. <Root componentId={this.props.componentId}>
  60. <Button label='Push' testID={PUSH_BTN} onPress={this.push} />
  61. <Button label='Show Lifecycle button' testID={SHOW_LIFECYCLE_BTN} onPress={this.showLifecycleButton} />
  62. <Button label='Remove all buttons' testID={RESET_BUTTONS} onPress={this.resetButtons} />
  63. <Button label='Change Button Props' testID={CHANGE_BUTTON_PROPS} onPress={this.changeButtonProps} />
  64. </Root>
  65. );
  66. }
  67. push = () => Navigation.push(this, Screens.Pushed);
  68. showLifecycleButton = () => Navigation.mergeOptions(this, {
  69. topBar: {
  70. rightButtons: [
  71. {
  72. id: 'ROUND',
  73. testID: ROUND_BUTTON,
  74. component: {
  75. name: Screens.LifecycleButton,
  76. passProps: {
  77. title: 'Two'
  78. }
  79. }
  80. }
  81. ]
  82. }
  83. });
  84. resetButtons = () => Navigation.mergeOptions(this, {
  85. topBar: {
  86. rightButtons: [],
  87. leftButtons: []
  88. }
  89. });
  90. changeButtonProps = () => {
  91. Navigation.mergeOptions('ROUND_COMPONENT', {
  92. passProps: {
  93. title: 'Three'
  94. }
  95. });
  96. }
  97. }
  98. module.exports = Options;