homeList.js
6.5 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
/**
* Created by Cassie on 2018/03/06
*/
import React, { Component } from 'react';
import {
StyleSheet,
View,
Text,
TouchableOpacity,
Image,
FlatList
} from 'react-native';
import Video from 'react-native-video';
import {zoomW,zoomH} from '../utils/getSize';
const isTop = require('../img/isTop.png');
const cover = require('../img/cover.png');
const video = require('../img/video.png');
const top1 = require('../img/top1.png');
const top2 = require('../img/top2.png');
const top3 = require('../img/top3.png');
export default class HomeList extends Component {
constructor(props) {
super(props);
this.state = {};
}
/* 渲染列表*/
keyExtractor = (item,index) => index;
/*首页列表*/
renderHomeItem = ({item,index}) => (
<TouchableOpacity style={styles.listItem} onPress={() => this.toDetail()}>
<View style={styles.itemTop}>
{item.isTop && <Image source={isTop} style={styles.isTopIcon} resizeMode="contain" />}
<Text numberOfLines={1} style={[styles.itemTitle,{width:item.isTop ? (305/zoomW):(345/zoomW)}]}>{item.title}</Text>
</View>
<View style={styles.itemContent}>
{item.cover && <Image source={cover} style={styles.coverImg} resizeMode="contain" />}
{item.video && !item.cover && <Image source={video} style={styles.coverImg} resizeMode="contain" />}
{item.content && !item.cover && !item.video && <Text numberOfLines={2} style={styles.contentText}>{item.content}</Text>}
</View>
<View style={styles.itemBottom}>
<Text style={{fontSize:14,color:'#999'}}>8K回复</Text>
<View style={{display:'flex',flexDirection:'row',alignItems:'center'}}>
<Image source={cover} style={styles.avatar} resizeMode="cover" />
<Text style={{fontSize:14,color:'#999'}}>李静·灌水区</Text>
</View>
</View>
</TouchableOpacity>
);
/*最新列表*/
renderNewItem = ({item,index}) => (
<TouchableOpacity style={styles.listItem}>
<View style={styles.itemTop}>
<Text numberOfLines={1} style={styles.itemTitle}>{item.title}</Text>
</View>
<View style={styles.itemContent}>
<Image source={video} style={[styles.moreImg,{marginRight:(5/zoomW)}]} resizeMode="cover" />
<Image source={video} style={[styles.moreImg,{marginRight:(5/zoomW)}]} resizeMode="cover" />
<Image source={video} style={styles.moreImg} resizeMode="cover" />
</View>
<View style={styles.itemBottom}>
<Text style={{fontSize:14,color:'#999'}}>8K回复</Text>
<View style={{display:'flex',flexDirection:'row',alignItems:'center'}}>
<Image source={cover} style={styles.avatar} resizeMode="cover" />
<Text style={{fontSize:14,color:'#999'}}>张空关·2017-12-30</Text>
</View>
</View>
</TouchableOpacity>
);
/*最热列表*/
renderHotItem = ({item,index}) => (
<TouchableOpacity style={styles.listItem}>
<View style={styles.itemTop}>
{index == 0 && <Image source={top1} style={styles.topNumIcon} resizeMode="contain" />}
{index == 1 && <Image source={top2} style={styles.topNumIcon} resizeMode="contain" />}
{index == 2 && <Image source={top3} style={styles.topNumIcon} resizeMode="contain" />}
<Text numberOfLines={1} style={[styles.itemTitle,{width:index == 0 || index == 1 || index == 2 ? (295/zoomW):(345/zoomW)}]}>{item.title}</Text>
</View>
<View style={styles.itemContent}>
{item.cover && <Image source={cover} style={styles.coverImg} resizeMode="contain" />}
{item.video && !item.cover && <Image source={video} style={styles.coverImg} resizeMode="contain" />}
{item.content && !item.cover && !item.video && <Text numberOfLines={2} style={styles.contentText}>{item.content}</Text>}
</View>
<View style={styles.itemBottom}>
<Text style={{fontSize:14,color:'#999'}}>8K回复</Text>
<View style={{display:'flex',flexDirection:'row',alignItems:'center'}}>
<Image source={cover} style={styles.avatar} resizeMode="cover" />
<Text style={{fontSize:14,color:'#999'}}>张空关·2017-12-30</Text>
</View>
</View>
</TouchableOpacity>
);
/*跳转到详情*/
toDetail(){
this.props.navigation.navigate('Detail',{})
};
render() {
return (
<View style={styles.background}>
{this.props.homeList && <FlatList keyExtractor={this.keyExtractor} data={this.props.homeList} renderItem={this.renderHomeItem} />}
{this.props.newList && <FlatList keyExtractor={this.keyExtractor} data={this.props.newList} renderItem={this.renderNewItem} />}
{this.props.hotList && <FlatList keyExtractor={this.keyExtractor} data={this.props.hotList} renderItem={this.renderHotItem} />}
</View>
);
}
}
const styles = StyleSheet.create({
background:{
width:'100%',
height:'100%',
backgroundColor:'#f2f2f2'
},
listItem:{
minHeight:(110/zoomH),
maxHeight:(318/zoomH),
backgroundColor:'#fff',
marginBottom:(8/zoomH),
padding:(15/zoomH),
},
itemTop:{
width:(345/zoomW),
display:'flex',
flexDirection:'row',
alignItems:'center'
},
itemTitle:{
color:'#000',
fontSize:16,
fontWeight:'600'
},
isTopIcon:{
width:(40/zoomW),
},
topNumIcon:{
width:(40/zoomW),
marginRight:10,
marginTop:(2/zoomH)
},
coverImg:{
width:(345/zoomW),
height:(193/zoomH)
},
moreImg:{
width:(112/zoomW),
height:(112/zoomW)
},
itemContent:{
display:'flex',
flexDirection:'row',
justifyContent:'center',
marginTop:(15/zoomH),
marginBottom:(15/zoomH)
},
contentText:{
fontSize:14,
color:'#666'
},
itemBottom:{
display:'flex',
flexDirection:'row',
justifyContent:'space-between'
},
avatar:{
width:(20/zoomW),
height:(20/zoomW),
borderRadius:(10/zoomW),
marginRight:(6/zoomW)
}
});