react-native-navigation的迁移库

LayoutsScreen.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. const React = require('react');
  2. const Root = require('../components/Root');
  3. const Button = require('../components/Button')
  4. const {
  5. WELCOME_SCREEN_HEADER,
  6. STACK_BTN,
  7. BOTTOM_TABS_BTN,
  8. BOTTOM_TABS,
  9. SIDE_MENU_BTN
  10. } = require('../testIDs');
  11. const Screens = require('./Screens');
  12. const Navigation = require('../services/Navigation');
  13. const {stack, component} = require('../commons/Layouts');
  14. class LayoutsScreen extends React.Component {
  15. static options() {
  16. return {
  17. topBar: {
  18. testID: WELCOME_SCREEN_HEADER,
  19. title: {
  20. text: 'React Native Navigation'
  21. }
  22. }
  23. };
  24. }
  25. render() {
  26. return (
  27. <Root componentId={this.props.componentId}>
  28. <Button label='Stack' testID={STACK_BTN} onPress={this.stack} />
  29. <Button label='BottomTabs' testID={BOTTOM_TABS_BTN} onPress={this.bottomTabs} />
  30. <Button label='SideMenu' testID={SIDE_MENU_BTN} onPress={this.sideMenu} />
  31. </Root>
  32. );
  33. }
  34. stack = () => Navigation.showModal(Screens.Stack);
  35. bottomTabs = () => Navigation.showModal({
  36. bottomTabs: {
  37. children: [
  38. stack(Screens.FirstBottomTabsScreen),
  39. stack({
  40. component: {
  41. name: Screens.SecondBottomTabsScreen
  42. }
  43. }, 'SecondTab'
  44. )
  45. ],
  46. options: {
  47. bottomTabs: {
  48. testID: BOTTOM_TABS
  49. }
  50. }
  51. }
  52. });
  53. sideMenu = () => Navigation.showModal({
  54. sideMenu: {
  55. left: {...component(Screens.SideMenuLeft)},
  56. center: stack({
  57. component: {
  58. id: 'SideMenuCenter',
  59. name: Screens.SideMenuCenter
  60. }
  61. }),
  62. right: {...component(Screens.SideMenuRight)}
  63. }
  64. });
  65. onClickSplitView = () => {
  66. Navigation.setRoot({
  67. root: {
  68. splitView: {
  69. id: 'SPLITVIEW_ID',
  70. master: {
  71. stack: {
  72. id: 'MASTER_ID',
  73. children: [
  74. {
  75. component: {
  76. name: 'navigation.playground.WelcomeScreen'
  77. },
  78. },
  79. ]
  80. },
  81. },
  82. detail: {
  83. stack: {
  84. id: 'DETAILS_ID',
  85. children: [
  86. {
  87. component: {
  88. name: 'navigation.playground.WelcomeScreen'
  89. },
  90. },
  91. ]
  92. }
  93. },
  94. options: {
  95. displayMode: 'auto',
  96. primaryEdge: 'leading',
  97. minWidth: 150,
  98. maxWidth: 300,
  99. },
  100. },
  101. },
  102. });
  103. }
  104. onClickSearchBar = () => {
  105. Navigation.push(this.props.componentId, {
  106. component: {
  107. name: 'navigation.playground.SearchControllerScreen'
  108. }
  109. });
  110. };
  111. }
  112. module.exports = LayoutsScreen;