react-native-navigation的迁移库

WelcomeScreen.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. const React = require('react');
  2. const { Component } = require('react');
  3. const { View, Text, Button } = require('react-native');
  4. const Navigation = require('react-native-navigation');
  5. class WelcomeScreen extends Component {
  6. constructor(props) {
  7. super(props);
  8. this.onClickPush = this.onClickPush.bind(this);
  9. this.onClickShowModal = this.onClickShowModal.bind(this);
  10. this.onClickLifecycleScreen = this.onClickLifecycleScreen.bind(this);
  11. this.onClickPushOptionsScreen = this.onClickPushOptionsScreen.bind(this);
  12. }
  13. render() {
  14. return (
  15. <View style={styles.root}>
  16. <Text style={styles.h1}>{`React Native Navigation!`}</Text>
  17. <Button title="Switch to tab based app" onPress={this.onClickSwitchToTabs} />
  18. <Button title="Switch to app with side menus" onPress={this.onClickSwitchToSideMenus} />
  19. <Button title="Push Lifecycle Screen" onPress={this.onClickLifecycleScreen} />
  20. <Button title="Push" onPress={this.onClickPush} />
  21. <Button title="Push Options Screen" onPress={this.onClickPushOptionsScreen} />
  22. <Button title="Show Modal" onPress={this.onClickShowModal} />
  23. <Button title="Show Redbox" onPress={this.onClickShowRedbox} />
  24. <Text style={styles.footer}>{`this.props.containerId = ${this.props.containerId}`}</Text>
  25. </View>
  26. );
  27. }
  28. onClickSwitchToTabs() {
  29. Navigation.setRoot({
  30. bottomTabs: [
  31. {
  32. container: {
  33. name: 'navigation.playground.TextScreen',
  34. passProps: {
  35. text: 'This is tab 1',
  36. myFunction: () => 'Hello from a function!'
  37. }
  38. }
  39. },
  40. {
  41. container: {
  42. name: 'navigation.playground.TextScreen',
  43. passProps: {
  44. text: 'This is tab 2'
  45. }
  46. }
  47. }
  48. ]
  49. });
  50. }
  51. onClickSwitchToSideMenus() {
  52. Navigation.setRoot({
  53. bottomTabs: [
  54. {
  55. container: {
  56. name: 'navigation.playground.TextScreen',
  57. passProps: {
  58. text: 'This is a side menu center screen tab 1'
  59. }
  60. }
  61. },
  62. {
  63. container: {
  64. name: 'navigation.playground.TextScreen',
  65. passProps: {
  66. text: 'This is a side menu center screen tab 2'
  67. }
  68. }
  69. },
  70. {
  71. container: {
  72. name: 'navigation.playground.TextScreen',
  73. passProps: {
  74. text: 'This is a side menu center screen tab 3'
  75. }
  76. }
  77. }
  78. ],
  79. sideMenu: {
  80. left: {
  81. container: {
  82. name: 'navigation.playground.TextScreen',
  83. passProps: {
  84. text: 'This is a left side menu screen'
  85. }
  86. }
  87. },
  88. right: {
  89. container: {
  90. name: 'navigation.playground.TextScreen',
  91. passProps: {
  92. text: 'This is a right side menu screen'
  93. }
  94. }
  95. }
  96. }
  97. });
  98. }
  99. onClickPush() {
  100. Navigation.push(this.props.containerId, {
  101. name: 'navigation.playground.PushedScreen'
  102. });
  103. }
  104. onClickLifecycleScreen() {
  105. Navigation.push(this.props.containerId, {
  106. name: 'navigation.playground.LifecycleScreen'
  107. });
  108. }
  109. onClickShowModal() {
  110. Navigation.showModal({
  111. container: {
  112. name: 'navigation.playground.ModalScreen'
  113. }
  114. });
  115. }
  116. onClickShowRedbox() {
  117. undefined();
  118. }
  119. onClickPushOptionsScreen() {
  120. Navigation.push(this.props.containerId, {
  121. name: 'navigation.playground.OptionsScreen'
  122. });
  123. }
  124. }
  125. module.exports = WelcomeScreen;
  126. const styles = {
  127. root: {
  128. flexGrow: 1,
  129. justifyContent: 'center',
  130. alignItems: 'center'
  131. },
  132. h1: {
  133. fontSize: 24,
  134. textAlign: 'center',
  135. margin: 30
  136. },
  137. footer: {
  138. fontSize: 10,
  139. color: '#888',
  140. marginTop: 10
  141. }
  142. };