react-native-navigation的迁移库

WelcomeScreen.js 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. }
  53. },
  54. {
  55. container: {
  56. name: 'navigation.playground.TextScreen',
  57. passProps: {
  58. text: 'This is tab 2'
  59. }
  60. }
  61. }
  62. ]
  63. });
  64. }
  65. onClickSwitchToSideMenus() {
  66. Navigation.setRoot({
  67. bottomTabs: [
  68. {
  69. container: {
  70. name: 'navigation.playground.TextScreen',
  71. passProps: {
  72. text: 'This is a side menu center screen tab 1'
  73. }
  74. }
  75. },
  76. {
  77. container: {
  78. name: 'navigation.playground.TextScreen',
  79. passProps: {
  80. text: 'This is a side menu center screen tab 2'
  81. }
  82. }
  83. },
  84. {
  85. container: {
  86. name: 'navigation.playground.TextScreen',
  87. passProps: {
  88. text: 'This is a side menu center screen tab 3'
  89. }
  90. }
  91. }
  92. ],
  93. sideMenu: {
  94. left: {
  95. container: {
  96. name: 'navigation.playground.SideMenuScreen',
  97. passProps: {
  98. side: 'left'
  99. }
  100. }
  101. },
  102. right: {
  103. container: {
  104. name: 'navigation.playground.SideMenuScreen',
  105. passProps: {
  106. side: 'right'
  107. }
  108. }
  109. }
  110. }
  111. });
  112. }
  113. async onClickPush() {
  114. await Navigation.push(this.props.containerId, {
  115. name: 'navigation.playground.PushedScreen'
  116. });
  117. }
  118. onClickLifecycleScreen() {
  119. Navigation.push(this.props.containerId, {
  120. name: 'navigation.playground.LifecycleScreen'
  121. });
  122. }
  123. async onClickShowModal() {
  124. await Navigation.showModal({
  125. container: {
  126. name: 'navigation.playground.ModalScreen'
  127. }
  128. });
  129. }
  130. onClickShowRedbox() {
  131. undefined();
  132. }
  133. onClickPushOptionsScreen() {
  134. Navigation.push(this.props.containerId, {
  135. name: 'navigation.playground.OptionsScreen'
  136. });
  137. }
  138. onClickPushTopTabsScreen() {
  139. Navigation.push(this.props.containerId, {
  140. topTabs: [
  141. {
  142. name: 'navigation.playground.TopTabOptionsScreen',
  143. passProps: {
  144. title: 'Tab 1',
  145. text: 'This is top tab 1'
  146. },
  147. navigationOptions: {
  148. topTab: {
  149. title: 'Tab 1'
  150. }
  151. }
  152. },
  153. {
  154. name: 'navigation.playground.TopTabScreen',
  155. passProps: {
  156. title: 'Tab 2',
  157. text: 'This is top tab 2'
  158. },
  159. navigationOptions: {
  160. topTab: {
  161. title: 'Tab 2'
  162. }
  163. }
  164. },
  165. {
  166. name: 'navigation.playground.TopTabScreen',
  167. passProps: {
  168. title: 'Tab 3',
  169. text: 'This is top tab 3'
  170. },
  171. navigationOptions: {
  172. topTab: {
  173. title: 'Tab 3'
  174. }
  175. }
  176. }
  177. ]
  178. });
  179. }
  180. onClickBackHandler() {
  181. Navigation.push(this.props.containerId, {
  182. name: 'navigation.playground.BackHandlerScreen'
  183. });
  184. }
  185. onClickPushOrientationMenuScreen() {
  186. Navigation.push(this.props.containerId, {
  187. name: 'navigation.playground.OrientationSelectScreen'
  188. });
  189. }
  190. }
  191. module.exports = WelcomeScreen;
  192. const styles = {
  193. root: {
  194. flexGrow: 1,
  195. justifyContent: 'center',
  196. alignItems: 'center'
  197. },
  198. h1: {
  199. fontSize: 24,
  200. textAlign: 'center',
  201. margin: 30
  202. },
  203. footer: {
  204. fontSize: 10,
  205. color: '#888',
  206. marginTop: 10
  207. }
  208. };