Last active
May 3, 2016 08:05
-
-
Save janicduplessis/aa104ab8a33cece4d10702458a21f640 to your computer and use it in GitHub Desktop.
ScrollableHeader.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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