react-native-navigation的迁移库

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