react-native-navigation的迁移库

PushedScreen.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import React, {
  2. Component,
  3. Text,
  4. View,
  5. ScrollView,
  6. TouchableOpacity,
  7. StyleSheet,
  8. TextInput
  9. } from 'react-native';
  10. import { connect } from 'react-redux';
  11. import * as counterActions from '../reducers/counter/actions';
  12. // this is a traditional React component connected to the redux store
  13. class PushedScreen extends Component {
  14. static navigatorStyle = {
  15. statusBarColor: '#303F9F',
  16. toolBarColor: '#3F51B5',
  17. navigationBarColor: '#303F9F',
  18. buttonsTint: '#FFFFFF',
  19. titleColor: '#FFFFFF',
  20. tabSelectedTextColor: '#FFA000',
  21. tabNormalTextColor: '#FFC107',
  22. tabIndicatorColor: '#FF4081'
  23. };
  24. constructor(props) {
  25. super(props);
  26. this.bgColor = this.getRandomColor();
  27. }
  28. getRandomColor() {
  29. var letters = '0123456789ABCDEF'.split('');
  30. var color = '#';
  31. for (var i = 0; i < 6; i++ ) {
  32. color += letters[Math.floor(Math.random() * 16)];
  33. }
  34. return color;
  35. }
  36. render() {
  37. return (
  38. <View style={{flex: 1, padding: 20, backgroundColor: this.bgColor}}>
  39. <Text style={styles.text}>
  40. <Text style={{fontWeight: '500'}}>Counter: </Text> {this.props.counter.count}
  41. </Text>
  42. <TouchableOpacity onPress={ this.onIncrementPress.bind(this) }>
  43. <Text style={styles.button}>Increment Counter</Text>
  44. </TouchableOpacity>
  45. <TouchableOpacity onPress={ this.onPushPress.bind(this) }>
  46. <Text style={styles.button}>Push Another</Text>
  47. </TouchableOpacity>
  48. <TouchableOpacity onPress={ this.onPopPress.bind(this) }>
  49. <Text style={styles.button}>Pop Screen</Text>
  50. </TouchableOpacity>
  51. <TextInput style={{height: 40, borderColor: 'gray', borderWidth: 1}}/>
  52. </View>
  53. );
  54. }
  55. onIncrementPress() {
  56. this.props.dispatch(counterActions.increment());
  57. }
  58. onPushPress() {
  59. this.props.navigator.push({
  60. title: "More",
  61. screen: "example.PushedScreen"
  62. });
  63. }
  64. onPopPress() {
  65. this.props.navigator.pop();
  66. }
  67. }
  68. const styles = StyleSheet.create({
  69. text: {
  70. textAlign: 'center',
  71. fontSize: 18,
  72. marginBottom: 10,
  73. marginTop:10
  74. },
  75. button: {
  76. textAlign: 'center',
  77. fontSize: 18,
  78. marginBottom: 10,
  79. marginTop:10,
  80. color: 'blue'
  81. }
  82. });
  83. // which props do we want to inject, given the global state?
  84. function mapStateToProps(state) {
  85. return {
  86. counter: state.counter
  87. };
  88. }
  89. export default connect(mapStateToProps)(PushedScreen);