react-native-navigation的迁移库

SecondTabScreen.js 2.1KB

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