react-native-navigation的迁移库

WelcomeScreen.js 16KB

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