forked from osdio/noder-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommentUp.js
More file actions
117 lines (96 loc) · 1.86 KB
/
CommentUp.js
File metadata and controls
117 lines (96 loc) · 1.86 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import React, {
Component,
View,
TouchableOpacity,
StyleSheet,
Text,
PropTypes
} from 'react-native';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import Icon from 'react-native-vector-icons/Ionicons';
import Spinner from './base/Spinner';
class CommentUp extends Component {
static propTypes = {
pending: PropTypes.bool,
disabled: PropTypes.bool,
replyId: PropTypes.string,
ups: PropTypes.array,
userId: PropTypes.string
};
static defaultProps = {
pending: false,
disabled: false,
ups: []
};
constructor(props){
super(props);
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
}
_onUpPress() {
const {disabled, pending, upReply, replyId, userId, topicId} = this.props;
if (disabled) {
return window.alert('不能给自己点赞哦!')
}
if (pending) return;
upReply({
replyId,
userId,
topicId
});
}
_isUped() {
return this.props.ups.some(item=> {
return item == this.props.userId
})
}
_renderUpIcon() {
if (this.props.pending) {
return (
<Spinner
size='small'
style={styles.loading}
/>
)
}
return (
<Icon
name={'thumbsup'}
size={16}
color={this._isUped() ? '#3498DB':'rgba(0,0,0,0.2)'}
style={styles.upIcon}
/>
)
}
render() {
const {ups} = this.props;
let count = ups.length;
return (
<TouchableOpacity
onPress={this._onUpPress.bind(this)}>
<View style={this.props.style}>
{this._renderUpIcon()}
{count == 0 ? null : (
<View style={styles.textWrapper}>
<Text style={styles.text}>{count}</Text>
</View>
)}
</View>
</TouchableOpacity>
)
}
}
const styles = StyleSheet.create({
textWrapper: {
paddingLeft: 7
},
text: {
fontSize: 12,
color: 'rgba(0,0,0,0.2)',
height: 12
},
loading: {
height: 12,
width: 16
}
});
export default CommentUp;