react-native-navigation的迁移库

ComplexLayout.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. const testIDs = require('../testIDs');
  6. class ComplexLayout extends Component {
  7. constructor(props) {
  8. super(props);
  9. }
  10. render() {
  11. return (
  12. <View style={styles.root}>
  13. <Text style={styles.h1} testID={testIDs.CENTERED_TEXT_HEADER}>{this.props.text || 'Complex layout screen'}</Text>
  14. <Button title={'External component in stack'} testID={testIDs.EXTERNAL_COMPONENT_IN_STACK} onPress={() => this.onExternalComponentInStackPressed()} />
  15. <Button title={'External component in deep stack'} testID={testIDs.EXTERNAL_COMPONENT_IN_DEEP_STACK} onPress={() => this.onExternalComponentInDeepStackPressed()} />
  16. <Button title={'Sidemenu layout inside a bottomTab'} testID={testIDs.SIDE_MENU_LAYOUT_INSIDE_BOTTOM_TAB} onPress={() => this.onSideMenuLayoutInsideBottomTabPressed()} />
  17. </View>
  18. );
  19. }
  20. onExternalComponentInStackPressed() {
  21. Navigation.showModal({
  22. stack: {
  23. children: [{
  24. externalComponent: {
  25. name: 'RNNCustomComponent',
  26. passProps: {
  27. text: 'External component in stack'
  28. }
  29. }
  30. }]
  31. }
  32. });
  33. }
  34. onExternalComponentInDeepStackPressed() {
  35. Navigation.showModal({
  36. stack: {
  37. children: [{
  38. component: {
  39. name: 'navigation.playground.TextScreen'
  40. }
  41. },
  42. {
  43. externalComponent: {
  44. name: 'RNNCustomComponent',
  45. passProps: {
  46. text: 'External component in deep stack'
  47. }
  48. }
  49. }]
  50. }
  51. });
  52. }
  53. onSideMenuLayoutInsideBottomTabPressed() {
  54. Navigation.dismissAllModals();
  55. Navigation.setRoot({
  56. root: {
  57. bottomTabs: {
  58. children: [
  59. {
  60. stack: {
  61. children: [
  62. {
  63. component: {
  64. name: 'navigation.playground.TextScreen',
  65. },
  66. },
  67. ],
  68. options: {
  69. bottomTab: {
  70. text: 'Stack',
  71. icon: require('../images/one.png'),
  72. },
  73. },
  74. },
  75. },
  76. {
  77. sideMenu: {
  78. left: {
  79. component: {
  80. name: 'navigation.playground.SideMenuScreen',
  81. },
  82. },
  83. center: {
  84. stack: {
  85. children: [
  86. {
  87. component: {
  88. name: 'navigation.playground.TextScreen',
  89. },
  90. },
  91. ],
  92. },
  93. },
  94. options: {
  95. bottomTab: {
  96. text: 'SideMenu',
  97. icon: require('../images/two.png'),
  98. },
  99. },
  100. },
  101. },
  102. ]
  103. }
  104. }
  105. });
  106. }
  107. }
  108. module.exports = ComplexLayout;
  109. const styles = {
  110. root: {
  111. flexGrow: 1,
  112. justifyContent: 'center',
  113. alignItems: 'center',
  114. backgroundColor: '#f5fcff'
  115. },
  116. h1: {
  117. fontSize: 24,
  118. textAlign: 'center',
  119. margin: 10
  120. },
  121. h2: {
  122. fontSize: 12,
  123. textAlign: 'center',
  124. margin: 10
  125. },
  126. footer: {
  127. fontSize: 10,
  128. color: '#888',
  129. marginTop: 10
  130. }
  131. };