-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
214 lines (198 loc) · 5.94 KB
/
App.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import React, { useCallback } from 'react';
import {
Image,
ImageBackground,
Text,
View,
useWindowDimensions,
} from 'react-native';
import {
GestureHandlerRootView,
Gesture,
GestureDetector,
} from 'react-native-gesture-handler';
import Animated, {
Easing,
interpolate,
useAnimatedStyle,
useSharedValue,
withDelay,
withSpring,
withTiming,
} from 'react-native-reanimated';
import { FontAwesome } from '@expo/vector-icons';
import { PostActions } from './components/PostActions';
import { Header } from './components/Header';
const heartRotationDegress = [-35, -25, -15, 15, 25, 35];
const INITIAL_SCALE_VALUE = 0;
const INITIAL_ROTATE_VALUE = 0;
const INITIAL_TRANSLATE_Y_VALUE = 0;
const AnimatedImage = Animated.createAnimatedComponent(Image);
export default function InstagramPost(props) {
const { width: windowWidth, height: windowHeight } = useWindowDimensions();
const heartScale = useSharedValue(INITIAL_SCALE_VALUE);
const heartRotate = useSharedValue(INITIAL_ROTATE_VALUE);
const heartTranslateY = useSharedValue(INITIAL_TRANSLATE_Y_VALUE);
const tagIconOpacity = useSharedValue(0);
const tagOpacity = useSharedValue(0);
const heartStyles = useAnimatedStyle(() => ({
transform: [
{
scale: Math.max(heartScale.value, INITIAL_SCALE_VALUE), // added Math.max to avoid negative values when withSping(0) is called
},
{
rotate: `${heartRotate.value}deg`,
},
{
translateY: heartTranslateY.value,
},
],
}));
const tagIconStyles = useAnimatedStyle(() => ({
opacity: tagIconOpacity.value,
}));
const tagStyles = useAnimatedStyle(() => ({
opacity: tagOpacity.value,
transform: [
{
scale: interpolate(tagOpacity.value, [0, 1], [0.5, 1]),
},
],
}));
const onDoubelTapStart = useCallback(() => {
const randomHeartRotationDegress =
heartRotationDegress[
Math.floor(Math.random() * heartRotationDegress.length)
];
heartScale.value = withSpring(1.5, undefined, (isFinished) => {
if (isFinished) {
heartRotate.value = withTiming(
randomHeartRotationDegress,
undefined,
(isFinished) => {
if (isFinished) {
heartRotate.value = withTiming(INITIAL_ROTATE_VALUE);
}
}
);
heartTranslateY.value = withTiming(
-windowHeight / 2,
{
duration: 1250,
easing: Easing.inOut(Easing.cubic),
},
(isFinished) => {
if (isFinished) {
heartScale.value = INITIAL_SCALE_VALUE;
heartTranslateY.value = INITIAL_TRANSLATE_Y_VALUE;
}
}
);
}
});
}, []);
const onSingleTapStart = useCallback(() => {
tagIconOpacity.value = withTiming(1, undefined, (isFinished) => {
if (isFinished) {
tagIconOpacity.value = withDelay(1500, withTiming(0));
}
});
tagOpacity.value = withTiming(1, undefined, (isFinished) => {
if (isFinished) {
tagOpacity.value = withDelay(1500, withTiming(0));
}
});
}, []);
const singleTap = Gesture.Tap().maxDuration(250).onStart(onSingleTapStart);
const doubleTap = Gesture.Tap()
.maxDuration(250)
.numberOfTaps(2)
.onStart(onDoubelTapStart);
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<View
style={{
flex: 1,
justifyContent: 'center',
}}
>
<Header />
<GestureDetector gesture={Gesture.Exclusive(doubleTap, singleTap)}>
<ImageBackground
source={require('./assets/dogs.jpeg')}
style={{
width: windowWidth,
height: windowWidth,
backgroundColor: 'transparent',
}}
>
<AnimatedImage
source={require('./assets/heart.png')}
style={[
{
width: windowWidth,
height: windowWidth,
shadowOffset: { width: 0, height: 20 },
shadowOpacity: 0.35,
shadowRadius: 35,
backgroundColor: 'transparent',
},
heartStyles,
]}
resizeMode='center'
/>
<Animated.View
style={[
{ position: 'absolute', left: 10, bottom: 10 },
tagIconStyles,
]}
>
<FontAwesome name='user' size={24} color='black' />
</Animated.View>
<Animated.View>
<Animated.View
style={[
{
backgroundColor: 'rgba(0, 0, 0, 0.6)',
paddingHorizontal: 10,
paddingVertical: 6,
width: 'auto',
position: 'absolute',
left: 80,
bottom: 100,
borderRadius: 5,
},
tagStyles,
]}
>
<Text style={{ color: 'white', fontWeight: '700' }}>
hardikparasher
</Text>
</Animated.View>
<Animated.View
style={[
{
backgroundColor: 'rgba(0, 0, 0, 0.6)',
paddingHorizontal: 10,
paddingVertical: 6,
width: 'auto',
position: 'absolute',
left: 200,
bottom: 140,
borderRadius: 5,
},
tagStyles,
]}
>
<Text style={{ color: 'white', fontWeight: '700' }}>
toucheypheonix
</Text>
</Animated.View>
</Animated.View>
</ImageBackground>
</GestureDetector>
<PostActions />
</View>
</GestureHandlerRootView>
);
}