react-native-navigation的迁移库

WelcomeScreen.js 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. const React = require('react');
  2. const { Component } = require('react');
  3. const { View, Text, Platform, TouchableHighlight } = require('react-native');
  4. const testIDs = require('../testIDs');
  5. const Button = require('./Button');
  6. const { Navigation } = require('react-native-navigation');
  7. class WelcomeScreen extends Component {
  8. static get options() {
  9. return {
  10. _statusBar: {
  11. backgroundColor: 'transparent',
  12. style: 'dark',
  13. drawBehind: true
  14. },
  15. topBar: {
  16. title: {
  17. text: 'My Screen'
  18. },
  19. largeTitle: {
  20. visible: false,
  21. },
  22. drawBehind: true,
  23. visible: false,
  24. animate: false
  25. }
  26. };
  27. }
  28. render() {
  29. return (
  30. <View style={styles.bar}>
  31. <View style={{ width: 2, height: 2, borderRadius: 1, backgroundColor: 'red', alignSelf: 'center' }} />
  32. <View style={styles.root} key={'root'}>
  33. <Text testID={testIDs.WELCOME_SCREEN_HEADER} style={styles.h1}>{`React Native Navigation!`}</Text>
  34. <Button title='Switch to tab based app' testID={testIDs.TAB_BASED_APP_BUTTON} onPress={this.onClickSwitchToTabs} />
  35. <Button title='Switch to app with side menus' testID={testIDs.TAB_BASED_APP_SIDE_BUTTON} onPress={this.onClickSwitchToSideMenus} />
  36. {Platform.OS === 'ios' && <Button title='Switch to split view based app' testID={testIDs.SPLIT_VIEW_BUTTON} onPress={this.onClickSplitView} />}
  37. <Button title='Push Lifecycle Screen' testID={testIDs.PUSH_LIFECYCLE_BUTTON} onPress={this.onClickLifecycleScreen} />
  38. <Button title='Static Lifecycle Events' testID={testIDs.PUSH_STATIC_LIFECYCLE_BUTTON} onPress={this.onClickShowStaticLifecycleOverlay} />
  39. <Button title='Push' testID={testIDs.PUSH_BUTTON} onPress={this.onClickPush} />
  40. {false && <Button title='Push Context Screen' testID={testIDs.PUSH_CONTEXT_SCREEN_BUTTON} onPress={this.onClickPushContextScreen} />}
  41. {Platform.OS === 'ios' && <Button testID={testIDs.SHOW_PREVIEW_BUTTON} onPress={this.onClickPush} onPressIn={this.onClickShowPreview} title='Push Preview' />}
  42. <Button title='Push Options Screen' testID={testIDs.PUSH_OPTIONS_BUTTON} onPress={this.onClickPushOptionsScreen} />
  43. <Button title='Push External Component' testID={testIDs.PUSH_EXTERNAL_COMPONENT_BUTTON} onPress={this.onClickPushExternalComponent} />
  44. {Platform.OS === 'android' && <Button title='Push Top Tabs screen' testID={testIDs.PUSH_TOP_TABS_BUTTON} onPress={this.onClickPushTopTabsScreen} />}
  45. {Platform.OS === 'android' && <Button title='Back Handler' testID={testIDs.BACK_HANDLER_BUTTON} onPress={this.onClickBackHandler} />}
  46. <Button title='Show Modal' testID={testIDs.SHOW_MODAL_BUTTON} onPress={this.onClickShowModal} />
  47. <Button title='Show Redbox' testID={testIDs.SHOW_REDBOX_BUTTON} onPress={this.onClickShowRedbox} />
  48. <Button title='Orientation' testID={testIDs.ORIENTATION_BUTTON} onPress={this.onClickPushOrientationMenuScreen} />
  49. <Button title='Provided Id' testID={testIDs.PROVIDED_ID} onPress={this.onClickProvidedId} />
  50. <Button title='Complex Layout' testID={testIDs.COMPLEX_LAYOUT_BUTTON} onPress={this.onClickComplexLayout} />
  51. <Button title='Push SearchBar' testID={testIDs.SHOW_TOPBAR_SEARCHBAR} onPress={this.onClickSearchBar} />
  52. <Text style={styles.footer}>{`this.props.componentId = ${this.props.componentId}`}</Text>
  53. </View>
  54. <View style={{ width: 2, height: 2, borderRadius: 1, backgroundColor: 'red', alignSelf: 'center' }} />
  55. </View>
  56. );
  57. }
  58. onClickSwitchToTabs = () => {
  59. Navigation.setRoot({
  60. root: {
  61. bottomTabs: {
  62. id: 'BottomTabs',
  63. children: [
  64. {
  65. stack: {
  66. id: 'TAB1_ID',
  67. children: [
  68. {
  69. component: {
  70. name: 'navigation.playground.TextScreen',
  71. passProps: {
  72. text: 'This is tab 1',
  73. myFunction: () => 'Hello from a function!'
  74. },
  75. options: {
  76. topBar: {
  77. visible: true,
  78. animate: false,
  79. title: {
  80. text: 'React Native Navigation!'
  81. }
  82. },
  83. bottomTab: {
  84. text: 'Tab 1',
  85. icon: require('../images/one.png'),
  86. selectedIcon: require('../images/one.png'),
  87. testID: testIDs.FIRST_TAB_BAR_BUTTON
  88. }
  89. }
  90. }
  91. }
  92. ],
  93. options: {
  94. topBar: {
  95. visible: false
  96. }
  97. }
  98. }
  99. },
  100. {
  101. stack: {
  102. children: [
  103. {
  104. component: {
  105. name: 'navigation.playground.TextScreen',
  106. passProps: {
  107. text: 'This is tab 2'
  108. }
  109. }
  110. }
  111. ],
  112. options: {
  113. bottomTab: {
  114. text: 'Tab 2',
  115. icon: require('../images/two.png'),
  116. testID: testIDs.SECOND_TAB_BAR_BUTTON
  117. }
  118. }
  119. }
  120. },
  121. {
  122. component: {
  123. name: 'navigation.playground.TextScreen',
  124. passProps: {
  125. text: 'This is tab 3',
  126. myFunction: () => 'Hello from a function!'
  127. },
  128. options: {
  129. topBar: {
  130. visible: true,
  131. animate: false
  132. },
  133. bottomTab: {
  134. text: 'Tab 3',
  135. icon: require('../images/one.png'),
  136. selectedIcon: require('../images/one.png')
  137. }
  138. }
  139. }
  140. }
  141. ],
  142. options: {
  143. bottomTabs: {
  144. titleDisplayMode: 'alwaysShow',
  145. testID: testIDs.BOTTOM_TABS_ELEMENT
  146. }
  147. }
  148. }
  149. }
  150. });
  151. }
  152. onClickSwitchToSideMenus = () => {
  153. Navigation.setRoot({
  154. root: {
  155. sideMenu: {
  156. left: {
  157. component: {
  158. name: 'navigation.playground.SideMenuScreen',
  159. passProps: {
  160. side: 'left'
  161. }
  162. }
  163. },
  164. center: {
  165. bottomTabs: {
  166. children: [
  167. {
  168. stack: {
  169. id: 'tab1Stack',
  170. children: [
  171. {
  172. component: {
  173. name: 'navigation.playground.TextScreen',
  174. passProps: {
  175. text: 'This is a side menu center screen tab 1'
  176. },
  177. // options: {
  178. // bottomTab: {
  179. // iconColor: 'red',
  180. // textColor: 'red',
  181. // selectedIconColor: 'purple',
  182. // selectedTextColor: 'purple',
  183. // }
  184. // }
  185. }
  186. }
  187. ],
  188. options: {
  189. bottomTab: {
  190. iconColor: 'red',
  191. textColor: 'red',
  192. selectedIconColor: 'purple',
  193. selectedTextColor: 'purple',
  194. text: 'Tab 1',
  195. icon: require('../images/one.png'),
  196. testID: testIDs.FIRST_TAB_BAR_BUTTON
  197. }
  198. }
  199. }
  200. },
  201. {
  202. stack: {
  203. children: [
  204. {
  205. component: {
  206. name: 'navigation.playground.TextScreen',
  207. passProps: {
  208. text: 'This is a side menu center screen tab 2'
  209. }
  210. }
  211. }
  212. ],
  213. options: {
  214. bottomTab: {
  215. text: 'Tab 2',
  216. icon: require('../images/two.png'),
  217. testID: testIDs.SECOND_TAB_BAR_BUTTON
  218. }
  219. }
  220. }
  221. },
  222. {
  223. stack: {
  224. children: [
  225. {
  226. component: {
  227. name: 'navigation.playground.TextScreen',
  228. passProps: {
  229. text: 'This is a side menu center screen tab 3'
  230. }
  231. }
  232. }
  233. ],
  234. options: {
  235. bottomTab: {
  236. text: 'Tab 3',
  237. icon: require('../images/three.png'),
  238. testID: testIDs.SECOND_TAB_BAR_BUTTON
  239. }
  240. }
  241. }
  242. }
  243. ],
  244. options: {
  245. bottomTab: {
  246. textColor: '#AED581',
  247. iconColor: '#AED581',
  248. selectedTextColor: '#90CAF9',
  249. selectedIconColor: '#90CAF9',
  250. fontFamily: 'HelveticaNeue-Italic',
  251. fontSize: 13
  252. }
  253. }
  254. }
  255. },
  256. right: {
  257. component: {
  258. name: 'navigation.playground.SideMenuScreen',
  259. passProps: {
  260. side: 'right'
  261. }
  262. }
  263. }
  264. }
  265. }
  266. });
  267. }
  268. onClickPush = async () => {
  269. await Navigation.push(this.props.componentId, {
  270. component: {
  271. name: 'navigation.playground.PushedScreen',
  272. options: {
  273. topBar: {
  274. title: {
  275. text: 'pushed',
  276. color: '#0000ff',
  277. fontSize: 14
  278. },
  279. subtitle: {
  280. text: 'subtitle',
  281. fontSize: 10,
  282. color: '#00ff00'
  283. }
  284. }
  285. }
  286. }
  287. });
  288. }
  289. onClickPushContextScreen = async () => {
  290. await Navigation.push(this.props.componentId, {
  291. component: {
  292. name: 'navigation.playground.ContextScreen',
  293. }
  294. })
  295. }
  296. onClickPushExternalComponent = async () => {
  297. await Navigation.push(this.props.componentId, {
  298. externalComponent: {
  299. name: 'RNNCustomComponent',
  300. passProps: {
  301. text: 'This is an external component'
  302. },
  303. options: {
  304. topBar: {
  305. title: {
  306. text: 'pushed'
  307. },
  308. visible: true,
  309. testID: testIDs.TOP_BAR_ELEMENT
  310. }
  311. }
  312. }
  313. });
  314. }
  315. onClickLifecycleScreen = () => {
  316. Navigation.push(this.props.componentId, {
  317. component: {
  318. name: 'navigation.playground.LifecycleScreen'
  319. }
  320. });
  321. }
  322. onClickShowStaticLifecycleOverlay = () => {
  323. Navigation.showOverlay({
  324. component: {
  325. name: 'navigation.playground.StaticLifecycleOverlay',
  326. options: {
  327. overlay: {
  328. interceptTouchOutside: false
  329. }
  330. }
  331. }
  332. });
  333. }
  334. onClickShowModal = async () => {
  335. await Navigation.showModal({
  336. stack: {
  337. children: [
  338. {
  339. component: {
  340. name: 'navigation.playground.ModalScreen'
  341. }
  342. }
  343. ]
  344. }
  345. });
  346. }
  347. onClickShowRedbox = () => {
  348. undefined();
  349. }
  350. onClickShowPreview = async ({ reactTag }) => {
  351. await Navigation.push(this.props.componentId, {
  352. component: {
  353. name: 'navigation.playground.PushedScreen',
  354. options: {
  355. animations: {
  356. push: {
  357. enabled: false
  358. }
  359. },
  360. preview: reactTag ? {
  361. reactTag,
  362. height: 300,
  363. commit: true,
  364. actions: [{
  365. id: 'action-cancel',
  366. title: 'Cancel'
  367. }, {
  368. id: 'action-delete',
  369. title: 'Delete',
  370. actions: [{
  371. id: 'action-delete-sure',
  372. title: 'Are you sure?',
  373. style: 'destructive'
  374. }]
  375. }]
  376. } : undefined,
  377. }
  378. }
  379. });
  380. }
  381. onClickPushOptionsScreen = () => {
  382. Navigation.push(this.props.componentId, {
  383. component: {
  384. name: 'navigation.playground.OptionsScreen',
  385. options: {
  386. animations: {
  387. push: {
  388. enabled: false
  389. }
  390. }
  391. }
  392. }
  393. });
  394. }
  395. onClickPushTopTabsScreen = () => {
  396. Navigation.push(this.props.componentId, {
  397. topTabs: {
  398. children: [
  399. {
  400. component: {
  401. name: 'navigation.playground.TopTabOptionsScreen',
  402. passProps: {
  403. title: 'Tab 1',
  404. text: 'This is top tab 1'
  405. },
  406. options: {
  407. topTab: {
  408. title: 'Tab 1'
  409. },
  410. topBar: {
  411. title: {
  412. text: 'One'
  413. }
  414. }
  415. }
  416. }
  417. },
  418. {
  419. component: {
  420. name: 'navigation.playground.TopTabScreen',
  421. passProps: {
  422. title: 'Tab 2',
  423. text: 'This is top tab 2'
  424. },
  425. options: {
  426. topTab: {
  427. title: 'Tab 2',
  428. titleFontFamily: 'HelveticaNeue-Italic'
  429. },
  430. topBar: {
  431. title: {
  432. text: 'Two'
  433. }
  434. }
  435. }
  436. }
  437. },
  438. {
  439. component: {
  440. name: 'navigation.playground.TopTabScreen',
  441. passProps: {
  442. title: 'Tab 3',
  443. text: 'This is top tab 3'
  444. },
  445. options: {
  446. topTab: {
  447. title: 'Tab 3'
  448. },
  449. topBar: {
  450. title: {
  451. text: 'Three'
  452. }
  453. }
  454. }
  455. }
  456. }
  457. ],
  458. options: {
  459. topTabs: {
  460. selectedTabColor: '#12766b',
  461. unselectedTabColor: 'red',
  462. fontSize: 6
  463. }
  464. }
  465. }
  466. });
  467. }
  468. onClickBackHandler = () => {
  469. Navigation.push(this.props.componentId, {
  470. component: {
  471. name: 'navigation.playground.BackHandlerScreen'
  472. }
  473. });
  474. }
  475. onClickPushOrientationMenuScreen = () => {
  476. Navigation.push(this.props.componentId, {
  477. component: {
  478. name: 'navigation.playground.OrientationSelectScreen'
  479. }
  480. });
  481. }
  482. onClickProvidedId = () => {
  483. Navigation.showModal({
  484. stack: {
  485. children: [
  486. {
  487. component: {
  488. name: 'navigation.playground.TextScreen',
  489. id: 'my unique id'
  490. }
  491. }
  492. ]
  493. }
  494. });
  495. Navigation.mergeOptions('my unique id', {
  496. topBar: {
  497. title: {
  498. text: 'User provided id'
  499. }
  500. }
  501. });
  502. }
  503. onClickComplexLayout = () => {
  504. Navigation.showModal({
  505. component: {
  506. name: 'navigation.playground.ComplexLayout'
  507. }
  508. });
  509. }
  510. onClickSplitView = () => {
  511. Navigation.setRoot({
  512. root: {
  513. splitView: {
  514. id: 'SPLITVIEW_ID',
  515. master: {
  516. stack: {
  517. id: 'MASTER_ID',
  518. children: [
  519. {
  520. component: {
  521. name: 'navigation.playground.WelcomeScreen'
  522. },
  523. },
  524. ]
  525. },
  526. },
  527. detail: {
  528. stack: {
  529. id: 'DETAILS_ID',
  530. children: [
  531. {
  532. component: {
  533. name: 'navigation.playground.WelcomeScreen'
  534. },
  535. },
  536. ]
  537. }
  538. },
  539. options: {
  540. displayMode: 'auto',
  541. primaryEdge: 'leading',
  542. minWidth: 150,
  543. maxWidth: 300,
  544. },
  545. },
  546. },
  547. });
  548. }
  549. onClickSearchBar = () => {
  550. Navigation.push(this.props.componentId, {
  551. component: {
  552. name: 'navigation.playground.SearchControllerScreen'
  553. }
  554. });
  555. }
  556. }
  557. module.exports = WelcomeScreen;
  558. const styles = {
  559. root: {
  560. flexGrow: 1,
  561. justifyContent: 'center',
  562. alignItems: 'center',
  563. backgroundColor: '#e8e8e8',
  564. },
  565. bar: {
  566. flex: 1,
  567. flexDirection: 'column',
  568. backgroundColor: '#e8e8e8',
  569. justifyContent: 'space-between'
  570. },
  571. h1: {
  572. fontSize: 24,
  573. textAlign: 'center',
  574. margin: 30
  575. },
  576. footer: {
  577. fontSize: 10,
  578. color: '#888',
  579. marginTop: 10
  580. }
  581. };