$ git show picker-wheel
3D picker wheel
A scrolling list that curves away in 3D like the iOS date picker, snapping to each row.
Inspired by iOS pickerFrom William Candillon’s “Can it be done in React Native?” series. The code here is a simplified rewrite for Reanimated 4 and 3.
This snippet uses APIs that didn’t change between versions, so the same code runs on Reanimated 4 and 3.
const ITEM = 40;
const y = useSharedValue(0);
const onScroll = useAnimatedScrollHandler(e => { y.value = e.contentOffset.y; });
function Item({ index, label }) {
const style = useAnimatedStyle(() => {
const d = (index * ITEM - y.value) / ITEM; // rows away from the center
return {
opacity: interpolate(Math.abs(d), [0, 2.5], [1, 0.2], Extrapolation.CLAMP),
transform: [
{ perspective: 600 },
{ rotateX: clamp(d * -25, -80, 80) + 'deg' },
{ scale: interpolate(Math.abs(d), [0, 2.5], [1, 0.85], Extrapolation.CLAMP) },
],
};
});
return <Animated.Text style={[styles.item, { height: ITEM }, style]}>{label}</Animated.Text>;
}
<Animated.ScrollView style={{ height: ITEM * 5 }} snapToInterval={ITEM} decelerationRate="fast"
contentContainerStyle={{ paddingVertical: ITEM * 2 }} onScroll={onScroll} scrollEventThrottle={16}
showsVerticalScrollIndicator={false}>{items.map((l, i) => <Item key={l} index={i} label={l} />)}</Animated.ScrollView>