-
Notifications
You must be signed in to change notification settings - Fork 0
/
StoryThumbnail.tsx
57 lines (52 loc) · 1.47 KB
/
StoryThumbnail.tsx
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
import React, { useState } from 'react'
import { useFocusEffect, useNavigation } from '@react-navigation/native'
import { StackNavigationProp } from '@react-navigation/stack'
import { Dimensions, Image, Pressable, StyleSheet, View } from 'react-native'
import { Story } from './Model'
import { SharedElement } from 'react-navigation-shared-element'
interface StoryThumbnailProps {
story: Story
}
const margin = 16;
const borderRadius = 5;
const width = Dimensions.get("window").width / 2 - margin * 2;
const StoryThumbnail = ({ story }: StoryThumbnailProps) => {
const [opacity, setOpacity] = useState(1)
const navigation = useNavigation<StackNavigationProp<any, any>>()
useFocusEffect(() => {
if (navigation.isFocused()) {
setOpacity(1)
}
})
return (
<Pressable
style={({ pressed }) => ({ opacity: pressed ? 0.5 : 1 })}
onPress={() => {
setOpacity(0)
navigation.navigate('Story', { story })
}}
>
<SharedElement id={story.id} style={{ flex: 1 }}>
<View style={[styles.container, { opacity }]}>
<Image source={story.source} style={styles.image} />
</View>
</SharedElement>
</Pressable>
)
}
const styles = StyleSheet.create({
container: {
width,
height: width * 1.77,
marginTop: 16,
borderRadius,
},
image: {
...StyleSheet.absoluteFillObject,
width: undefined,
height: undefined,
resizeMode: "cover",
borderRadius,
},
})
export default StoryThumbnail