Last active
March 16, 2019 08:33
-
-
Save simontreny/13ca4c3370d6eef3634ba36b84cb806e to your computer and use it in GitHub Desktop.
Utilisation d'Animated pour rendre fixe l'entête
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
// scrollOffset est maintenant une Animated.Value | |
state = { text: "", scrollOffset: new Animated.Value(0) }; | |
render() { | |
// Utilisation d'Animated.event pour mettre à jour scrollOffset lors de l'évènement onScroll | |
const scrollEvent = Animated.event( | |
[{ nativeEvent: { contentOffset: { y: this.state.scrollOffset } } }], | |
{ useNativeDriver: true } | |
); | |
return ( | |
<Animated.ScrollView | |
style={{ flex: 1, backgroundColor: "white" }} | |
onScroll={scrollEvent} | |
scrollEventThrottle={1} | |
> | |
{this.renderHeader()} | |
{this.renderContent()} | |
</Animated.ScrollView> | |
); | |
} | |
renderHeader() { | |
const headerHeight = 240; | |
return ( | |
// Utilisation d'Animated.View pour associer la valeur animée à la props translateY | |
<Animated.View | |
style={{ | |
height: headerHeight, | |
transform: [{ translateY: this.state.scrollOffset }], | |
zIndex: 100, | |
}} | |
> | |
/* ... */ | |
</Animated.View> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment