-
Notifications
You must be signed in to change notification settings - Fork 1
/
MLContentCell.js
174 lines (138 loc) · 4.12 KB
/
MLContentCell.js
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
* Created by milodong on 2016/10/24.
*/
import React, {Component} from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
PanResponder
} from 'react-native';
var Dimensions = require('Dimensions');
var width = Dimensions.get('window').width;
var Button = require('./Button');
var ContentCell = React.createClass({
getDefaultProps() {
return{
title: '花',
subTitle: '漂亮的花',
iconName: 'mine_icon',
cost: 122,
finishStatus: true,
callAddClick: null,
callDecreaseClick: null,
callDelectClick: null
}
},
getInitialState() {
return{
SelectStatus: false,
left: 0
}
},
componentWillMount(){
this._panResponder = PanResponder.create({
onStartShouldSetPanResponder: () => true,
onMoveShouldSetPanResponder: ()=> true,
onPanResponderGrant: ()=>{
},
onPanResponderMove: (evt,gestureState)=>{
if (gestureState.dx< 0){
if (gestureState.dx < -80){
this.setState({
left: -80
})
}else if (gestureState.dx >= -80){
this.setState({
left: gestureState.dx
})
}
}else {
if (gestureState.dx > 80 && this.state.left < 0){
this.setState({
left: 0
})
}else if (gestureState.dx < 80 && this.state.left < 0){
this.setState({
left: gestureState.dx - 80
})
}
}
},
onPanResponderRelease: (evt,gestureState)=>{
var dx = gestureState.dx < 0 ? -80 : 0
this.setState({
left: dx
})
}
})
},
render() {
return (
<View style={{width: width + 80, height: 120, backgroundColor: 'white', flexDirection: 'row', alignItems: 'center', marginLeft: this.state.left}}
{...this._panResponder.panHandlers}
>
<Image source= {{uri : this.props.iconName}} style={{width: 90, height: 90, marginLeft: 15}}/>
{/* 下部分 */}
{this.bottomView()}
<Button
containerStyle = {{ backgroundColor: '#FD7D7F', width:80, height: 120, alignItems: 'center', justifyContent: 'center'}}
style={{ fontSize: 16, textAlign: 'center', color: 'white'}}
text={'删除'}
onPress={() => this.delectClick()}
/>
</View>
);
},
bottomView() {
var price = this.props.cost.toFixed(2);
var priceInt = price.substring(0, price.length - 2);
var priceFloat = price.substring(price.length - 2, price.length);
if (this.props.finishStatus){
return(
<View style={styles.bottomViewStyle}>
<Text numberOfLines={1} style={{color: '#767676', fontSize: 15, marginRight: 15}}>{this.props.title}</Text>
<Text numberOfLines={1} style={{color: '#FD7E7F', fontSize: 13, marginTop: 8,marginRight: 15}}>{this.props.subTitle}</Text>
<Text style={{color: '#FD696B', fontSize: 16, position: 'absolute', bottom: 20}}>¥
<Text style={{color: '#FD696B', fontSize: 24}}>{priceInt}</Text>
<Text style={{color: '#FD696B', fontSize: 20}}>{priceFloat}</Text>
</Text>
</View>
)
}else {
return(
<View style={styles.bottomViewStyle}>
<Text numberOfLines={1} style={{color: '#767676', fontSize: 15}}>{this.props.title}</Text>
<Text numberOfLines={1} style={{color: '#FD7E7F', fontSize: 13, marginTop: 8}}>{this.props.subTitle}</Text>
<Text style={{color: '#FD696B', fontSize: 16, position: 'absolute', bottom: 20}}>¥
<Text style={{color: '#FD696B', fontSize: 24}}>{priceInt}</Text>
<Text style={{color: '#FD696B', fontSize: 20}}>{priceFloat}</Text>
</Text>
<View style={{width:65, height: 20, alignItems: 'center', justifyContent: 'center',borderWidth: 0.5, borderColor: 'red', borderRadius: 3, position: 'absolute', right: 20, bottom: 20}}>
<Text style={{fontSize: 12, textAlign: 'center', color: 'red'}}>失效</Text>
</View>
</View>
)
}
},
callSelectClick(selectStatus) {
this.setState({
SelectStatus : !selectStatus
})
},
delectClick() {
this.props.callDelectClick('删除');
}
})
const styles = StyleSheet.create({
bottomViewStyle: {
width: width - 108,
height: 105,
marginTop: 15,
marginLeft: 8
}
});
module.exports = ContentCell;