1 | import React, {
|
2 | Component, PropTypes,
|
3 | } from 'react';
|
4 |
|
5 | import {
|
6 | TouchableWithoutFeedback, View,
|
7 | } from 'react-native';
|
8 |
|
9 | import Checkbox from '../Checkbox';
|
10 | import Text from './stringToText';
|
11 |
|
12 | class Item extends Component {
|
13 |
|
14 | constructor(props) {
|
15 | super(props);
|
16 | this.componentWillReceiveProps(props);
|
17 | }
|
18 |
|
19 |
|
20 | componentWillReceiveProps = (props) => {
|
21 | this.state = { ...props };
|
22 | }
|
23 |
|
24 |
|
25 | set state(state) {
|
26 | state && Object.keys(state).forEach(key => this[key] = state[key]);
|
27 | }
|
28 |
|
29 | picked = false
|
30 |
|
31 | render() {
|
32 | const { children, onChange, picked, style } = this;
|
33 | return (
|
34 | <TouchableWithoutFeedback onPress={() => onChange(!picked)}>
|
35 | {Text.isText(children) ? (
|
36 | <View style={[{ flexDirection: 'row', height: 54, alignItems: 'center', justifyContent: 'space-between', paddingHorizontal: 20, borderTopWidth: 1, borderTopColor: '#e2e2e2' }, style]}>
|
37 | <Text>{children}</Text>
|
38 | {picked && (
|
39 | <Checkbox checked={picked} />
|
40 | )}
|
41 | </View>
|
42 | ) : (
|
43 | <children.type {...children.props} picked={picked} />
|
44 | )}
|
45 | </TouchableWithoutFeedback>
|
46 | );
|
47 | }
|
48 | }
|
49 |
|
50 | Item.propTypes = {
|
51 | picked: PropTypes.bool,
|
52 | style: View.propTypes.style,
|
53 | };
|
54 |
|
55 | Item.defaultProps = {
|
56 | picked: false,
|
57 | style: null,
|
58 | };
|
59 |
|
60 | export default Item;
|