react-native-navigation的迁移库

WelcomeScreen.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import React, { Component } from 'react';
  2. import { View, Text, Button } from 'react-native';
  3. import Navigation from 'react-native-navigation';
  4. class WelcomeScreen extends Component {
  5. constructor(props) {
  6. super(props);
  7. this.onClickPush = this.onClickPush.bind(this);
  8. }
  9. render() {
  10. return (
  11. <View style={styles.root}>
  12. <Text style={styles.h1}>{`React Native Navigation!`}</Text>
  13. <Button title="Switch to tab based app" onPress={this.onClickSwitchToTabs} />
  14. <Button title="Switch to app with side menus" onPress={this.onClickSwitchToSideMenus} />
  15. <Button title="Switch to lifecycle screen" onPress={this.onClickLifecycleScreen} />
  16. <Button title="Push" onPress={this.onClickPush} />
  17. <Text style={styles.footer}>{`this.props.id = ${this.props.id}`}</Text>
  18. </View>
  19. );
  20. }
  21. onClickSwitchToTabs() {
  22. Navigation.setRoot({
  23. tabs: [
  24. {
  25. container: {
  26. name: 'com.example.SimpleScreen',
  27. passProps: {
  28. text: 'This is tab 1',
  29. myFunction: () => 'Hello from a function!'
  30. }
  31. }
  32. },
  33. {
  34. container: {
  35. name: 'com.example.SimpleScreen',
  36. passProps: {
  37. text: 'This is tab 2'
  38. }
  39. }
  40. }
  41. ]
  42. });
  43. }
  44. onClickSwitchToSideMenus() {
  45. Navigation.setRoot({
  46. tabs: [
  47. {
  48. container: {
  49. name: 'com.example.SimpleScreen'
  50. }
  51. },
  52. {
  53. container: {
  54. name: 'com.example.SimpleScreen'
  55. }
  56. },
  57. {
  58. container: {
  59. name: 'com.example.SimpleScreen'
  60. }
  61. }
  62. ],
  63. sideMenu: {
  64. left: {
  65. container: {
  66. name: 'com.example.SimpleScreen'
  67. }
  68. },
  69. right: {
  70. container: {
  71. name: 'com.example.SimpleScreen'
  72. }
  73. }
  74. }
  75. });
  76. }
  77. onClickPush() {
  78. Navigation.on(this.props.id).push({
  79. name: 'com.example.SimpleScreen',
  80. passProps: {
  81. text: 'Pushed screen'
  82. }
  83. });
  84. }
  85. onClickLifecycleScreen() {
  86. Navigation.on(this.props.id).push({
  87. name: 'com.example.LifecycleScreen'
  88. });
  89. }
  90. }
  91. export default WelcomeScreen;
  92. const styles = {
  93. root: {
  94. flexGrow: 1,
  95. justifyContent: 'center',
  96. alignItems: 'center',
  97. backgroundColor: '#f5fcff'
  98. },
  99. h1: {
  100. fontSize: 24,
  101. textAlign: 'center',
  102. margin: 30
  103. },
  104. footer: {
  105. fontSize: 10,
  106. color: '#888',
  107. marginTop: 80
  108. }
  109. };