$ git show jelly-scroll
Jelly scroll
List rows skew with scroll velocity and settle back with a spring, giving a wobbly feel.
Inspired by Jelly scrollFrom 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 velocity = useSharedValue(0), lastY = useSharedValue(0), lastT = useSharedValue(0);
const onScroll = useAnimatedScrollHandler({
onScroll: e => {
const now = Date.now(); // e.velocity is iOS only, so compute it
velocity.value = (e.contentOffset.y - lastY.value) / Math.max(1, now - lastT.value);
lastY.value = e.contentOffset.y; lastT.value = now;
},
onMomentumEnd: () => { velocity.value = 0; },
});
const skew = useDerivedValue(() => withSpring(clamp(velocity.value * 6, -12, 12), { damping: 8 }));
const row = useAnimatedStyle(() => ({ transform: [{ skewY: skew.value + 'deg' }] }));
// apply row style to every item (or to the content container)