index.js
10.2 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/**
* Created by DEV005 on 2017/11/13.
*/
/**
* Created by tdzl2003 on 12/18/16.
*/
import React, {Component} from "react";
import {
Image,
ListView,
NativeModules,
StyleSheet,
Text,
TextInput,
TouchableOpacity,
View,
Platform,
RefreshControl,
ActivityIndicator,
ScrollView,
Dimensions,
Modal,
FlatList,
Button
} from "react-native";
import { observable, useStrict, action } from 'mobx';
import { observer } from 'mobx-react';
import {xnToast} from "../utils/utils";
import AppService from "../service/AppService";
import Orientation from 'react-native-orientation';
import moment from "moment";
import {timeShow} from "../utils/utils";
import Video from 'react-native-video'
import SearchBar from 'react-native-search-bar'
export default class DEMO extends Component {
static navigationOptions = ({ navigation, screenProps })=>({
title: '收藏',
headerLeft:(<View style={{flexDirection: 'row',flex:1}}>
<TouchableOpacity style={{flexDirection: 'column',justifyContent: 'center',paddingRight:15,paddingLeft:15}} onPress={navigation.state.params?navigation.state.params._close:null}>
<Image style={{ width:16,height:16}} source={require('../img/back.png')} resizeMode="contain"/>
</TouchableOpacity>
</View>)
});
constructor(props) {
super(props);
this.state = {
dataSoure:[
// {objectType:'picture'},
// {objectType:'video'},
// {objectType:'text'},
// {objectType:'audio'},
// {objectType:'url'}
],
pause:false,
allList:[]
};
}
componentWillMount(){
this.getData();
}
getData=()=>{
let vm={
pageSize:0,
unionId:global.unionId
};
AppService.findCollectList(vm).then(data=>{
if (data.errors == null || data.errors.length > 0) {
xnToast(data.errors[0].message);
return
}
this.setState({
dataSoure:data.result,
allList:data.result
});
})
}
setTime=(e)=>{
if (!this.state.pause){
this.setState({
pause:true
})
}else {
this.setState({
pause:false
})
}
}
componentDidMount(){
let _this=this;
//设置头部
this.props.navigation.setParams({
_goBack:()=>{
this.props.navigation.goBack();
},
_close:()=>{
NativeModules.system.navTo("BACK")
}
});
};
_toPage=(page,item)=>{
let that = this;
this.props.navigation.navigate(page, {item:item,callBack:()=>{
that.getData();
}})
};
rowRender =(item,i)=>{
if (item.objectType == 'IMAGE') {
return (
<TouchableOpacity onPress={()=>{this._toPage('Detail',item)}}>
<View style={{flex:1,backgroundColor:'#fff',padding:25,borderRadius:8}}>
<Image resizeMode="contain" source={{uri:item.objectContent}} style={{backgroundColor:'#ececf1',height:90,width:90}}></Image>
<Text style={{color:'#999',fontSize:12,marginTop:20}}>{item.objectName} <Text style={{color:'#999',fontSize:14}}>{}</Text></Text>
</View>
</TouchableOpacity>
)
}else if (item.objectType == 'VIDEO') {
return (
<TouchableOpacity onPress={()=>{this._toPage('Detail',item)}}>
<View style={{flex:1,backgroundColor:'#fff',padding:25,borderRadius:8}}>
{/*<Image style={{backgroundColor:'blue',height:90,width:90}}></Image>*/}
<Video source={{uri: item.objectContent}} // 视频的URL地址,或者本地地址,都可以.
rate={1} // 控制暂停/播放,0 代表暂停paused, 1代表播放normal.
volume={1.0} // 声音的放大倍数,0 代表没有声音,就是静音muted, 1 代表正常音量 normal,更大的数字表示放大的倍数
muted={false} // true代表静音,默认为false.
paused={this.state.pause} // true代表暂停,默认为false
resizeMode="cover" // 视频的自适应伸缩铺放行为,
repeat={false} // 是否重复播放
playInBackground={false} // 当app转到后台运行的时候,播放是否暂停
playWhenInactive={false} // [iOS] Video continues to play when control or notification center are shown. 仅适用于IOS
onProgress={this.setTime} // 进度控制,每250ms调用一次,以获取视频播放的进度
style={{height:90,width:90,backgroundColor:'#999'}} />
<Text style={{color:'#999',fontSize:12,marginTop:20}}>{item.objectName} <Text style={{color:'#999',fontSize:14}}>{moment(Number(item.time)).format('YYYY-MM-DD HH:mm')}</Text></Text>
</View>
</TouchableOpacity>
)
}else if (item.objectType == 'TEXT') {
return (
<TouchableOpacity onPress={()=>{this._toPage('Detail',item)}}>
<View style={{flex:1,backgroundColor:'#fff',padding:25,borderRadius:8}}>
<Text style={{fontSize:16,color:'#333'}}>{item.objectContent}</Text>
<Text style={{color:'#999',fontSize:12,marginTop:20}}>{item.objectName} <Text style={{color:'#999',fontSize:14}}>{moment(Number(item.time)).format('YYYY-MM-DD HH:mm')}</Text></Text>
</View>
</TouchableOpacity>
)
}else if (item.objectType == 'AUDIO') {
return (
<TouchableOpacity onPress={()=>{this._toPage('Detail',item)}}>
<View style={{flex:1,backgroundColor:'#fff',padding:25,borderRadius:8}}>
<View style={{flexDirection:'row',alignItems:'center'}}>
<Image source={require('../img/sound.png')} style={{height:50,width:50}}></Image>
<Text style={{marginLeft:15}}></Text>
</View>
<Text style={{color:'#999',fontSize:12,marginTop:20}}>{item.objectName} <Text style={{color:'#999',fontSize:14}}>{moment(Number(item.time)).format('YYYY-MM-DD HH:mm')}</Text></Text>
</View>
</TouchableOpacity>
)
}else if (item.objectType == 'url') {
return (
<TouchableOpacity onPress={()=>{this._toPage('Detail',item)}}>
<View style={{flex:1,backgroundColor:'#fff',padding:25,borderRadius:8}}>
<View style={{flexDirection:'row',alignItems:'flex-start'}}>
<Image style={{backgroundColor:'yellow',height:50,width:50}}></Image>
<Text style={{marginLeft:15}}>此处显示文章标题</Text>
</View>
<Text style={{color:'#999',fontSize:12,marginTop:20}}>{item.objectName} <Text style={{color:'#999',fontSize:14}}>{moment(Number(item.time)).format('YYYY-MM-DD HH:mm')}</Text></Text>
</View>
</TouchableOpacity>
)
}
}
search = (text) =>{
let contain=[];
for (let i =0;i<this.state.allList.length;i++){
let aaa = this.state.allList[i].objectContent;
let bbb = aaa.indexOf(text);
if (bbb >-1 ){
contain.push(this.state.allList[i]);
}
}
this.setState({
dataSoure:contain
})
}
render() {
return (
<View style={styles.body}>
<View style={{width:"100%",height:50,flexDirection:'row',justifyContent:'flex-end',backgroundColor:'#efeff4'}}>
<View style={{flex:1,marginLeft:10,marginRight:10,justifyContent:'center',
marginBottom:9,marginTop:9,backgroundColor:'#ffffff',borderWidth:1,
borderColor:'#dddddd',borderRadius:4}}>
<TextInput placeholder={"搜索"}
returnKeyType="search"
onSubmitEditing={()=>this.search(this.state.search)}
onChangeText={(text)=>{
this.state.search=text
}}
underlineColorAndroid="transparent"
style={{flex:1,marginLeft:10,fontSize:12,padding:0}}></TextInput>
</View>
</View>
<FlatList
style={styles.list}
data={this.state.dataSoure}
renderItem={({item,i}) => this.rowRender(item,i)}
ItemSeparatorComponent={()=><View style={{height:10,backgroundColor:'#f0eff5'}}/>}
showsVerticalScrollIndicator={false}
/>
</View>
);
}
}
const styles = StyleSheet.create({
body:{
flex:1,
flexDirection:"column",
backgroundColor:"#f0eff5",
},
list:{
flex:1,
marginLeft:10,
marginRight:10,
marginBottom:10
},
item:{
flexDirection:"row",
alignItems:"center",
backgroundColor:"#fff",
borderBottomWidth:0.5,
borderBottomColor:"#ddd",
padding:8,
},
itemInfo:{
flex:1,
justifyContent:"center",
height:30,
},
itemInfoText:{
color:"#333",
fontSize:14,
},
link:{
width:10,
height:10,
borderTopWidth:0.5,
borderTopColor:"#666",
borderRightWidth:0.5,
borderRightColor:"#666",
transform:[
{rotate:'45deg'},
],
},
});