Skip to content

Instantly share code, notes, and snippets.

@janicduplessis
Last active May 3, 2016 08:05
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 janicduplessis/aa104ab8a33cece4d10702458a21f640 to your computer and use it in GitHub Desktop.
Save janicduplessis/aa104ab8a33cece4d10702458a21f640 to your computer and use it in GitHub Desktop.
ScrollableHeader.js
...
const imageOpacity = this.state.scrollY.interpolate({
inputRange: [0, HEADER_SCROLL_DISTANCE / 2, HEADER_SCROLL_DISTANCE],
outputRange: [1, 1, 0],
extrapolate: 'clamp',
});
const imageTranslate = this.state.scrollY.interpolate({
inputRange: [0, HEADER_SCROLL_DISTANCE],
outputRange: [0, -50],
extrapolate: 'clamp',
});
...
<ScrollView>
...
</ScrollView>
<Animated.View style={[styles.header, {height: headerHeight}]}>
<Animated.Image
style={[
styles.backgroundImage,
{opacity: imageOpacity, transform: [{translateY: imageTranslate}]},
]}
source={require('./images/cat.jpg')}
/>
<Animated.View>
...
</Animated.View>
</Animated.View>
...
backgroundImage: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
width: null,
height: HEADER_MAX_HEIGHT,
resizeMode: 'cover',
},
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment