Replies: 1 comment
-
This does not address your question directly but I have recently implemented similar behavior with regular items.movexport function CountriesWithFlashList() {
const { animationStyles, scrollToTop, animationListProps } =
useToggleHeaderOnScroll<CountryT>({
height: 55,
});
const onFilterTextChange = useCallback((text: string) => {
scrollToTop(); // to show matching items that might have been scrolled away/up
setFilterTerm(text);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<View>
<Animated.View style={animationStyles.container}>
<InputSearch
onTextChange={onFilterTextChange}
style={animationStyles.header}
/>
</Animated.View>
<AppFlashList<CountryT>
{...animationListProps}
estimatedItemSize={55}
//... data, renderItem ...etc
/>
</View>
); export function useToggleHeaderOnScroll<T>({ height }: { height: number }) {
const listRef = useRef<FlashList<T>>(null);
const scrollY = useRef(new Animated.Value(0));
const diffClamp = Animated.diffClamp(scrollY.current, 0, height);
const translateY = diffClamp.interpolate({
inputRange: [0, height],
outputRange: [0, -height],
});
const scrollToTop = useCallback(() => {
listRef.current?.scrollToOffset({
animated: true,
offset: 0,
});
}, []);
const animationListProps: Omit<
AppFlashListProps<T>,
'data' | 'renderItem'
> = useMemo(
() => ({
listRef,
bounces: false, // 👀 overwrite to true if pullToRefresh is needed :\
onScroll: (e: NativeSyntheticEvent<NativeScrollEvent>) => {
const yOffset = e.nativeEvent.contentOffset.y; // y-offset is negative when list bounces
scrollY.current.setValue(yOffset > 0 ? yOffset : 0);
},
onScrollBeginDrag: Keyboard.dismiss,
contentContainerStyle: { paddingTop: height },
}),
[height],
);
return {
animationStyles: {
container: {
transform: [{ translateY }],
zIndex: 10,
elevation: 5,
},
header: animationStyles.header,
},
scrollToTop,
animationListProps,
};
}
const animationStyles = StyleSheet.create({
header: {
position: 'absolute',
top: 0,
start: 0,
end: 0,
backgroundColor: ThemeColor.white,
borderBottomWidth: 1,
borderBottomColor: ThemeColor.lightBlue,
},
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I managed to get this animation working with a regular

FlatList
.But for some reason this is what happens when we try the same approach with

FlashList
.I'm struggling to understand why is this happening so that's why I marked is as potential bug, but it might just be ignorance from my end regarding
FlashList
. It looks like this is a challenge thatRecyclerListView
(which being used under the hood) accounted for as noted in their docs.Here's a simplification of the problem/code that I'm having:
Versions of the relevant packages I'm using:
Beta Was this translation helpful? Give feedback.
All reactions