react-native-navigation的迁移库

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import React, {Component, PropTypes} from 'react';
  2. import {
  3. Text,
  4. View,
  5. ScrollView,
  6. TouchableOpacity,
  7. StyleSheet
  8. } from 'react-native';
  9. import { connect } from 'react-redux';
  10. import * as counterActions from '../reducers/counter/actions';
  11. import * as appActions from '../reducers/app/actions';
  12. // this is a traditional React component connected to the redux store
  13. class LoginScreen extends Component {
  14. static propTypes = {
  15. str: PropTypes.string.isRequired,
  16. obj: PropTypes.object.isRequired,
  17. num: PropTypes.number.isRequired
  18. };
  19. constructor(props) {
  20. super(props);
  21. console.log(props);
  22. }
  23. render() {
  24. return (
  25. <View style={{flex: 1, padding: 20}}>
  26. <Text style={styles.text}>
  27. <Text style={{fontWeight: '500'}}>Counter: </Text> {this.props.counter.count}
  28. </Text>
  29. <TouchableOpacity onPress={ this.onIncrementPress.bind(this) }>
  30. <Text style={styles.button}>Increment Counter</Text>
  31. </TouchableOpacity>
  32. <TouchableOpacity onPress={ this.onLoginPress.bind(this) }>
  33. <Text style={styles.button}>Login</Text>
  34. </TouchableOpacity>
  35. <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
  36. <Text style={{fontWeight: '500'}}>Number prop: {this.props.num}</Text>
  37. <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text>
  38. <Text style={{fontWeight: '500'}}>Array prop: {this.props.obj.arr[0].str}</Text>
  39. <Text style={{fontWeight: '500'}}>Array of arrays prop: {JSON.stringify(this.props.obj.arr2)}</Text>
  40. </View>
  41. );
  42. }
  43. onIncrementPress() {
  44. this.props.dispatch(counterActions.increment());
  45. }
  46. onLoginPress() {
  47. this.props.dispatch(appActions.login());
  48. }
  49. }
  50. const styles = StyleSheet.create({
  51. text: {
  52. textAlign: 'center',
  53. fontSize: 18,
  54. marginBottom: 10,
  55. marginTop:10,
  56. },
  57. button: {
  58. textAlign: 'center',
  59. fontSize: 18,
  60. marginBottom: 10,
  61. marginTop:10,
  62. color: 'blue'
  63. }
  64. });
  65. // which props do we want to inject, given the global state?
  66. function mapStateToProps(state) {
  67. return {
  68. counter: state.counter
  69. };
  70. }
  71. export default connect(mapStateToProps)(LoginScreen);