-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMediaContentPoster.tsx
More file actions
100 lines (90 loc) · 2.32 KB
/
Copy pathMediaContentPoster.tsx
File metadata and controls
100 lines (90 loc) · 2.32 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
import React, { useState, useRef, useCallback } from 'react';
import { StyleSheet, Animated, ActivityIndicator, Platform } from 'react-native';
import { View } from './Themed';
interface MediaContentPosterProps {
background: string;
isPortrait: boolean;
}
const MediaContentPoster: React.FC<MediaContentPosterProps> = ({ background, isPortrait }) => {
const [isLoading, setIsLoading] = useState(true);
const fadeAnim = useRef(new Animated.Value(0)).current;
const startAnimations = useCallback(() => {
setIsLoading(false);
Animated.timing(fadeAnim, {
toValue: 1,
duration: 500,
useNativeDriver: true,
}).start();
}, [fadeAnim]);
const containerStyle = [
styles.posterContainer,
{ aspectRatio: isPortrait ? 1 / 1 : 16 / 9 }
];
const posterStyle = [
styles.poster,
{
opacity: fadeAnim,
borderRadius: isPortrait ? 0 : 10,
}
];
const shadowContainerStyle = [
styles.shadowContainer,
{
borderRadius: isPortrait ? 0 : 10,
// Platform-specific shadows
...Platform.select({
ios: {
shadowColor: '#000',
shadowOffset: { width: 0, height: 8 },
shadowOpacity: 0.44,
shadowRadius: 10.32,
},
android: {
elevation: 16,
},
}),
}
];
return (
<View style={containerStyle}>
<Animated.View style={shadowContainerStyle}>
{isLoading && (
<Animated.View style={styles.loaderContainer}>
<ActivityIndicator color="#535aff" />
</Animated.View>
)}
<Animated.Image
resizeMode={isPortrait ? 'cover' : 'contain'}
source={{ uri: background }}
style={posterStyle}
onLoad={startAnimations}
/>
</Animated.View>
</View>
);
};
const styles = StyleSheet.create({
posterContainer: {
position: 'relative',
width: '100%',
overflow: 'hidden',
alignItems: 'center',
justifyContent: 'center',
},
shadowContainer: {
width: '100%',
height: '100%',
backgroundColor: 'transparent',
},
poster: {
width: '100%',
height: '100%',
},
loaderContainer: {
...StyleSheet.absoluteFillObject,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'rgba(0,0,0,0.2)',
},
});
export default MediaContentPoster;