Detail.js
15.9 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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/**
* 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,
ProgressViewIOS,
ProgressBarAndroid
} from "react-native";
import { observable, useStrict, action } from 'mobx';
import { observer } from 'mobx-react';
import xnMainCss from "../css/css";
import {xnToast} from "../utils/utils";
import AppService from "../service/AppService";
import Orientation from 'react-native-orientation';
import * as size from "../utils/getSize";
import moment from "moment";
import Video from 'react-native-video'
var Sound = require('react-native-sound');
import ActionSheet from 'react-native-actionsheet'
export default class Detail extends Component {
static navigationOptions = ({ navigation, screenProps })=>({
title: '详情',
headerLeft:(<View style={{flexDirection: 'row',flex:1}}>
<TouchableOpacity style={{flexDirection: 'column',justifyContent: 'center',paddingRight:15,paddingLeft:10}} onPress={navigation.state.params?navigation.state.params._goBack:null}>
<Image style={{ width:16,height:16}} source={require('../img/back.png')} resizeMode="contain"/>
</TouchableOpacity>
<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/close.png')} resizeMode="contain"/>
</TouchableOpacity>
</View>),
headerRight:(<View style={{flexDirection: 'row',flex:1}}>
<TouchableOpacity style={{flexDirection: 'column',justifyContent: 'center',paddingRight:15,paddingLeft:15}} onPress={navigation.state.params?navigation.state.params._more:null}>
<Image style={{width:34,height:34}} source={require('../img/ddd.png')} resizeMode="contain"/>
</TouchableOpacity>
</View>)
});
constructor(props) {
super(props);
this.state = {
width: 90,
height: 200,
item:this.props.navigation.state.params.item,
progress:0.02,
isplay:false,
CANCEL_INDEX:0,
DESTRUCTIVE_INDEX:2,
options:[ '取消', '发送给朋友', '删除' ],
title:null,
category:'more'
};
if (this.state.item.objectType === 'IMAGE'){
this.state.CANCEL_INDEX = 0;
this.state.DESTRUCTIVE_INDEX = 2;
this.state.options = [ '取消', '发送给朋友', '删除' ];
this.state.title=null;
this.state.category = 'more';
}else if (this.state.item.objectType === 'TEXT') {
this.state.CANCEL_INDEX = 0;
this.state.DESTRUCTIVE_INDEX = 2;
this.state.options = [ '取消', '发送给朋友', '删除' ];
this.state.title=null;
this.state.category = 'more';
}else {
this.state.CANCEL_INDEX = 0;
this.state.DESTRUCTIVE_INDEX = 1;
this.state.options = [ '取消', '确定' ];
this.state.title='确认删除?';
this.state.category = 'delete';
}
if (this.state.item.objectType === 'AUDIO')
this.player = new Sound(this.state.item.objectContent, null, (error) => {
if (error) {
console.log('failed to load the sound', error);
return;
}
// loaded successfully
});
}
componentDidMount(){
let _this=this;
//设置头部
this.props.navigation.setParams({
_goBack:()=>{
this.props.navigation.goBack();
},
_close:()=>{
NativeModules.system.navTo("BACK")
},
_more:()=>{
if (this.state.item.objectType === 'IMAGE'){
this.setState({
CANCEL_INDEX:0,
DESTRUCTIVE_INDEX:2,
options:[ '取消', '发送给朋友', '删除' ],
title:null,
category:'more'
})
}else if (this.state.item.objectType === 'TEXT') {
this.setState({
CANCEL_INDEX:0,
DESTRUCTIVE_INDEX:2,
options:[ '取消', '发送给朋友', '删除' ],
title:null,
category:'more'
})
}else {
this.setState({
CANCEL_INDEX:0,
DESTRUCTIVE_INDEX:1,
options:[ '取消', '确定' ],
title:'确认删除?',
category:'delete'
})
}
this.ActionSheet.show();
}
});
};
componentWillUnmount() {
if(this.timer)
{
clearInterval(this.timer);
delete this.timer;
}
}
_toPage=(page)=>{
this.props.navigation.navigate(page)
};
onProgress = (event) =>{
console.log(event);
}
pause = () =>{
let that = this;
if (this.state.isplay){
this.player.pause();
if(this.timer)
{
clearInterval(this.timer);
delete this.timer;
}
}else {
this.player.play(function () {
if(that.timer)
{
clearInterval(that.timer);
delete that.timer;
}
that.setState({
isplay:!that.state.isplay,
progress:0.02
})
});
if(this.timer)
{
clearInterval(this.timer);
delete this.timer;
}
this.timer = setInterval(
() => { console.log('把一个定时器的引用挂在this上');
this.player.getCurrentTime((seconds) => {
let press = seconds/this.player.getDuration();
this.setState({
progress:press
})
});
},
250
);
}
this.setState({
isplay:!this.state.isplay
})
}
loadStart = (event) =>{
let height = (size.width-50) * event.naturalSize.height / event.naturalSize.width; //按照屏幕宽度进行等比缩放
this.setState({height:height});
console.log(event);
}
handlePress = (cate,i) =>{
if (cate === 'more'){
if (i === 0){
//取消
}else if (i === 1){
//发送消息
NativeModules.system.sendMessage(this.state.item.objectContent,this.state.item.objectType).then((result) => {} ).catch((error) => {
console.log(error)
});
}else if (i === 2){
this.setState({
CANCEL_INDEX:0,
DESTRUCTIVE_INDEX:1,
options:[ '取消', '确定' ],
title:'确认删除?',
category:'delete'
})
this.ActionSheet.show();
}
}else if (cate === 'delete'){
if (i === 0){
//取消
}else if (i === 1){
//确定删除
let vm={
id:this.state.item.id
};
AppService.deleteCollectios(vm).then(data=>{
if (data.errors == null || data.errors.length > 0) {
xnToast(data.errors[0].message);
return
}
this.props.navigation.state.params.callBack();
this.props.navigation.goBack();
})
}
}
}
_rowRender = (item) =>{
if (item.objectType == 'IMAGE') {
Image.getSize(item.objectContent, (width, height) => {
height = (size.width-30) * height / width; //按照屏幕宽度进行等比缩放
this.setState({width:size.width, height:height});
});
return (
<View style={{flex:1,backgroundColor:'#fff',padding:25,borderRadius:8}}>
<TouchableOpacity>
<Image source={{uri:item.objectContent}}
style={{backgroundColor:'#fff', height: this.state.height}}></Image>
</TouchableOpacity>
<Text style={{color:'#999',fontSize:14,marginTop:20}}>收藏于{moment(Number(item.time)).format('YYYY-MM-DD HH:mm')}</Text>
</View>
)
}else if (item.objectType == 'VIDEO') {
return (
<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={true} // true代表静音,默认为false.
paused={false} // true代表暂停,默认为false
resizeMode="contain" // 视频的自适应伸缩铺放行为,
repeat={true} // 是否重复播放
onLoad={this.loadStart} // 当视频的回调函数
playInBackground={true} // 当app转到后台运行的时候,播放是否暂停
playWhenInactive={false} // [iOS] Video continues to play when control or notification center are shown. 仅适用于IOS
onProgress={this.setTime} // 进度控制,每250ms调用一次,以获取视频播放的进度
style={{backgroundColor:'#fff',flex:1,height:this.state.height}} />
<Text style={{color:'#999',fontSize:14,marginTop:20}}>收藏于{moment(Number(item.time)).format('YYYY-MM-DD HH:mm')}</Text>
</View>
)
}else if (item.objectType == 'TEXT') {
return (
<View style={{flex:1,backgroundColor:'#fff',padding:25,borderRadius:8}}>
<Text style={{fontSize:16,color:'#333'}}>{item.objectContent}</Text>
<Text style={{color:'#999',fontSize:14,marginTop:20}}>收藏于{moment(Number(item.time)).format('YYYY-MM-DD HH:mm')}</Text>
</View>
)
}else if (item.objectType == 'AUDIO') {
if (Platform.OS === 'ios'){
return (
<View style={{flex:1,backgroundColor:'#fff',padding:25}}>
<View style={{borderWidth:0.5,borderColor:'#999',flexDirection:'row',alignItems:'center'}}>
<TouchableOpacity style={{height:50,width:50,justifyContent:'center',alignItems:'center'}} onPress={()=>this.pause()}>
<Image source={this.state.isplay?require('../img/pause.png'):require('../img/play.png')} style={{height:35,width:35}}></Image>
</TouchableOpacity>
{/*<Text style={{marginLeft:15}}>00:03</Text>*/}
<ProgressViewIOS style={{marginLeft:10,marginRight:10,flex:1}} progress={this.state.progress}/>
</View>
<Text style={{color:'#999',fontSize:14,marginTop:20}}>收藏于{moment(Number(item.time)).format('YYYY-MM-DD HH:mm')}</Text>
</View>
)
}else {
return (
<View style={{flex:1,backgroundColor:'#fff',padding:25}}>
<View style={{borderWidth:0.5,borderColor:'#999',flexDirection:'row',alignItems:'center'}}>
<TouchableOpacity onPress={()=>this.pause()}>
<Image source={this.state.isplay?require('../img/pause.png'):require('../img/play.png')} style={{height:50,width:50}}></Image>
</TouchableOpacity>
{/*<Text style={{marginLeft:15}}>00:03</Text>*/}
<ProgressBarAndroid style={{marginLeft:10,marginRight:10,flex:1}} styleAttr="Horizontal" progress={this.state.progress}/>
</View>
<Text style={{color:'#999',fontSize:14,marginTop:20}}>收藏于{moment(Number(item.time)).format('YYYY-MM-DD HH:mm')}</Text>
</View>
)
}
}else if (item.objectType == 'url') {
return (
<TouchableOpacity >
<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:14,marginTop:20}}>收藏于{moment(Number(item.time)).format('YYYY-MM-DD HH:mm')}</Text>
</View>
</TouchableOpacity>
)
}
}
render() {
return (
<View style={xnMainCss.body}>
<ScrollView style={{backgroundColor:'#fff'}}>
<View style={{flexDirection:'row',flex:1,padding:15}}>
{/*<Image style={{backgroundColor:'red',width:44,height:44,borderRadius:4,marginRight:15}}></Image>*/}
{/*<View style={{width:15}}></View>*/}
<Text style={{flex:1,fontSize:17,fontWeight:'500'}}>{this.state.item.sourceName} - {this.state.item.objectName}</Text>
</View>
<View style={{backgroundColor:'#999',height:0.5,marginLeft:15,marginRight:15}}></View>
{/*<View style={{flexDirection:'row',padding:15,alignItems:'center'}}>*/}
{/*<Image style={{width:15,height:15,backgroundColor:'red'}}></Image>*/}
{/*<Text style={{marginLeft:10,fontSize:14}}>添加标签</Text>*/}
{/*</View>*/}
{/*<View style={{backgroundColor:'#999',height:0.5,marginLeft:15,marginRight:15}}></View>*/}
{this._rowRender(this.state.item)}
</ScrollView>
<ActionSheet
ref={o => this.ActionSheet = o}
title={this.state.title}
options={this.state.options}
cancelButtonIndex={this.state.CANCEL_INDEX}
destructiveButtonIndex={this.state.DESTRUCTIVE_INDEX}
onPress={(i)=>this.handlePress(this.state.category,i)}
/>
</View>
);
}
}
const styles = StyleSheet.create({
body:{
flex:1,
flexDirection:"column",
backgroundColor:"#f0eff5",
},
line:{
height:40,
padding:10
},
});