react-native-navigation的迁移库

WelcomeScreen.js 16KB

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