$ git show spotify-header

Album header

Intermediate/anim spotify-header

Cover art shrinks and fades as you scroll; a compact title bar fades in on top.

Inspired by SpotifyFrom William Candillon’s “Can it be done in React Native?” series. The code here is a simplified rewrite for Reanimated 4 and 3.
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.

useAnimatedScrollHandlerinterpolate
spotify-header.tsx · reanimated 4
const y = useSharedValue(0);
const onScroll = useAnimatedScrollHandler(e => { y.value = e.contentOffset.y; });
const cover = useAnimatedStyle(() => ({
  opacity: interpolate(y.value, [0, 200], [1, 0], Extrapolation.CLAMP),
  transform: [{ scale: interpolate(y.value, [-100, 0, 200], [1.3, 1, 0.7], Extrapolation.CLAMP) }],
}));
const titleBar = useAnimatedStyle(() => ({
  opacity: interpolate(y.value, [180, 240], [0, 1], Extrapolation.CLAMP),
}));
// sticky play button: translateY: Math.max(0, y.value - PLAY_BUTTON_Y)
return <Animated.ScrollView onScroll={onScroll} scrollEventThrottle={16}>{/* ... */}</Animated.ScrollView>;