react-native-navigation的迁移库

WelcomeScreen.js 11KB

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