react-native-navigation的迁移库

WelcomeScreen.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. const React = require('react');
  2. const { Component } = require('react');
  3. const { View, Text, Button, Platform } = require('react-native');
  4. const testIDs = require('../testIDs');
  5. const { Navigation } = require('react-native-navigation');
  6. class WelcomeScreen extends Component {
  7. static get options() {
  8. return {
  9. topBar: {
  10. title: {
  11. largeTitle: false,
  12. title: 'My Screen'
  13. },
  14. drawBehind: true,
  15. visible: false,
  16. animate: false
  17. }
  18. };
  19. }
  20. render() {
  21. return (
  22. <View style={styles.root} key={'root'}>
  23. <Text testID={testIDs.WELCOME_SCREEN_HEADER} style={styles.h1}>{`React Native Navigation!`}</Text>
  24. <Button title='Switch to tab based app' testID={testIDs.TAB_BASED_APP_BUTTON} onPress={this.onClickSwitchToTabs} />
  25. <Button title='Switch to app with side menus' testID={testIDs.TAB_BASED_APP_SIDE_BUTTON} onPress={this.onClickSwitchToSideMenus} />
  26. <Button title='Push Lifecycle Screen' testID={testIDs.PUSH_LIFECYCLE_BUTTON} onPress={this.onClickLifecycleScreen} />
  27. <Button title='Static Lifecycle Events' testID={testIDs.PUSH_STATIC_LIFECYCLE_BUTTON} onPress={this.onClickShowStaticLifecycleOverlay} />
  28. <Button title='Push' testID={testIDs.PUSH_BUTTON} onPress={this.onClickPush} />
  29. <Button title='Push Options Screen' testID={testIDs.PUSH_OPTIONS_BUTTON} onPress={this.onClickPushOptionsScreen} />
  30. <Button title='Push External Component' testID={testIDs.PUSH_EXTERNAL_COMPONENT_BUTTON} onPress={this.onClickPushExternalComponent} />
  31. {Platform.OS === 'android' && <Button title='Push Top Tabs screen' testID={testIDs.PUSH_TOP_TABS_BUTTON} onPress={this.onClickPushTopTabsScreen} />}
  32. {Platform.OS === 'android' && <Button title='Back Handler' testID={testIDs.BACK_HANDLER_BUTTON} onPress={this.onClickBackHandler} />}
  33. <Button title='Show Modal' testID={testIDs.SHOW_MODAL_BUTTON} onPress={this.onClickShowModal} />
  34. <Button title='Show Redbox' testID={testIDs.SHOW_REDBOX_BUTTON} onPress={this.onClickShowRedbox} />
  35. <Button title='Orientation' testID={testIDs.ORIENTATION_BUTTON} onPress={this.onClickPushOrientationMenuScreen} />
  36. <Button title='Provided Id' testID={testIDs.PROVIDED_ID} onPress={this.onClickProvidedId} />
  37. <Text style={styles.footer}>{`this.props.componentId = ${this.props.componentId}`}</Text>
  38. </View>
  39. );
  40. }
  41. onClickSwitchToTabs = () => {
  42. Navigation.setRoot({
  43. bottomTabs: {
  44. children: [
  45. {
  46. stack: {
  47. children: [
  48. {
  49. component: {
  50. name: 'navigation.playground.TextScreen',
  51. passProps: {
  52. text: 'This is tab 1',
  53. myFunction: () => 'Hello from a function!'
  54. },
  55. options: {
  56. topBar: {
  57. visible: true,
  58. title: {
  59. text: 'React Native Navigation!'
  60. }
  61. }
  62. }
  63. }
  64. }
  65. ],
  66. options: {
  67. bottomTab: {
  68. title: 'Tab 1',
  69. icon: require('../images/one.png'),
  70. testID: testIDs.FIRST_TAB_BAR_BUTTON
  71. },
  72. topBar: {
  73. visible: false
  74. }
  75. }
  76. }
  77. },
  78. {
  79. stack: {
  80. children: [
  81. {
  82. component: {
  83. name: 'navigation.playground.TextScreen',
  84. passProps: {
  85. text: 'This is tab 2'
  86. }
  87. }
  88. }
  89. ],
  90. options: {
  91. bottomTab: {
  92. title: 'Tab 2',
  93. icon: require('../images/two.png'),
  94. testID: testIDs.SECOND_TAB_BAR_BUTTON
  95. }
  96. }
  97. }
  98. }
  99. ],
  100. options: {
  101. bottomTabs: {
  102. tabColor: 'red',
  103. selectedTabColor: 'blue',
  104. fontFamily: 'HelveticaNeue-Italic',
  105. fontSize: 13,
  106. testID: testIDs.BOTTOM_TABS_ELEMENT
  107. }
  108. }
  109. }
  110. });
  111. }
  112. onClickSwitchToSideMenus = () => {
  113. Navigation.setRoot({
  114. sideMenu: {
  115. left: {
  116. component: {
  117. name: 'navigation.playground.SideMenuScreen',
  118. passProps: {
  119. side: 'left'
  120. }
  121. }
  122. },
  123. center: {
  124. bottomTabs: {
  125. children: [
  126. {
  127. stack: {
  128. children: [
  129. {
  130. component: {
  131. name: 'navigation.playground.TextScreen',
  132. passProps: {
  133. text: 'This is a side menu center screen tab 1'
  134. }
  135. }
  136. }
  137. ],
  138. options: {
  139. bottomTab: {
  140. title: 'Tab 1',
  141. icon: require('../images/one.png'),
  142. testID: testIDs.FIRST_TAB_BAR_BUTTON
  143. }
  144. }
  145. }
  146. },
  147. {
  148. stack: {
  149. children: [
  150. {
  151. component: {
  152. name: 'navigation.playground.TextScreen',
  153. passProps: {
  154. text: 'This is a side menu center screen tab 2'
  155. }
  156. }
  157. }
  158. ],
  159. options: {
  160. bottomTab: {
  161. title: 'Tab 2',
  162. icon: require('../images/two.png'),
  163. testID: testIDs.SECOND_TAB_BAR_BUTTON
  164. }
  165. }
  166. }
  167. },
  168. {
  169. stack: {
  170. children: [
  171. {
  172. component: {
  173. name: 'navigation.playground.TextScreen',
  174. passProps: {
  175. text: 'This is a side menu center screen tab 3'
  176. }
  177. }
  178. }
  179. ],
  180. options: {
  181. bottomTab: {
  182. title: 'Tab 3',
  183. icon: require('../images/three.png'),
  184. testID: testIDs.SECOND_TAB_BAR_BUTTON
  185. }
  186. }
  187. }
  188. }
  189. ],
  190. options: {
  191. bottomTabs: {
  192. tabColor: 'red',
  193. selectedTabColor: 'blue',
  194. fontFamily: 'HelveticaNeue-Italic',
  195. fontSize: 13
  196. }
  197. }
  198. }
  199. },
  200. right: {
  201. component: {
  202. name: 'navigation.playground.SideMenuScreen',
  203. passProps: {
  204. side: 'right'
  205. }
  206. }
  207. }
  208. }
  209. });
  210. }
  211. onClickPush = async () => {
  212. await Navigation.push(this.props.componentId, {
  213. component: {
  214. name: 'navigation.playground.PushedScreen',
  215. options: {
  216. topBar: {
  217. title: {
  218. text: 'pushed'
  219. }
  220. }
  221. }
  222. }
  223. });
  224. }
  225. onClickPushExternalComponent = async () => {
  226. await Navigation.push(this.props.componentId, {
  227. externalComponent: {
  228. name: 'RNNCustomComponent',
  229. passProps: {
  230. text: 'This is an external component'
  231. },
  232. options: {
  233. topBar: {
  234. title: {
  235. text: 'pushed'
  236. },
  237. visible: true,
  238. testID: testIDs.TOP_BAR_ELEMENT
  239. }
  240. }
  241. }
  242. });
  243. }
  244. onClickLifecycleScreen = () => {
  245. Navigation.push(this.props.componentId, {
  246. component: {
  247. name: 'navigation.playground.LifecycleScreen'
  248. }
  249. });
  250. }
  251. onClickShowStaticLifecycleOverlay = () => {
  252. Navigation.showOverlay({
  253. component: {
  254. name: 'navigation.playground.StaticLifecycleOverlay',
  255. options: {
  256. overlay: {
  257. interceptTouchOutside: false
  258. }
  259. }
  260. }
  261. });
  262. }
  263. onClickShowModal = async () => {
  264. await Navigation.showModal({
  265. stack: {
  266. children: [
  267. {
  268. component: {
  269. name: 'navigation.playground.ModalScreen'
  270. }
  271. }
  272. ]
  273. }
  274. });
  275. }
  276. onClickShowRedbox = () => {
  277. undefined();
  278. }
  279. onClickPushOptionsScreen = () => {
  280. Navigation.push(this.props.componentId, {
  281. component: {
  282. name: 'navigation.playground.OptionsScreen',
  283. options: {
  284. animated: false
  285. }
  286. }
  287. });
  288. }
  289. onClickPushTopTabsScreen = () => {
  290. Navigation.push(this.props.componentId, {
  291. topTabs: {
  292. children: [
  293. {
  294. component: {
  295. name: 'navigation.playground.TopTabOptionsScreen',
  296. passProps: {
  297. title: 'Tab 1',
  298. text: 'This is top tab 1'
  299. },
  300. options: {
  301. topTab: {
  302. title: {
  303. text: 'Tab 1'
  304. }
  305. },
  306. topBar: {
  307. title: {
  308. text: 'One'
  309. }
  310. }
  311. }
  312. }
  313. },
  314. {
  315. component: {
  316. name: 'navigation.playground.TopTabScreen',
  317. passProps: {
  318. title: 'Tab 2',
  319. text: 'This is top tab 2'
  320. },
  321. options: {
  322. topTab: {
  323. title: 'Tab 2',
  324. titleFontFamily: 'HelveticaNeue-Italic'
  325. },
  326. topBar: {
  327. title: {
  328. text: 'Two'
  329. }
  330. }
  331. }
  332. }
  333. },
  334. {
  335. component: {
  336. name: 'navigation.playground.TopTabScreen',
  337. passProps: {
  338. title: 'Tab 3',
  339. text: 'This is top tab 3'
  340. },
  341. options: {
  342. topTab: {
  343. title: 'Tab 3'
  344. },
  345. topBar: {
  346. title: {
  347. text: 'Three'
  348. }
  349. }
  350. }
  351. }
  352. }
  353. ]
  354. },
  355. options: {
  356. topTabs: {
  357. selectedTabColor: '#12766b',
  358. unselectedTabColor: 'red',
  359. fontSize: 6
  360. }
  361. }
  362. });
  363. }
  364. onClickBackHandler = () => {
  365. Navigation.push(this.props.componentId, {
  366. component: {
  367. name: 'navigation.playground.BackHandlerScreen'
  368. }
  369. });
  370. }
  371. onClickPushOrientationMenuScreen = () => {
  372. Navigation.push(this.props.componentId, {
  373. component: {
  374. name: 'navigation.playground.OrientationSelectScreen'
  375. }
  376. });
  377. }
  378. onClickProvidedId = () => {
  379. Navigation.showModal({
  380. stack: {
  381. children: [
  382. {
  383. component: {
  384. name: 'navigation.playground.TextScreen',
  385. id: 'my unique id'
  386. }
  387. }
  388. ]
  389. }
  390. });
  391. Navigation.setOptions('my unique id', {
  392. topBar: {
  393. title: {
  394. text: 'User provided id'
  395. }
  396. }
  397. });
  398. }
  399. }
  400. module.exports = WelcomeScreen;
  401. const styles = {
  402. root: {
  403. flexGrow: 1,
  404. justifyContent: 'center',
  405. alignItems: 'center',
  406. backgroundColor: 'white'
  407. },
  408. h1: {
  409. fontSize: 24,
  410. textAlign: 'center',
  411. margin: 30
  412. },
  413. footer: {
  414. fontSize: 10,
  415. color: '#888',
  416. marginTop: 10
  417. }
  418. };