forked from bradoyler/newswatch-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideoRow.js
More file actions
97 lines (90 loc) · 2.72 KB
/
VideoRow.js
File metadata and controls
97 lines (90 loc) · 2.72 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
'use strict';
var moment = require('moment');
var React = require('react-native');
var {
Image,
PixelRatio,
StyleSheet,
Text,
TouchableHighlight,
View
} = React;
var getImageSource = require('./getImageSource');
var VideoRow = React.createClass({
render: function() {
var viewCount = this.props.video.stats.viewCount;
var pubDate = moment(this.props.video.publishedAt).fromNow(true);
var channelTitle = this.props.video.channelTitle;
var title = this.props.video.title;
var thumbnail = {uri:this.props.video.thumbnails.default.url};
var defaultImg = require('image!story-background');
return (
<View>
<TouchableHighlight onPress={this.props.onSelect}>
<View style={styles.row}>
<DelayedImage
defaultSource={defaultImg}
source={thumbnail}
style={styles.cellImage}
/>
<View style={styles.textContainer}>
<Text style={styles.title} numberOfLines={2}>{title}</Text>
<Text style={styles.channel} numberOfLines={1}>
{channelTitle} {' '} •{' '} {pubDate} •{' '} {viewCount} views
</Text>
</View>
</View>
</TouchableHighlight>
<View style={styles.cellBorder} />
</View>
);
}
});
var DelayedImage = React.createClass({
propTypes: Image.propTypes,
getInitialState(): { showImage: boolean } {
return { showImage: true };
},
componentWillReceiveProps: function(nextProps: any) {
if(this.props.source.uri != nextProps.source.uri) {
this.setState({ showImage: false });
setTimeout(() => this.setState({ showImage: true }), 0);
}
},
render: function(): React.Component {
return <Image {...this.props} source={{uri: this.state.showImage ? this.props.source.uri : null}} />
},
});
var styles = StyleSheet.create({
textContainer: {
flex: 1,
},
title: {
flex: 1,
fontSize: 16,
fontWeight: '500',
marginBottom: 2,
},
channel: {
color: '#999999',
fontSize: 12,
},
row: {
alignItems: 'center',
backgroundColor: 'white',
flexDirection: 'row',
padding: 5,
},
cellImage: {
backgroundColor: '#dddddd',
height: 65,
marginRight: 10,
width: 60,
},
cellBorder: {
backgroundColor: 'rgba(0, 0, 0, 0.1)',
height: 1,
marginLeft: 4,
},
});
module.exports = VideoRow;