BannerReourceList.js
3.14 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
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import {getSlicedUrl} from '../../utils/Utils';
const {
AppRegistry,
StyleSheet,
Text,
View,
Image,
ListView,
Dimensions,
TouchableOpacity,
PixelRatio,
} = ReactNative;
export default class BannerReourceList extends React.Component {
constructor(props) {
super(props);
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
});
}
renderRow(rowData,sectionID,rowID,highlightRow) {
let newSrc = getSlicedUrl(rowData.src, itemWidth, itemWidth, 1);
return (
<TouchableOpacity activeOpacity={0.5} onPress={() => {
this.props.onPressSlideItem && this.props.onPressSlideItem(rowData.url);
}}>
<View style={styles.row}>
<View style={{width: itemWidth, height: itemWidth}}>
<Image
source={{uri: newSrc}}
style={{width: itemWidth, height: itemWidth}}
resizeMode={'contain'}
></Image>
</View>
<View style={styles.textV}>
<Text style={styles.text} numberOfLines={1}>
{rowData.name}
</Text>
</View>
</View>
</TouchableOpacity>
);
}
render() {
let {resource} = this.props;
let res = resource.toJS();
let data = res.data;
let title = data?data.title:null;
let list = data?data.list:null;
if (!resource || resource.size == 0 || !list) {
return null;
}
return (
<View style={styles.cellList}>
<View style={styles.titleStyle}>
<Text style={styles.titleText} numberOfLines={1}>{title.title}</Text>
</View>
<ListView
showsHorizontalScrollIndicator ={false}
dataSource={this.dataSource.cloneWithRows(list)}
horizontal={true}
renderRow={this.renderRow.bind(this)}
/>
</View>
);
}
};
let {width, height} = Dimensions.get('window');
let itemWidth= Math.ceil(width/4);
let itemHeight = 50;
let styles = StyleSheet.create({
cellList:{
justifyContent: 'center',
width: Dimensions.get('window').width,
height: 200,
backgroundColor: 'white',
},
titleStyle:{
alignItems: 'center',
justifyContent: 'center',
height: 48,
width:Dimensions.get('window').width,
backgroundColor: 'white',
},
row: {
marginLeft: 10,
width: itemWidth,
height: itemWidth,
backgroundColor: 'white',
},
textV: {
width: itemWidth,
height: 40,
backgroundColor:'transparent',
},
text: {
fontWeight: 'bold',
color: 'gray',
width: itemWidth,
height: 40,
textAlign: 'center',
backgroundColor:'transparent',
},
titleText: {
textAlign: 'center',
fontSize: 16,
},
});