$ git show press-scale
Press scale
Shrink a button slightly while pressed, spring back on release.
// Reanimated 4: a CSS transition reacts to the pressed state
const [pressed, setPressed] = useState(false);
return (
<Pressable onPressIn={() => setPressed(true)} onPressOut={() => setPressed(false)}>
<Animated.View
style={[styles.button, {
transform: [{ scale: pressed ? 0.92 : 1 }],
transitionProperty: 'transform',
transitionDuration: '120ms',
transitionTimingFunction: 'ease-out',
}]}
/>
</Pressable>
);
// Need a spring feel or no re-render per press? Use the worklet version from the v3 tab; it runs on v4 too.