react-native-navigation的迁移库

PushedScreen.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import React, {Component, PropTypes} from 'react';
  2. import {
  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. static propTypes = {
  25. passed: PropTypes.string.isRequired
  26. };
  27. constructor(props) {
  28. super(props);
  29. this.bgColor = this.getRandomColor();
  30. }
  31. getRandomColor() {
  32. var letters = '0123456789ABCDEF'.split('');
  33. var color = '#';
  34. for (var i = 0; i < 6; i++ ) {
  35. color += letters[Math.floor(Math.random() * 16)];
  36. }
  37. return color;
  38. }
  39. render() {
  40. return (
  41. <View style={{flex: 1, padding: 20, backgroundColor: this.bgColor}}>
  42. <Text style={styles.text}>
  43. <Text style={{fontWeight: '500'}}>Counter: </Text> {this.props.counter.count}
  44. </Text>
  45. <TouchableOpacity onPress={ this.onIncrementPress.bind(this) }>
  46. <Text style={styles.button}>Increment Counter</Text>
  47. </TouchableOpacity>
  48. <TouchableOpacity onPress={ this.onPushPress.bind(this) }>
  49. <Text style={styles.button}>Push Another</Text>
  50. </TouchableOpacity>
  51. <TouchableOpacity onPress={ this.onPopPress.bind(this) }>
  52. <Text style={styles.button}>Pop Screen</Text>
  53. </TouchableOpacity>
  54. <TouchableOpacity onPress={ this.onShowModalPress.bind(this) }>
  55. <Text style={styles.button}>Modal Screen</Text>
  56. </TouchableOpacity>
  57. <TouchableOpacity onPress={ this.onDismissModal.bind(this) }>
  58. <Text style={styles.button}>Dismiss modal</Text>
  59. </TouchableOpacity>
  60. <TouchableOpacity onPress={ this.onDismissAllModalsPress.bind(this) }>
  61. <Text style={styles.button}>Dismiss all modals</Text>
  62. </TouchableOpacity>
  63. <TextInput style={{height: 40, borderColor: 'gray', borderWidth: 1}}/>
  64. <Text style={{fontWeight: '500'}}>{this.props.passed}</Text>
  65. </View>
  66. );
  67. }
  68. onIncrementPress() {
  69. this.props.dispatch(counterActions.increment());
  70. }
  71. onPushPress() {
  72. this.props.navigator.push({
  73. title: "More",
  74. screen: "example.PushedScreen"
  75. });
  76. }
  77. onPopPress() {
  78. this.props.navigator.pop();
  79. }
  80. onShowModalPress() {
  81. this.props.navigator.showModal({
  82. title: "Modal Screen",
  83. screen: "example.PushedScreen"
  84. });
  85. }
  86. onDismissAllModalsPress() {
  87. this.props.navigator.dismissAllModals();
  88. }
  89. onDismissModal() {
  90. this.props.navigator.dismissModal();
  91. }
  92. }
  93. const styles = StyleSheet.create({
  94. text: {
  95. textAlign: 'center',
  96. fontSize: 18,
  97. marginBottom: 10,
  98. marginTop:10
  99. },
  100. button: {
  101. textAlign: 'center',
  102. fontSize: 18,
  103. marginBottom: 10,
  104. marginTop:10,
  105. color: 'blue'
  106. }
  107. });
  108. // which props do we want to inject, given the global state?
  109. function mapStateToProps(state) {
  110. return {
  111. counter: state.counter
  112. };
  113. }
  114. export default connect(mapStateToProps)(PushedScreen);