$ git show toggle-switch
Toggle switch
Custom switch: the thumb springs across and the track changes color.
import Animated, { cubicBezier } from 'react-native-reanimated';
<Pressable onPress={() => setOn(v => !v)} accessibilityRole="switch" accessibilityState={{ checked: on }}>
<Animated.View
style={[styles.track, {
backgroundColor: on ? '#0B7A93' : '#D8E0E4',
transitionProperty: 'backgroundColor',
transitionDuration: '200ms',
}]}>
<Animated.View
style={[styles.thumb, {
transform: [{ translateX: on ? 26 : 0 }],
transitionProperty: 'transform',
transitionDuration: '250ms',
transitionTimingFunction: cubicBezier(0.3, 1.4, 0.5, 1),
}]}
/>
</Animated.View>
</Pressable>