improve shrink logic
This commit is contained in:
@@ -28,27 +28,32 @@ export const GrowWrapper = function GrowWrapper({
|
|||||||
transform: [{scale: scale.value}],
|
transform: [{scale: scale.value}],
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const onTouchStart = React.useCallback(() => {
|
const shrink = useCallback(() => {
|
||||||
|
'worklet'
|
||||||
|
cancelAnimation(scale)
|
||||||
|
scale.value = withTiming(1, {duration: 200}, () => {
|
||||||
|
animationDidComplete.value = false
|
||||||
|
})
|
||||||
|
}, [animationDidComplete, scale])
|
||||||
|
|
||||||
|
const grow = React.useCallback(() => {
|
||||||
|
'worklet'
|
||||||
scale.value = withTiming(1.05, {duration: 750}, finished => {
|
scale.value = withTiming(1.05, {duration: 750}, finished => {
|
||||||
if (!finished) return
|
if (!finished) return
|
||||||
animationDidComplete.value = true
|
animationDidComplete.value = true
|
||||||
runOnJS(playHaptic)()
|
runOnJS(playHaptic)()
|
||||||
runOnJS(onOpenMenu)()
|
runOnJS(onOpenMenu)()
|
||||||
})
|
|
||||||
}, [scale, animationDidComplete, playHaptic, onOpenMenu])
|
|
||||||
|
|
||||||
const onTouchEnd = useCallback(() => {
|
shrink()
|
||||||
cancelAnimation(scale)
|
})
|
||||||
animationDidComplete.value = false
|
}, [scale, animationDidComplete, playHaptic, onOpenMenu, shrink])
|
||||||
scale.value = withTiming(1, {duration: 200})
|
|
||||||
}, [animationDidComplete, scale])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AnimatedPressable
|
<AnimatedPressable
|
||||||
style={animatedStyle}
|
style={animatedStyle}
|
||||||
unstable_pressDelay={300}
|
unstable_pressDelay={300}
|
||||||
onPressIn={onTouchStart}
|
onPressIn={grow}
|
||||||
onTouchEnd={onTouchEnd}>
|
onTouchEnd={shrink}>
|
||||||
{children}
|
{children}
|
||||||
</AnimatedPressable>
|
</AnimatedPressable>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user