react-native-navigation的迁移库

LayoutsScreen.js 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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.StackScreen);
  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: {
  57. ...stack({
  58. component: {
  59. id: 'SideMenuCenter',
  60. name: Screens.SideMenuCenter
  61. }
  62. })
  63. },
  64. right: {...component(Screens.SideMenuRight)}
  65. }
  66. });
  67. onClickSwitchToTabs = () => {
  68. Navigation.setRoot({
  69. root: {
  70. bottomTabs: {
  71. id: 'BottomTabs',
  72. children: [
  73. {
  74. stack: {
  75. id: 'TAB1_ID',
  76. children: [
  77. {
  78. component: {
  79. name: 'navigation.playground.TextScreen',
  80. passProps: {
  81. text: 'This is tab 1',
  82. myFunction: () => 'Hello from a function!'
  83. },
  84. options: {
  85. topBar: {
  86. visible: true,
  87. animate: false,
  88. title: {
  89. text: 'React Native Navigation!'
  90. }
  91. },
  92. bottomTab: {
  93. text: 'Tab 1',
  94. icon: require('../images/colored_tab_icon.png'),
  95. testID: testIDs.FIRST_TAB_BAR_BUTTON
  96. }
  97. }
  98. }
  99. }
  100. ],
  101. options: {
  102. topBar: {
  103. visible: false
  104. }
  105. }
  106. }
  107. },
  108. {
  109. stack: {
  110. children: [
  111. {
  112. component: {
  113. name: 'navigation.playground.TextScreen',
  114. passProps: {
  115. text: 'This is tab 2'
  116. }
  117. }
  118. }
  119. ],
  120. options: {
  121. bottomTab: {
  122. text: 'Tab 2',
  123. icon: require('../images/two.png'),
  124. iconColor: '#1B4C77',
  125. selectedIconColor: '#0f0',
  126. testID: testIDs.SECOND_TAB_BAR_BUTTON
  127. }
  128. }
  129. }
  130. },
  131. {
  132. component: {
  133. name: 'navigation.playground.TextScreen',
  134. passProps: {
  135. text: 'This is tab 3',
  136. myFunction: () => 'Hello from a function!'
  137. },
  138. options: {
  139. topBar: {
  140. visible: true,
  141. animate: false
  142. },
  143. bottomTab: {
  144. text: 'Tab 3',
  145. icon: require('../images/one.png'),
  146. iconColor: '#1B4C77',
  147. selectedIconColor: '#0f0',
  148. selectedIcon: require('../images/one.png')
  149. }
  150. }
  151. }
  152. }
  153. ],
  154. options: {
  155. bottomTabs: {
  156. titleDisplayMode: 'alwaysShow',
  157. testID: testIDs.BOTTOM_TABS_ELEMENT
  158. }
  159. }
  160. }
  161. }
  162. });
  163. }
  164. onClickSwitchToSideMenus = () => {
  165. Navigation.setRoot({
  166. root: {
  167. sideMenu: {
  168. left: {
  169. component: {
  170. name: 'navigation.playground.SideMenuScreen',
  171. passProps: {
  172. side: 'left'
  173. }
  174. }
  175. },
  176. center: {
  177. bottomTabs: {
  178. children: [
  179. {
  180. stack: {
  181. id: 'tab1Stack',
  182. children: [
  183. {
  184. component: {
  185. name: 'navigation.playground.TextScreen',
  186. passProps: {
  187. text: 'This is a side menu center screen tab 1'
  188. }
  189. }
  190. }
  191. ],
  192. options: {
  193. bottomTab: {
  194. iconColor: 'red',
  195. textColor: 'red',
  196. selectedIconColor: 'purple',
  197. selectedTextColor: 'purple',
  198. text: 'Tab 1',
  199. icon: require('../images/one.png'),
  200. testID: testIDs.FIRST_TAB_BAR_BUTTON
  201. }
  202. }
  203. }
  204. },
  205. {
  206. stack: {
  207. children: [
  208. {
  209. component: {
  210. name: 'navigation.playground.TextScreen',
  211. passProps: {
  212. text: 'This is a side menu center screen tab 2'
  213. }
  214. }
  215. }
  216. ],
  217. options: {
  218. bottomTab: {
  219. text: 'Tab 2',
  220. icon: require('../images/two.png'),
  221. testID: testIDs.SECOND_TAB_BAR_BUTTON
  222. }
  223. }
  224. }
  225. },
  226. {
  227. stack: {
  228. children: [
  229. {
  230. component: {
  231. name: 'navigation.playground.TextScreen',
  232. passProps: {
  233. text: 'This is a side menu center screen tab 3'
  234. }
  235. }
  236. }
  237. ],
  238. options: {
  239. bottomTab: {
  240. text: 'Tab 3',
  241. icon: require('../images/three.png'),
  242. testID: testIDs.SECOND_TAB_BAR_BUTTON
  243. }
  244. }
  245. }
  246. }
  247. ],
  248. options: {
  249. bottomTab: {
  250. textColor: '#AED581',
  251. iconColor: '#AED581',
  252. selectedTextColor: '#90CAF9',
  253. selectedIconColor: '#90CAF9',
  254. fontFamily: 'HelveticaNeue-Italic',
  255. fontSize: 13
  256. }
  257. }
  258. }
  259. },
  260. right: {
  261. component: {
  262. name: 'navigation.playground.SideMenuScreen',
  263. passProps: {
  264. side: 'right'
  265. }
  266. }
  267. }
  268. }
  269. }
  270. });
  271. }
  272. onClickPush = async () => {
  273. await Navigation.push(this.props.componentId, {
  274. component: {
  275. name: 'navigation.playground.PushedScreen',
  276. options: {
  277. layout: {
  278. },
  279. topBar: {
  280. title: {
  281. text: 'pushed',
  282. color: '#0000ff',
  283. fontSize: 14
  284. },
  285. subtitle: {
  286. text: 'subtitle',
  287. fontSize: 10,
  288. color: '#00ff00'
  289. }
  290. }
  291. }
  292. }
  293. });
  294. }
  295. onClickPushContextScreen = async () => {
  296. await Navigation.push(this.props.componentId, {
  297. component: {
  298. name: 'navigation.playground.ContextScreen',
  299. }
  300. })
  301. }
  302. onClickPushExternalComponent = async () => {
  303. await Navigation.push(this.props.componentId, {
  304. externalComponent: {
  305. name: 'RNNCustomComponent',
  306. passProps: {
  307. text: 'This is an external component'
  308. },
  309. options: {
  310. topBar: {
  311. title: {
  312. text: 'pushed'
  313. },
  314. visible: true,
  315. testID: testIDs.TOP_BAR_ELEMENT
  316. }
  317. }
  318. }
  319. });
  320. }
  321. onClickLifecycleScreen = () => {
  322. Navigation.push(this.props.componentId, {
  323. component: {
  324. name: 'navigation.playground.LifecycleScreen'
  325. }
  326. });
  327. }
  328. onClickShowStaticLifecycleOverlay = () => {
  329. Navigation.showOverlay({
  330. component: {
  331. name: 'navigation.playground.StaticLifecycleOverlay',
  332. options: {
  333. overlay: {
  334. interceptTouchOutside: false
  335. }
  336. }
  337. }
  338. });
  339. }
  340. onClickShowModal = async () => {
  341. await Navigation.showModal({
  342. stack: {
  343. children: [
  344. {
  345. component: {
  346. name: 'navigation.playground.ModalScreen'
  347. }
  348. }
  349. ]
  350. }
  351. });
  352. }
  353. onClickShowRedbox = () => {
  354. undefined();
  355. }
  356. onClickShowPreview = async ({reactTag}) => {
  357. await Navigation.push(this.props.componentId, {
  358. component: {
  359. name: 'navigation.playground.PushedScreen',
  360. options: {
  361. animations: {
  362. push: {
  363. enabled: false
  364. }
  365. },
  366. preview: reactTag ? {
  367. reactTag,
  368. height: 300,
  369. commit: true,
  370. actions: [{
  371. id: 'action-cancel',
  372. title: 'Cancel'
  373. }, {
  374. id: 'action-delete',
  375. title: 'Delete',
  376. actions: [{
  377. id: 'action-delete-sure',
  378. title: 'Are you sure?',
  379. style: 'destructive'
  380. }]
  381. }]
  382. } : undefined,
  383. }
  384. }
  385. });
  386. }
  387. onClickPushOptionsScreen = () => {
  388. Navigation.push(this.props.componentId, {
  389. component: {
  390. name: 'navigation.playground.OptionsScreen',
  391. options: {
  392. animations: {
  393. push: {
  394. enabled: false
  395. }
  396. }
  397. }
  398. }
  399. });
  400. }
  401. onClickPushTopTabsScreen = () => {
  402. Navigation.push(this.props.componentId, {
  403. topTabs: {
  404. children: [
  405. {
  406. component: {
  407. name: 'navigation.playground.TopTabOptionsScreen',
  408. passProps: {
  409. title: 'Tab 1',
  410. text: 'This is top tab 1'
  411. },
  412. options: {
  413. topTab: {
  414. title: 'Tab 1'
  415. },
  416. topBar: {
  417. title: {
  418. text: 'One'
  419. }
  420. }
  421. }
  422. }
  423. },
  424. {
  425. component: {
  426. name: 'navigation.playground.TopTabScreen',
  427. passProps: {
  428. title: 'Tab 2',
  429. text: 'This is top tab 2'
  430. },
  431. options: {
  432. topTab: {
  433. title: 'Tab 2',
  434. titleFontFamily: 'HelveticaNeue-Italic'
  435. },
  436. topBar: {
  437. title: {
  438. text: 'Two'
  439. }
  440. }
  441. }
  442. }
  443. },
  444. {
  445. component: {
  446. name: 'navigation.playground.TopTabScreen',
  447. passProps: {
  448. title: 'Tab 3',
  449. text: 'This is top tab 3'
  450. },
  451. options: {
  452. topTab: {
  453. title: 'Tab 3'
  454. },
  455. topBar: {
  456. title: {
  457. text: 'Three'
  458. }
  459. }
  460. }
  461. }
  462. }
  463. ],
  464. options: {
  465. topTabs: {
  466. selectedTabColor: '#12766b',
  467. unselectedTabColor: 'red',
  468. fontSize: 6
  469. }
  470. }
  471. }
  472. });
  473. }
  474. onClickBackHandler = () => {
  475. Navigation.push(this.props.componentId, {
  476. component: {
  477. name: 'navigation.playground.BackHandlerScreen'
  478. }
  479. });
  480. }
  481. onClickPushOrientationMenuScreen = () => {
  482. Navigation.push(this.props.componentId, {
  483. component: {
  484. name: 'navigation.playground.OrientationSelectScreen'
  485. }
  486. });
  487. }
  488. onClickProvidedId = () => {
  489. Navigation.showModal({
  490. stack: {
  491. children: [
  492. {
  493. component: {
  494. name: 'navigation.playground.TextScreen',
  495. id: 'my unique id'
  496. }
  497. }
  498. ]
  499. }
  500. });
  501. Navigation.mergeOptions('my unique id', {
  502. topBar: {
  503. title: {
  504. text: 'User provided id'
  505. }
  506. }
  507. });
  508. }
  509. onClickComplexLayout = () => {
  510. Navigation.showModal({
  511. component: {
  512. name: 'navigation.playground.ComplexLayout'
  513. }
  514. });
  515. }
  516. onClickSplitView = () => {
  517. Navigation.setRoot({
  518. root: {
  519. splitView: {
  520. id: 'SPLITVIEW_ID',
  521. master: {
  522. stack: {
  523. id: 'MASTER_ID',
  524. children: [
  525. {
  526. component: {
  527. name: 'navigation.playground.WelcomeScreen'
  528. },
  529. },
  530. ]
  531. },
  532. },
  533. detail: {
  534. stack: {
  535. id: 'DETAILS_ID',
  536. children: [
  537. {
  538. component: {
  539. name: 'navigation.playground.WelcomeScreen'
  540. },
  541. },
  542. ]
  543. }
  544. },
  545. options: {
  546. displayMode: 'auto',
  547. primaryEdge: 'leading',
  548. minWidth: 150,
  549. maxWidth: 300,
  550. },
  551. },
  552. },
  553. });
  554. }
  555. onClickSearchBar = () => {
  556. Navigation.push(this.props.componentId, {
  557. component: {
  558. name: 'navigation.playground.SearchControllerScreen'
  559. }
  560. });
  561. };
  562. }
  563. module.exports = LayoutsScreen;