Skip to content

Commit 0bb76ef

Browse files
authored
chore: refactor ArtworkSaveIconWrapper (#12846)
* chore: refactor ArtworkSaveIconWrapper * chore: decrease mass
1 parent eef7e42 commit 0bb76ef

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/app/Components/ArtworkGrids/ArtworkSaveIconWrapper.tsx

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,54 @@
11
import { HeartFillIcon, HeartStrokeIcon } from "@artsy/icons/native"
22
import { HEART_ICON_SIZE } from "app/Components/constants"
33
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"
115

126
export const ArtworkSaveIconWrapper: React.FC<{
137
isSaved: boolean
148
testID?: string
159
accessibilityLabel?: string
1610
fill?: string
1711
}> = ({ isSaved, testID, accessibilityLabel, fill }) => {
18-
const scaleAnimation = useSharedValue(1)
12+
const scaleAnimation = useAnimatedValue(1)
1913
const didMount = useRef(false)
2014

21-
const animatedStyles = useAnimatedStyle(() => ({
22-
transform: [{ scale: scaleAnimation.value }],
23-
}))
24-
2515
useEffect(() => {
2616
if (!didMount.current) {
2717
didMount.current = true
2818
return
2919
}
3020

3121
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,
3526
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,
3738
}),
38-
withTiming(1.1, { duration: 300 }),
39-
withTiming(1, { duration: 200 })
40-
)
39+
]).start()
4140
} else {
4241
// We don't want to animation the dislike
43-
scaleAnimation.value = 1
42+
scaleAnimation.setValue(1)
4443
}
4544
}, [isSaved, scaleAnimation])
4645

4746
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+
>
4952
{!!isSaved ? (
5053
<HeartFillIcon
5154
height={HEART_ICON_SIZE}

0 commit comments

Comments
 (0)