From a23929238bcd9faa6740bbe1c600158bb66cbfec Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Thu, 7 Dec 2023 05:12:03 +0000 Subject: [PATCH] onScroll --- src/view/com/util/Views.web.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/view/com/util/Views.web.tsx b/src/view/com/util/Views.web.tsx index 2a421433cd..7e6ccfc2ae 100644 --- a/src/view/com/util/Views.web.tsx +++ b/src/view/com/util/Views.web.tsx @@ -60,6 +60,7 @@ export const FlatList = React.forwardRef(function FlatListImpl( contentContainerStyle, onEndReached, onEndReachedThreshold, + onScroll, ...props }: React.PropsWithChildren & AddedProps>, ref: React.Ref>, @@ -118,6 +119,9 @@ export const FlatList = React.forwardRef(function FlatListImpl( React.useImperativeHandle( ref, () => ({ + scrollToTop() { + console.log('yeahh') + }, scrollToOffset({animated, offset}) { nativeRef.current.scrollTo({ x: 0, @@ -129,6 +133,21 @@ export const FlatList = React.forwardRef(function FlatListImpl( [], ) + React.useEffect(() => { + function handleScroll(e) { + onScroll.current.worklet({ + ...e.nativeEvent, + eventName: 'onScroll', + contentOffset: { + x: 0, + y: window.scrollY, + }, + }) + } + window.addEventListener('scroll', handleScroll) + return () => window.removeEventListener('scroll', handleScroll) + }, [onScroll]) + return (