$ git show range-slider
Range slider
Two thumbs pick a minimum and maximum; each one stops at the other and the fill stretches between them.
import { scheduleOnRN } from 'react-native-worklets';
// Gesture-driven, so Reanimated 4 keeps shared values; scheduleOnRN replaces runOnJS
const W = 280, THUMB = 24, MIN_GAP = THUMB;
const lo = useSharedValue(0.2 * W), hi = useSharedValue(0.8 * W);
const report = (a, b) => onChange(Math.round((a / W) * max), Math.round((b / W) * max));
const thumbPan = (self, isLow) => Gesture.Pan()
.hitSlop(12)
.onChange((e) => {
const next = self.value + e.changeX;
self.value = isLow
? Math.min(Math.max(next, 0), hi.value - MIN_GAP)
: Math.max(Math.min(next, W), lo.value + MIN_GAP);
})
.onEnd(() => scheduleOnRN(report, lo.value, hi.value));
const lowPan = thumbPan(lo, true);
const highPan = thumbPan(hi, false);
const fill = useAnimatedStyle(() => ({ left: lo.value, width: hi.value - lo.value }));
const lowStyle = useAnimatedStyle(() => ({ transform: [{ translateX: lo.value - THUMB / 2 }] }));
const highStyle = useAnimatedStyle(() => ({ transform: [{ translateX: hi.value - THUMB / 2 }] }));
<View style={{ width: W, height: THUMB }}>
<View style={styles.track} />
<Animated.View style={[styles.fill, fill]} />
<GestureDetector gesture={lowPan}><Animated.View style={[styles.thumb, lowStyle]} /></GestureDetector>
<GestureDetector gesture={highPan}><Animated.View style={[styles.thumb, highStyle]} /></GestureDetector>
</View>