Reputation: 3062
Using React Native, I am trying to mimic the below animation. The header (Map Pin and Stamba Hotel Tbilisi) scrolls up with the FlatList, but then if the user scrolls down the header is immediately scrolled down with the FlatList. Kindly note this animation is adhering to the SareAreaView.
The problems I am having are the following;
return (
<SafeAreaView style={{ zIndex: 1, flex: 1 }}>
<Animated.View style={[styles.header, { transform: [{ translateY }] }]}>
<HomeHeader2 />
</Animated.View>
{loading ?
<View/> : <FlatList/>
}
</SafeAreaView>
)
// FLATLIST PROP TO HANDLE ANIMATION
onScroll={ Animated.event([{nativeEvent:
{ contentOffset: { y: scrollY } } }], {
useNativeDriver: false,
})
}
// INTERPOLATE OVER SCROLLY
const scrollY = useRef(new Animated.Value(0)).current;
const translateY = scrollY.interpolate({
inputRange: [0, 50],
outputRange: [0, -50],
extrapolateRight: "clamp",
});
const styles = StyleSheet.create({
header: {
backgroundColor: "blue",
justifyContent: "center",
alignItems: "center",
position: "relative", // AS SHOULD BE UNDER SAFEAREAVIEW
left: 0,
right: 0,
top: 0,
},
});
Am I on the right track here or is there a better approach?
Upvotes: 1
Views: 113