-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prize.js
140 lines (128 loc) · 3.11 KB
/
Prize.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
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
import React from "react";
import {
Dimensions,
Image,
StyleSheet,
Text,
TouchableOpacity,
View,
} from "react-native";
import GestureRecognizer, {
swipeDirections,
} from "react-native-swipe-gestures";
// will prioritize prizes if there are any
// otherwise will draw from random
// viewed prizes will be deleted from local storage on close
export default function Prize({
aww,
isPrize,
onClose,
ShareBtn,
NextBtn,
videoRef,
}) {
const [isLoading, setLoading] = React.useState(false);
const config = {
velocityThreshold: 0.3,
directionalOffsetThreshold: 60,
};
const handleSwipe = (gestureName) => {
const { SWIPE_RIGHT, SWIPE_DOWN } = swipeDirections;
switch (gestureName) {
case SWIPE_RIGHT:
case SWIPE_DOWN:
onClose(isPrize, aww.id);
}
};
const maybeImage = getImageUrlIfExists(aww);
return (
<GestureRecognizer
config={config}
onSwipe={(direction) => handleSwipe(direction)}
style={{ flex: 1 }}
>
<View style={styles.container}>
{isLoading && (
<Text
style={{ fontSize: 28, textAlign: "center", paddingBottom: 15 }}
>
🎁incoming!
</Text>
)}
{maybeImage ? (
<>
<Image
resizeMode="contain"
source={{
uri: maybeImage,
}}
style={{
width: Dimensions.get("window").width * 0.8,
height: Dimensions.get("window").height * 0.45,
}}
/>
</>
) : (
<TouchableOpacity
onPress={() => {
videoRef.presentFullscreenPlayer();
videoRef.playAsync();
}}
>
<Image
resizeMode="contain"
source={{
uri: aww.thumbnail,
}}
style={{
width: Dimensions.get("window").width * 0.8,
height: Dimensions.get("window").height * 0.45,
}}
/>
<Image
resizeMode="contain"
source={require("./assets/play.png")}
style={{
position: "absolute",
left: "30%",
top: "30%",
width: 100,
height: 100,
}}
/>
</TouchableOpacity>
)}
<Text style={{ padding: 12 }}>{aww.title}</Text>
<NextBtn isPrize={isPrize} prizeId={aww.id} />
<ShareBtn />
</View>
</GestureRecognizer>
);
}
function getImageUrlIfExists(aww) {
if (aww.url.endsWith(".jpg")) {
return aww.url;
}
if (aww?.secure_media?.oembed) {
return aww.secure_media.oembed.thumbnail_url;
}
return null;
}
const styles = StyleSheet.create({
button: {
backgroundColor: "#679b9b",
borderRadius: 10,
padding: 12,
margin: 12,
},
container: {
alignItems: "center",
justifyContent: "center",
backgroundColor: "#ffb6b6",
flex: 1,
paddingVertical: 60,
},
overlay: {
backgroundColor: "rgba(255,85,117,0.95)",
},
});