Skip to content

Instantly share code, notes, and snippets.

@tomhicks
Created June 20, 2019 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomhicks/9e256a2fd030dfbf774de65fee65be04 to your computer and use it in GitHub Desktop.
Save tomhicks/9e256a2fd030dfbf774de65fee65be04 to your computer and use it in GitHub Desktop.
Bouncy header helper functions
import {Animated} from "react-native"
export function getSpoingyTransform(
scrollY: Animated.Value,
headerHeight: number,
) {
return [
{
translateY: scrollY.interpolate({
inputRange: [-headerHeight, 0, 1],
outputRange: [-headerHeight / 2, 0, 0.5],
}),
},
{
scale: scrollY.interpolate({
inputRange: [-headerHeight, 0, 1],
outputRange: [2, 1, 1],
}),
},
]
}
export function captureScroll(scrollY: Animated.Value) {
return {
onScroll: Animated.event(
[
{
nativeEvent: {
contentOffset: {
y: scrollY,
},
},
},
],
{useNativeDriver: true},
),
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment