$ git show parallax-header

Collapsing header

Advanced/anim parallax-header

Header shrinks and its image moves slower than the list as you scroll.

Main · New Architecture only · worklets live in react-native-worklets

This snippet uses APIs that didn’t change between versions, so the same code runs on Reanimated 4 and 3.

useAnimatedScrollHandlerinterpolateExtrapolation
parallax-header.tsx · reanimated 4
const scrollY = useSharedValue(0);
const onScroll = useAnimatedScrollHandler(e => { scrollY.value = e.contentOffset.y; });
const header = useAnimatedStyle(() => ({
  height: interpolate(scrollY.value, [0, 150], [220, 80], Extrapolation.CLAMP),
}));
const image = useAnimatedStyle(() => ({
  transform: [{ translateY: scrollY.value * 0.5 }],
  opacity: interpolate(scrollY.value, [0, 150], [1, 0.2], Extrapolation.CLAMP),
}));
return <Animated.ScrollView onScroll={onScroll} scrollEventThrottle={16}>{/* ... */}</Animated.ScrollView>;