$ git show parallax-header
Collapsing header
Header shrinks and its image moves slower than the list as you scroll.
This snippet uses APIs that didn’t change between versions, so the same code runs on Reanimated 4 and 3.
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>;