SixLinesFloor.js
2.38 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
'use strict';
import React, {Component} from 'react';
import ReactNative, {
View,
ListView,
TouchableOpacity,
StyleSheet,
Dimensions,
} from 'react-native';
import Immutable, {Map} from 'immutable';
import SlicedImage from '../../../common/components/SlicedImage';
import YH_Image from '../../../common/components/YH_Image';
import HeadTitleCell from '../cell/HeadTitleCell';
/**
* 六图并列楼层,
* 这个楼层是六个图片,一行两个展示
**/
export default class SixLinesFloor extends Component{
constructor(props) {
super(props);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
});
this.renderRow = this.renderRow.bind(this);
}
renderRow(rowData,sectionID,rowID,highlightRow){
let goodsImageUrl = rowData.get('src');
goodsImageUrl = SlicedImage.getSlicedUrl(goodsImageUrl, imageWidth, imageHeight, 2);
return(
<TouchableOpacity activeOpacity={1}
onPress={() => this.props.onPressImageItem && this.props.onPressImageItem(rowData.get('url'), rowID)}>
<YH_Image style={styles.goodsImage} url={goodsImageUrl} />
</TouchableOpacity>
);
}
render(){
let data = this.props.data;
let title = data.get("title");
let imglst = data.get("list");
let lineNumber = Math.floor((imglst.size + 1)/2);
let containerHeight = 40 + lineNumber * imageHeight;
return(
<View style={[styles.container, {height: containerHeight}]}>
<HeadTitleCell title={title.get('name')} moreUrl={title.get('more_url')} onPressTitleMore={this.props.onPressTitleMore}/>
<ListView
contentContainerStyle={styles.listViewContainer}
dataSource={this.dataSource.cloneWithRows(imglst.toArray())}
renderRow={this.renderRow}/>
</View>
);
}
};
let {width} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 320;
let imageWidth = Math.floor(width / 2);
let imageHeight = Math.floor(imageWidth * 180 / 375);
let styles = StyleSheet.create({
container: {
width: width,
},
listViewContainer: {
width: width,
flexDirection: 'row',
flexWrap: 'wrap',
alignItems:'flex-start',
},
goodsImage: {
width: imageWidth,
height: imageHeight,
},
});