react-native-navigation的迁移库

WelcomeScreen.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. }
  256. });
  257. }
  258. onClickShowModal = async () => {
  259. await Navigation.showModal({
  260. stack: {
  261. children: [
  262. {
  263. component: {
  264. name: 'navigation.playground.ModalScreen'
  265. }
  266. }
  267. ]
  268. }
  269. });
  270. }
  271. onClickShowRedbox = () => {
  272. undefined();
  273. }
  274. onClickPushOptionsScreen = () => {
  275. Navigation.push(this.props.componentId, {
  276. component: {
  277. name: 'navigation.playground.OptionsScreen',
  278. options: {
  279. animated: false
  280. }
  281. }
  282. });
  283. }
  284. onClickPushTopTabsScreen = () => {
  285. Navigation.push(this.props.componentId, {
  286. topTabs: {
  287. children: [
  288. {
  289. component: {
  290. name: 'navigation.playground.TopTabOptionsScreen',
  291. passProps: {
  292. title: 'Tab 1',
  293. text: 'This is top tab 1'
  294. },
  295. options: {
  296. topTab: {
  297. title: {
  298. text: 'Tab 1'
  299. }
  300. },
  301. topBar: {
  302. title: {
  303. text: 'One'
  304. }
  305. }
  306. }
  307. }
  308. },
  309. {
  310. component: {
  311. name: 'navigation.playground.TopTabScreen',
  312. passProps: {
  313. title: 'Tab 2',
  314. text: 'This is top tab 2'
  315. },
  316. options: {
  317. topTab: {
  318. title: 'Tab 2',
  319. titleFontFamily: 'HelveticaNeue-Italic'
  320. },
  321. topBar: {
  322. title: {
  323. text: 'Two'
  324. }
  325. }
  326. }
  327. }
  328. },
  329. {
  330. component: {
  331. name: 'navigation.playground.TopTabScreen',
  332. passProps: {
  333. title: 'Tab 3',
  334. text: 'This is top tab 3'
  335. },
  336. options: {
  337. topTab: {
  338. title: 'Tab 3'
  339. },
  340. topBar: {
  341. title: {
  342. text: 'Three'
  343. }
  344. }
  345. }
  346. }
  347. }
  348. ]
  349. },
  350. options: {
  351. topTabs: {
  352. selectedTabColor: '#12766b',
  353. unselectedTabColor: 'red',
  354. fontSize: 6
  355. }
  356. }
  357. });
  358. }
  359. onClickBackHandler = () => {
  360. Navigation.push(this.props.componentId, {
  361. component: {
  362. name: 'navigation.playground.BackHandlerScreen'
  363. }
  364. });
  365. }
  366. onClickPushOrientationMenuScreen = () => {
  367. Navigation.push(this.props.componentId, {
  368. component: {
  369. name: 'navigation.playground.OrientationSelectScreen'
  370. }
  371. });
  372. }
  373. onClickProvidedId = () => {
  374. Navigation.showModal({
  375. stack: {
  376. children: [
  377. {
  378. component: {
  379. name: 'navigation.playground.TextScreen',
  380. id: 'my unique id'
  381. }
  382. }
  383. ]
  384. }
  385. });
  386. Navigation.setOptions('my unique id', {
  387. topBar: {
  388. title: {
  389. text: 'User provided id'
  390. }
  391. }
  392. });
  393. }
  394. }
  395. module.exports = WelcomeScreen;
  396. const styles = {
  397. root: {
  398. flexGrow: 1,
  399. justifyContent: 'center',
  400. alignItems: 'center',
  401. backgroundColor: 'white'
  402. },
  403. h1: {
  404. fontSize: 24,
  405. textAlign: 'center',
  406. margin: 30
  407. },
  408. footer: {
  409. fontSize: 10,
  410. color: '#888',
  411. marginTop: 10
  412. }
  413. };