Skip to content

Instantly share code, notes, and snippets.

@ajsmth
Last active February 26, 2020 20:03
Show Gist options
  • Save ajsmth/e509dadfbff574a4d2b53d86c8f520fb to your computer and use it in GitHub Desktop.
Save ajsmth/e509dadfbff574a4d2b53d86c8f520fb to your computer and use it in GitHub Desktop.
Controlling the hero section - Final
const clampHeroSection = Animated.add(
// we want to make the hero section maintain its position on scroll
// we can do this by setting its translateY value to whatever the scroll value is
scrollY.current,
// shift it up by subtracting points until we've scrolled beyond the search section, and clamp it after that
scrollY.current.interpolate({
inputRange: [0, SEARCH_PLAYLISTS_HEIGHT],
outputRange: [0, -SEARCH_PLAYLISTS_HEIGHT],
// we also want it to shift down when the user pulls down, so we clamp the above range with 'extrapolateRight'
// using just 'extrapolate' would clamp the scroll value in both directions
extrapolateRight: 'clamp',
}),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment