SingleImage.js
7.97 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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import Immutable, {Map} from 'immutable';
const {
AppRegistry,
StyleSheet,
Text,
View,
Image,
ListView,
Dimensions,
TouchableOpacity,
Platform,
} = ReactNative;
export default class SingleImage extends React.Component {
constructor(props) {
super(props);
this.state = {
width: Dimensions.get('window').width,
height: 0,
};
}
shouldComponentUpdate(nextProps,nextState){
if (Immutable.is(nextProps.resource, this.props.resource) && nextState.height==this.state.height) {
return false;
} else {
return true;
}
}
componentDidMount() {
let {resource} = this.props;
let template_name = resource.get('data');
let src = template_name.get('src');
let imageHeight = template_name.get('height');
let imageWidth = template_name.get('width');
if (!imageHeight || !imageWidth) {
Image.getSize(src, (width, height) => {
if (this.imageView) {
this.setState({width, height});
}
});
}
}
render() {
let {resource} = this.props;
let template_name = resource.get('data');
let src = template_name.get('src');
let linkUrl = template_name.get('url');
let imageHeight = template_name.get('height');
let imageWidth = template_name.get('width');
let tagList = template_name?template_name.get('tagList'):null;
tagList = tagList?tagList.toJS():[];
let tagListGlobal = template_name?template_name.get('tagListGlobal'):null;
tagListGlobal = tagListGlobal?tagListGlobal.toJS():[];
tagList = tagList.concat(tagListGlobal);
let tagListLimit = template_name?template_name.get('tagListLimit'):null;
tagListLimit = tagListLimit?tagListLimit.toJS():[];
tagList = tagList.concat(tagListLimit);
if (tagList.constructor != Array) {
tagList = [];
}
if (imageHeight && imageWidth) {
return (
<View style={{width: screenWidth,height: (imageHeight/imageWidth)*screenWidth,marginLeft: 10}}>
{linkUrl?<TouchableOpacity activeOpacity={0.5} onPress={() => {
this.props.onPressLink && this.props.onPressLink(linkUrl);
}}>
<Image
source={{uri: src}}
style={{width: screenWidth,height: (imageHeight/imageWidth)*screenWidth}}
/>
</TouchableOpacity>:<Image
source={{uri: src}}
style={{width: screenWidth,height: (imageHeight/imageWidth)*screenWidth}}
/>}
{tagList?tagList.map((value, i) => {
let is_limitbuy = value.is_limitbuy == 'Y'?true:false;
return (
<View
key={'values' + i}
style={{
maxWidth: screenWidth - 20,
height: tagHeigth,
position: 'absolute',
left: 10,
bottom: i*(tagHeigth+10)+10,
backgroundColor: 'transparent',
flexDirection: 'row',
justifyContent: 'flex-end',
alignItems: 'center',
borderRadius: 10,
}}
>
<Image source={require('../../image/KA_dian.png')} style={styles.icon} resizeMode={'contain'}></Image>
<TouchableOpacity activeOpacity={0.5} onPress={() => {
let pos_id = 102;
this.props.onPressProduct && this.props.onPressProduct(value.product_skn,i,pos_id,value.is_global);
}}>
<View style={styles.tagView}>
<Text style={{
maxWidth: screenWidth - 20 - 2*tagHeigth - 20,
color: 'white',
paddingLeft: 10,
paddingRight: 10,
backgroundColor: 'transparent',
}} numberOfLines={1}>{value.tagName}</Text>
{
is_limitbuy ? null : <TouchableOpacity style={styles.button} activeOpacity={0.5} onPress={() => {
let pos_id = 105;
let product_id = value.product_id?value.product_id:'';
this.props.onPressShopCar && this.props.onPressShopCar(value.product_skn,product_id,pos_id,value.is_global=='Y'?true:false);
}}>
<Image source={require('../../image/dian_gwc_bt.png')} style={styles.image} resizeMode={'contain'}></Image>
</TouchableOpacity>
}
</View>
</TouchableOpacity>
</View>
);
}):null}
</View>
);
}else {
return (
<View style={{width: screenWidth,height: (this.state.height/this.state.width)*screenWidth}}>
{linkUrl?<TouchableOpacity activeOpacity={0.5} onPress={() => {
this.props.onPressLink && this.props.onPressLink(linkUrl);
}}>
<Image
ref={(ref)=>this.imageView=ref}
source={{uri: src}}
style={{width: screenWidth,height: (this.state.height/this.state.width)*screenWidth}}
/>
</TouchableOpacity>:<Image
ref={(ref)=>this.imageView=ref}
source={{uri: src}}
style={{width: screenWidth,height: (this.state.height/this.state.width)*screenWidth}}
/>}
</View>
);
}
}
};
let screenWidth = Dimensions.get('window').width - 20;
let tagHeigth = Math.ceil(45 * Dimensions.get('window').width / 750);
let tagWidth = Math.ceil(65 * Dimensions.get('window').width / 750);
let imageView = null;
let styles = StyleSheet.create({
tagView: {
height : tagHeigth,
backgroundColor: 'rgba(0, 0, 0, 0.6)',
borderTopLeftRadius: 15,
borderBottomLeftRadius: 15,
borderTopRightRadius: 15,
borderBottomRightRadius: 15,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
button: {
height : tagHeigth,
width : tagWidth + 5,
backgroundColor: 'rgba(0, 0, 0, 0.6)',
borderTopRightRadius: 15,
borderBottomRightRadius: 15,
flexDirection: 'row',
},
image: {
width : tagWidth - 7,
height : tagHeigth,
marginLeft: 8,
backgroundColor: 'transparent',
},
icon: {
width : tagHeigth - 5,
height : tagHeigth - 5,
marginRight: 10,
backgroundColor: 'transparent',
},
rightDetail: {
maxWidth: Math.ceil(screenWidth * (2/3)) - 2*tagHeigth,
height : tagHeigth,
color: 'white',
paddingLeft: 10,
paddingRight: 10,
paddingTop: Platform.OS === 'ios' ? 5 : 2,
paddingBottom: Platform.OS === 'ios' ? 5 : 2,
},
});