react-native-navigation的迁移库

WelcomeScreen.js 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. const React = require('react');
  2. const { Component } = require('react');
  3. const { View, Text, Button } = require('react-native');
  4. const testIDs = require('../testIDs');
  5. const Navigation = require('react-native-navigation');
  6. class WelcomeScreen extends Component {
  7. static get navigationOptions() {
  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. }
  24. render() {
  25. return (
  26. <View style={styles.root}>
  27. <Text testID={testIDs.WELCOME_SCREEN_HEADER} style={styles.h1}>{`React Native Navigation!`}</Text>
  28. <Button title="Switch to tab based app" testID={testIDs.TAB_BASED_APP_BUTTON} onPress={this.onClickSwitchToTabs} />
  29. <Button title="Switch to app with side menus" testID={testIDs.TAB_BASED_APP_SIDE_BUTTON} onPress={this.onClickSwitchToSideMenus} />
  30. <Button title="Push Lifecycle Screen" testID={testIDs.PUSH_LIFECYCLE_BUTTON} onPress={this.onClickLifecycleScreen} />
  31. <Button title="Push" testID={testIDs.PUSH_BUTTON} onPress={this.onClickPush} />
  32. <Button title="Push Options Screen" testID={testIDs.PUSH_OPTIONS_BUTTON} onPress={this.onClickPushOptionsScreen} />
  33. <Button title="Push Top Tabs screen" testID={testIDs.PUSH_TOP_TABS_BUTTON} onPress={this.onClickPushTopTabsScreen} />
  34. <Button title="Back Handler" testID={testIDs.BACK_HANDLER_BUTTON} onPress={this.onClickBackHandler} />
  35. <Button title="Show Modal" testID={testIDs.SHOW_MODAL_BUTTON} onPress={this.onClickShowModal} />
  36. <Button title="Show Redbox" testID={testIDs.SHOW_REDBOX_BUTTON} onPress={this.onClickShowRedbox} />
  37. <Button title="Orientation" testID={testIDs.ORIENTATION_BUTTON} onPress={this.onClickPushOrientationMenuScreen} />
  38. <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
  39. </View>
  40. );
  41. }
  42. onClickSwitchToTabs() {
  43. Navigation.setRoot({
  44. bottomTabs: [
  45. {
  46. container: {
  47. name: 'navigation.playground.TextScreen',
  48. passProps: {
  49. text: 'This is tab 1',
  50. myFunction: () => 'Hello from a function!'
  51. },
  52. navigationOptions: {
  53. bottomTab: {
  54. title: 'Tab 1',
  55. testID: testIDs.FIRST_TAB_BAR_BUTTON
  56. }
  57. }
  58. }
  59. },
  60. {
  61. container: {
  62. name: 'navigation.playground.TextScreen',
  63. passProps: {
  64. text: 'This is tab 2'
  65. },
  66. navigationOptions: {
  67. bottomTab: {
  68. title: 'Tab 2',
  69. testID: testIDs.SECOND_TAB_BAR_BUTTON
  70. }
  71. }
  72. }
  73. }
  74. ]
  75. });
  76. }
  77. onClickSwitchToSideMenus() {
  78. Navigation.setRoot({
  79. bottomTabs: [
  80. {
  81. container: {
  82. name: 'navigation.playground.TextScreen',
  83. passProps: {
  84. text: 'This is a side menu center screen tab 1'
  85. }
  86. }
  87. },
  88. {
  89. container: {
  90. name: 'navigation.playground.TextScreen',
  91. passProps: {
  92. text: 'This is a side menu center screen tab 2'
  93. }
  94. }
  95. },
  96. {
  97. container: {
  98. name: 'navigation.playground.TextScreen',
  99. passProps: {
  100. text: 'This is a side menu center screen tab 3'
  101. }
  102. }
  103. }
  104. ],
  105. sideMenu: {
  106. left: {
  107. container: {
  108. name: 'navigation.playground.SideMenuScreen',
  109. passProps: {
  110. side: 'left'
  111. }
  112. }
  113. },
  114. right: {
  115. container: {
  116. name: 'navigation.playground.SideMenuScreen',
  117. passProps: {
  118. side: 'right'
  119. }
  120. }
  121. }
  122. }
  123. });
  124. }
  125. async onClickPush() {
  126. await Navigation.push(this.props.containerId, {
  127. name: 'navigation.playground.PushedScreen'
  128. });
  129. }
  130. onClickLifecycleScreen() {
  131. Navigation.push(this.props.containerId, {
  132. name: 'navigation.playground.LifecycleScreen'
  133. });
  134. }
  135. async onClickShowModal() {
  136. await Navigation.showModal({
  137. container: {
  138. name: 'navigation.playground.ModalScreen'
  139. }
  140. });
  141. }
  142. onClickShowRedbox() {
  143. undefined();
  144. }
  145. onClickPushOptionsScreen() {
  146. Navigation.push(this.props.containerId, {
  147. name: 'navigation.playground.OptionsScreen'
  148. });
  149. }
  150. onClickPushTopTabsScreen() {
  151. Navigation.push(this.props.containerId, {
  152. topTabs: [
  153. {
  154. name: 'navigation.playground.TopTabOptionsScreen',
  155. passProps: {
  156. title: 'Tab 1',
  157. text: 'This is top tab 1'
  158. },
  159. navigationOptions: {
  160. topTab: {
  161. title: 'Tab 1'
  162. }
  163. }
  164. },
  165. {
  166. name: 'navigation.playground.TopTabScreen',
  167. passProps: {
  168. title: 'Tab 2',
  169. text: 'This is top tab 2'
  170. },
  171. navigationOptions: {
  172. topTab: {
  173. title: 'Tab 2'
  174. }
  175. }
  176. },
  177. {
  178. name: 'navigation.playground.TopTabScreen',
  179. passProps: {
  180. title: 'Tab 3',
  181. text: 'This is top tab 3'
  182. },
  183. navigationOptions: {
  184. topTab: {
  185. title: 'Tab 3'
  186. }
  187. }
  188. }
  189. ]
  190. });
  191. }
  192. onClickBackHandler() {
  193. Navigation.push(this.props.containerId, {
  194. name: 'navigation.playground.BackHandlerScreen'
  195. });
  196. }
  197. onClickPushOrientationMenuScreen() {
  198. Navigation.push(this.props.containerId, {
  199. name: 'navigation.playground.OrientationSelectScreen'
  200. });
  201. }
  202. }
  203. module.exports = WelcomeScreen;
  204. const styles = {
  205. root: {
  206. flexGrow: 1,
  207. justifyContent: 'center',
  208. alignItems: 'center'
  209. },
  210. h1: {
  211. fontSize: 24,
  212. textAlign: 'center',
  213. margin: 30
  214. },
  215. footer: {
  216. fontSize: 10,
  217. color: '#888',
  218. marginTop: 10
  219. }
  220. };