$ git show checkbox
Animated checkbox
The box fills with color, gives a small bounce, and the check mark draws itself in.
Remember me
// Reanimated 4: a CSS transition handles the box colors; the check still draws via animated props
import Svg, { Path } from 'react-native-svg';
const AnimatedPath = Animated.createAnimatedComponent(Path);
const CHECK = 22;
const p = useSharedValue(checked ? 1 : 0);
useEffect(() => {
p.value = withTiming(checked ? 1 : 0, { duration: 220 });
}, [checked]);
const mark = useAnimatedProps(() => ({ strokeDashoffset: CHECK * (1 - p.value) }));
<Pressable onPress={() => setChecked((v) => !v)} accessibilityRole="checkbox" accessibilityState={{ checked }}>
<Animated.View style={[styles.box, {
backgroundColor: checked ? '#2F54EB' : 'transparent',
borderColor: checked ? '#2F54EB' : '#C9CED6',
transform: [{ scale: checked ? 1 : 0.96 }],
transitionProperty: ['backgroundColor', 'borderColor', 'transform'],
transitionDuration: '220ms',
transitionTimingFunction: cubicBezier(0.3, 1.6, 0.5, 1), // overshoot = the bounce
}]}>
<Svg width={16} height={16} viewBox="0 0 24 24">
<AnimatedPath d="M5 12.5l4.5 4.5L19 7.5" stroke="white" strokeWidth={3.5} fill="none"
strokeLinecap="round" strokeLinejoin="round" strokeDasharray={CHECK} animatedProps={mark} />
</Svg>
</Animated.View>
</Pressable>