-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPowerPerson.js
117 lines (109 loc) · 2.7 KB
/
PowerPerson.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
import React, {useEffect} from 'react';
import {Image, View, StyleSheet} from 'react-native';
import Animated, {
useSharedValue,
useAnimatedStyle,
withTiming,
withSequence,
withDelay,
} from 'react-native-reanimated';
const PowerPerson = ({image, isHappy, isSad}) => {
const heartAnimation = useSharedValue(0);
const cloudAnimation = useSharedValue(0);
const personSize = useSharedValue(1);
useEffect(() => {
if (isHappy) {
heartAnimation.value = withSequence(
withTiming(1),
withDelay(700, withTiming(0)),
);
personSize.value = withSequence(
withTiming(1.1),
withDelay(700, withTiming(1)),
);
}
if (isSad) {
cloudAnimation.value = withSequence(
withTiming(1),
withDelay(700, withTiming(0)),
);
personSize.value = withSequence(
withTiming(0.9),
withDelay(700, withTiming(1)),
);
}
}, [cloudAnimation, heartAnimation, isSad, isHappy, personSize]);
const animatedHeart = useAnimatedStyle(() => {
return {
opacity: heartAnimation.value,
transform: [{translateY: 20 - heartAnimation.value * 20}],
};
});
const animatedCloud = useAnimatedStyle(() => {
return {
opacity: cloudAnimation.value,
transform: [{translateY: 20 - cloudAnimation.value * 20}],
};
});
const personScale = useAnimatedStyle(() => {
return {
transform: [
{translateY: (personSize.value - 1) * -50},
{scale: personSize.value},
],
};
});
return (
<>
<View style={styles.wrapper}>
<Animated.View style={[animatedHeart, styles.heartWrapper]}>
<Image
source={{
uri: 'https://image.flaticon.com/icons/png/512/3208/3208700.png',
}}
style={styles.heartImage}
/>
</Animated.View>
<Animated.View style={[animatedCloud, styles.cloudWrapper]}>
<Image
source={{
uri: 'https://image.flaticon.com/icons/png/512/1146/1146860.png',
}}
style={styles.cloudImage}
/>
</Animated.View>
<Animated.View style={personScale}>
<Image source={{uri: image}} style={styles.personImage} />
</Animated.View>
</View>
</>
);
};
const styles = StyleSheet.create({
wrapper: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center',
},
personImage: {
height: 95,
width: 95,
},
heartImage: {
height: 55,
width: 55,
},
heartWrapper: {
position: 'absolute',
bottom: 105,
},
cloudImage: {
height: 65,
width: 65,
},
cloudWrapper: {
position: 'absolute',
bottom: 95,
},
});
export default PowerPerson;