$ git show segmented-control
Segmented control
A raised thumb slides behind the selected option with a little overshoot, like the iOS control.
DayWeekMonth
// Reanimated 4: the thumb's left is a percentage and a CSS transition slides it, no measuring
const OPTIONS = ['Day', 'Week', 'Month'];
const [selected, setSelected] = useState(0);
<View style={styles.track}> {/* flexDirection 'row', padding 3, borderRadius 10, light gray */}
{/* Absolute box inset by the padding, so percentages are of the inner width */}
<View pointerEvents="none" style={styles.thumbArea}>
<Animated.View style={[styles.thumb, {
width: 100 / OPTIONS.length + '%',
left: (selected * 100) / OPTIONS.length + '%',
transitionProperty: 'left',
transitionDuration: '320ms',
transitionTimingFunction: cubicBezier(0.3, 1.4, 0.5, 1), // slight overshoot
}]} />
</View>
{OPTIONS.map((label, i) => (
<Pressable key={label} style={styles.segment} onPress={() => setSelected(i)}>
<Text style={[styles.label, selected === i && styles.labelActive]}>{label}</Text>
</Pressable>
))}
</View>