Skip to content

Instantly share code, notes, and snippets.

@simontreny
Last active March 16, 2019 08:33
Show Gist options
  • Save simontreny/13ca4c3370d6eef3634ba36b84cb806e to your computer and use it in GitHub Desktop.
Save simontreny/13ca4c3370d6eef3634ba36b84cb806e to your computer and use it in GitHub Desktop.
Utilisation d'Animated pour rendre fixe l'entête
// 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