react-native-navigation的迁移库

FirstBottomTabScreen.js 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. const React = require('react');
  2. const Root = require('../components/Root');
  3. const Button = require('../components/Button')
  4. const Navigation = require('./../services/Navigation');
  5. const Screens = require('./Screens');
  6. const { component } = require('../commons/Layouts');
  7. const {
  8. SWITCH_TAB_BY_INDEX_BTN,
  9. SWITCH_TAB_BY_COMPONENT_ID_BTN,
  10. SET_BADGE_BTN,
  11. CLEAR_BADGE_BTN,
  12. HIDE_TABS_BTN,
  13. SHOW_TABS_BTN,
  14. HIDE_TABS_PUSH_BTN
  15. } = require('../testIDs')
  16. class FirstBottomTabScreen extends React.Component {
  17. static options() {
  18. return {
  19. layout: {
  20. orientation: ['portrait', 'landscape']
  21. },
  22. topBar: {
  23. title: {
  24. text: 'First Tab'
  25. }
  26. },
  27. bottomTab: {
  28. icon: require('../../img/whatshot.png'),
  29. text: 'Tab 1',
  30. dotIndicator: { visible: true }
  31. }
  32. };
  33. }
  34. constructor(props) {
  35. super(props);
  36. this.dotVisible = true;
  37. }
  38. render() {
  39. return (
  40. <Root componentId={this.props.componentId}>
  41. <Button label='Switch Tab by Index' testID={SWITCH_TAB_BY_INDEX_BTN} onPress={this.switchTabByIndex} />
  42. <Button label='Switch Tab by componentId' testID={SWITCH_TAB_BY_COMPONENT_ID_BTN} onPress={this.switchTabByComponentId} />
  43. <Button label='Set Badge' testID={SET_BADGE_BTN} onPress={() => this.setBadge('NEW')} />
  44. <Button label='Clear Badge' testID={CLEAR_BADGE_BTN} onPress={() => this.setBadge('')} />
  45. <Button label='Set Notification Dot' onPress={this.setNotificationDot} />
  46. <Button label='Hide Tabs' testID={HIDE_TABS_BTN} onPress={() => this.toggleTabs(false)} />
  47. <Button label='Show Tabs' testID={SHOW_TABS_BTN} onPress={() => this.toggleTabs(true)} />
  48. <Button label='Hide Tabs on Push' testID={HIDE_TABS_PUSH_BTN} onPress={this.hideTabsOnPush} />
  49. <Button label='Push' onPress={this.push} />
  50. </Root>
  51. );
  52. }
  53. switchTabByIndex = () => Navigation.mergeOptions(this, {
  54. bottomTabs: {
  55. currentTabIndex: 1
  56. }
  57. });
  58. switchTabByComponentId = () => Navigation.mergeOptions('SecondTab', {
  59. bottomTabs: {
  60. currentTabId: 'SecondTab'
  61. }
  62. });
  63. setBadge = (badge) => {
  64. this.badgeVisible = !!badge;
  65. if (this.badgeVisible) this.dotVisible = false;
  66. Navigation.mergeOptions(this, {
  67. bottomTab: { badge, animateBadge: true }
  68. });
  69. }
  70. setNotificationDot = () => {
  71. this.dotVisible = !this.dotVisible;
  72. Navigation.mergeOptions(this, {
  73. bottomTab: {
  74. dotIndicator: { visible: this.dotVisible, animate: true }
  75. }
  76. });
  77. }
  78. toggleTabs = (visible) => Navigation.mergeOptions(this, {
  79. bottomTabs: { visible }
  80. });
  81. hideTabsOnPush = () => Navigation.push(this, component(Screens.Pushed, {
  82. bottomTabs: { visible: false }
  83. }));
  84. push = () => Navigation.push(this, Screens.Pushed);
  85. }
  86. module.exports = FirstBottomTabScreen;