forked from ant-design/ant-design-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
72 lines (64 loc) · 1.67 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import * as React from 'react';
import { View, Text, TouchableWithoutFeedback } from 'react-native';
import TagStyle from './style/index';
import TagProps from './TagPropsType';
export default class Modal extends React.Component<TagProps, any> {
static defaultProps = {
disabled: false,
selected: false,
onChange() {},
};
constructor(props) {
super(props);
this.state = {
selected: props.selected,
closed: false,
};
}
componentWillReceiveProps(nextProps) {
if (this.props.selected !== nextProps.selected) {
this.setState({
selected: nextProps.selected,
});
}
}
onClick = () => {
const { disabled, onChange } = this.props;
if (disabled) {
return;
}
const isSelect: boolean = this.state.selected;
this.setState({
selected: !isSelect,
}, () => {
onChange(!isSelect);
});
}
render() {
const {children, disabled, style} = this.props;
const selected = this.state.selected;
let wrapStyle;
let textStyle;
if (!selected && !disabled) {
wrapStyle = TagStyle.normalWrap;
textStyle = TagStyle.normalText;
}
if (selected && !disabled) {
wrapStyle = TagStyle.activeWrap;
textStyle = TagStyle.activeText;
}
if (disabled) {
wrapStyle = TagStyle.disabledWrap;
textStyle = TagStyle.disabledText;
}
return (
<View style={[ TagStyle.tag, style ]}>
<TouchableWithoutFeedback onPress={this.onClick}>
<View style={[TagStyle.wrap, wrapStyle]}>
<Text style={[TagStyle.text, textStyle]}>{children} </Text>
</View>
</TouchableWithoutFeedback>
</View>
);
}
}