|
1 | 1 | import { HeartFillIcon, HeartStrokeIcon } from "@artsy/icons/native" |
2 | 2 | import { HEART_ICON_SIZE } from "app/Components/constants" |
3 | 3 | import { useEffect, useRef } from "react" |
4 | | -import Animated, { |
5 | | - useAnimatedStyle, |
6 | | - useSharedValue, |
7 | | - withSequence, |
8 | | - withSpring, |
9 | | - withTiming, |
10 | | -} from "react-native-reanimated" |
| 4 | +import { Animated, useAnimatedValue } from "react-native" |
11 | 5 |
|
12 | 6 | export const ArtworkSaveIconWrapper: React.FC<{ |
13 | 7 | isSaved: boolean |
14 | 8 | testID?: string |
15 | 9 | accessibilityLabel?: string |
16 | 10 | fill?: string |
17 | 11 | }> = ({ isSaved, testID, accessibilityLabel, fill }) => { |
18 | | - const scaleAnimation = useSharedValue(1) |
| 12 | + const scaleAnimation = useAnimatedValue(1) |
19 | 13 | const didMount = useRef(false) |
20 | 14 |
|
21 | | - const animatedStyles = useAnimatedStyle(() => ({ |
22 | | - transform: [{ scale: scaleAnimation.value }], |
23 | | - })) |
24 | | - |
25 | 15 | useEffect(() => { |
26 | 16 | if (!didMount.current) { |
27 | 17 | didMount.current = true |
28 | 18 | return |
29 | 19 | } |
30 | 20 |
|
31 | 21 | if (isSaved) { |
32 | | - scaleAnimation.value = withSequence( |
33 | | - withSpring(isSaved ? 0.7 : 1, { |
34 | | - mass: 1, |
| 22 | + Animated.sequence([ |
| 23 | + Animated.spring(scaleAnimation, { |
| 24 | + toValue: 0.7, |
| 25 | + mass: 0.01, |
35 | 26 | stiffness: 300, |
36 | | - damping: 20, |
| 27 | + useNativeDriver: true, |
| 28 | + }), |
| 29 | + Animated.timing(scaleAnimation, { |
| 30 | + toValue: 1.1, |
| 31 | + duration: 300, |
| 32 | + useNativeDriver: true, |
| 33 | + }), |
| 34 | + Animated.timing(scaleAnimation, { |
| 35 | + toValue: 1, |
| 36 | + duration: 200, |
| 37 | + useNativeDriver: true, |
37 | 38 | }), |
38 | | - withTiming(1.1, { duration: 300 }), |
39 | | - withTiming(1, { duration: 200 }) |
40 | | - ) |
| 39 | + ]).start() |
41 | 40 | } else { |
42 | 41 | // We don't want to animation the dislike |
43 | | - scaleAnimation.value = 1 |
| 42 | + scaleAnimation.setValue(1) |
44 | 43 | } |
45 | 44 | }, [isSaved, scaleAnimation]) |
46 | 45 |
|
47 | 46 | return ( |
48 | | - <Animated.View style={animatedStyles} testID={testID} accessibilityLabel={accessibilityLabel}> |
| 47 | + <Animated.View |
| 48 | + style={{ transform: [{ scale: scaleAnimation }] }} |
| 49 | + testID={testID} |
| 50 | + accessibilityLabel={accessibilityLabel} |
| 51 | + > |
49 | 52 | {!!isSaved ? ( |
50 | 53 | <HeartFillIcon |
51 | 54 | height={HEART_ICON_SIZE} |
|
0 commit comments