I had read a lot of examples with similar problems, but I can achieve the behaviour expected. I think is not the code but React Native.
I have a Component Header (View) and a FlatList, when I scroll down I want to hide the Component Header. The Component Header translate in Y successfully but the FlatList don't move up and a blank area keep in place.
Here the code:
const TestAnimatedFlatList = Animated.createAnimatedComponent(FlatList);
const [animatedValue, setanimatedValue] = useState(new Animated.Value(0));
let translateY = animatedValue.interpolate({
inputRange: [0, 230],
outputRange: [0, -230],
extrapolate: Extrapolate.CLAMP,
});
<View style={{ flex: 1 }}>
<Animated.View style={{
transform: [{translateY}],
backgroundColor: 'lightblue',
height: 230}}>
</Animated.View>
<TestAnimatedFlatList
data = {dataT}
renderItem={renderItem}
keyExtractor={ (item) => item }
style = {{flex: 1}}
onScroll={Animated.event(
[{nativeEvent: {
contentOffset: {
y: animatedValue
}
}
}],
{useNativeDriver: true}
)}
/>
The expected behaviour should be that when the Component Header disappear the FlatList up to the top replacing it and cover all the screen.
The actual behaviour:
I have try a lot of thing like: transforming the size and position of the FlatList at the same time but that don't render correctly when I scroll and start to jump. The other thing was putting the flat list inside the Component Header (View) with the same unwanted result.
Due to the complexity of my Component Header is not a good idea to put it as header in the FlatList. That's why I am using Animated component. Maybe the whole approach is not correctly.
I am using: React Native 0.63.53