-
Notifications
You must be signed in to change notification settings - Fork 33
/
component.js
101 lines (92 loc) 路 2.71 KB
/
component.js
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
import * as React from 'react';
import { Text, TouchableOpacity, View, ViewPropTypes, ActivityIndicator } from 'react-native';
import { PropTypes } from 'prop-types';
import { ProgressBar } from 'kitsu/components/ProgressBar';
import { ProgressiveImage } from 'kitsu/components/ProgressiveImage';
import { Rating } from 'kitsu/components/Rating';
import { Navigation } from 'react-native-navigation';
import { Screens } from 'kitsu/navigation';
import { styles } from './styles';
export const MediaCard = ({
caption,
cardDimensions,
cardStyle,
mediaData,
componentId,
progress,
ratingTwenty,
ratingSystem,
style,
loading,
}) => {
const onPress = () => {
if (componentId && mediaData && mediaData.id && mediaData.type) {
Navigation.push(componentId, {
component: {
name: Screens.MEDIA_PAGE,
passProps: {
mediaId: mediaData.id,
mediaType: mediaData.type,
},
},
});
}
};
return (
<TouchableOpacity onPress={onPress} disabled={loading}>
<View style={[styles.posterImageContainer, { width: cardDimensions.width }, style]}>
{mediaData && mediaData.posterImage ? (
<ProgressiveImage
duration={500}
source={{ uri: mediaData.posterImage.small }}
style={[styles.posterImageCard, cardDimensions, cardStyle]}
/>
) : (
<View style={[styles.posterImageCard, cardDimensions, cardStyle]} />
)}
{caption.length > 0 && <Text style={styles.captionText}>{caption}</Text>}
{progress > 0 && (
<ProgressBar fillPercentage={progress} height={3} style={styles.progressBar} />
)}
{typeof ratingTwenty !== 'undefined' && (
<Rating
disabled
ratingTwenty={ratingTwenty}
ratingSystem={ratingSystem}
size="tiny"
viewType="single"
showNotRated={false}
style={styles.rating}
/>
)}
{loading &&
<View style={styles.loading}>
<ActivityIndicator color={'rgba(255,255,255,0.6)'} />
</View>
}
</View>
</TouchableOpacity>
);
};
MediaCard.propTypes = {
caption: PropTypes.string,
cardDimensions: PropTypes.object.isRequired,
cardStyle: ViewPropTypes.style,
mediaData: PropTypes.object.isRequired,
componentId: PropTypes.any,
progress: PropTypes.number,
ratingTwenty: PropTypes.number,
ratingSystem: PropTypes.string,
style: ViewPropTypes.style,
loading: PropTypes.bool,
};
MediaCard.defaultProps = {
caption: '',
cardStyle: null,
progress: 0,
ratingTwenty: undefined,
ratingSystem: 'simple',
style: null,
loading: false,
componentId: null,
};