react-native-navigation的迁移库

WelcomeScreen.js 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. container: {
  143. name: 'navigation.playground.TopTabOptionsScreen',
  144. passProps: {
  145. title: 'Tab 1',
  146. text: 'This is top tab 1'
  147. }
  148. }
  149. },
  150. {
  151. container: {
  152. name: 'navigation.playground.TopTabScreen',
  153. passProps: {
  154. title: 'Tab 2',
  155. text: 'This is top tab 2'
  156. }
  157. }
  158. },
  159. {
  160. container: {
  161. name: 'navigation.playground.TopTabScreen',
  162. passProps: {
  163. title: 'Tab 3',
  164. text: 'This is top tab 3'
  165. }
  166. }
  167. }
  168. ]
  169. });
  170. }
  171. onClickBackHandler() {
  172. Navigation.push(this.props.containerId, {
  173. name: 'navigation.playground.BackHandlerScreen'
  174. });
  175. }
  176. onClickPushOrientationMenuScreen() {
  177. Navigation.push(this.props.containerId, {
  178. name: 'navigation.playground.OrientationSelectScreen'
  179. });
  180. }
  181. }
  182. module.exports = WelcomeScreen;
  183. const styles = {
  184. root: {
  185. flexGrow: 1,
  186. justifyContent: 'center',
  187. alignItems: 'center'
  188. },
  189. h1: {
  190. fontSize: 24,
  191. textAlign: 'center',
  192. margin: 30
  193. },
  194. footer: {
  195. fontSize: 10,
  196. color: '#888',
  197. marginTop: 10
  198. }
  199. };