diff --git a/src/view/com/util/List.web.tsx b/src/view/com/util/List.web.tsx index 73000d95f1..9bea2d7951 100644 --- a/src/view/com/util/List.web.tsx +++ b/src/view/com/util/List.web.tsx @@ -92,12 +92,24 @@ function ListImpl( if (!element) return return { - scrollWidth: element.scrollWidth, - scrollHeight: element.scrollHeight, - clientWidth: element.clientWidth, - clientHeight: element.clientHeight, - scrollY: element.scrollTop, - scrollX: element.scrollLeft, + get scrollWidth() { + return element.scrollWidth + }, + get scrollHeight() { + return element.scrollHeight + }, + get clientWidth() { + return element.clientWidth + }, + get clientHeight() { + return element.clientHeight + }, + get scrollY() { + return element.scrollTop + }, + get scrollX() { + return element.scrollLeft + }, scrollTo(options?: ScrollToOptions) { element.scrollTo(options) }, @@ -113,12 +125,24 @@ function ListImpl( } } else { return { - scrollWidth: document.documentElement.scrollWidth, - scrollHeight: document.documentElement.scrollHeight, - clientWidth: window.innerWidth, - clientHeight: window.innerHeight, - scrollY: window.scrollY, - scrollX: window.scrollX, + get scrollWidth() { + return document.documentElement.scrollWidth + }, + get scrollHeight() { + return document.documentElement.scrollHeight + }, + get clientWidth() { + return window.innerWidth + }, + get clientHeight() { + return window.innerHeight + }, + get scrollY() { + return window.scrollY + }, + get scrollX() { + return window.scrollX + }, scrollTo(options: ScrollToOptions) { window.scrollTo(options) }, @@ -135,7 +159,7 @@ function ListImpl( } }, [containWeb]) - const nativeRef = React.useRef(null) + const nativeRef = React.useRef(null) React.useImperativeHandle( ref, () => @@ -257,9 +281,15 @@ function ListImpl( return ( + style={[ + style, + containWeb && { + flex: 1, + // @ts-expect-error web only + 'overflow-y': 'scroll', + }, + ]} + ref={nativeRef as any}> ( pal.border, ]}> {onStartReached && ( @@ -300,7 +330,7 @@ function ListImpl( ))} {onEndReached && ( @@ -363,13 +393,13 @@ let Row = function RowImpl({ Row = React.memo(Row) let Visibility = ({ - root = null, + root, topMargin = '0px', bottomMargin = '0px', onVisibleChange, style, }: { - root?: Element | null + root?: React.RefObject | null topMargin?: string bottomMargin?: string onVisibleChange: (isVisible: boolean) => void @@ -393,7 +423,7 @@ let Visibility = ({ React.useEffect(() => { const observer = new IntersectionObserver(handleIntersection, { - root, + root: root?.current ?? null, rootMargin: `${topMargin} 0px ${bottomMargin} 0px`, }) const tail: Element | null = tailRef.current! diff --git a/src/view/screens/Storybook/ListContained.tsx b/src/view/screens/Storybook/ListContained.tsx index c4e06efb22..b3ea091f40 100644 --- a/src/view/screens/Storybook/ListContained.tsx +++ b/src/view/screens/Storybook/ListContained.tsx @@ -22,9 +22,15 @@ export function ListContained() { <> { + onScroll={e => { 'worklet' - console.log('onScroll') + console.log( + JSON.stringify({ + contentOffset: e.contentOffset, + layoutMeasurement: e.layoutMeasurement, + contentSize: e.contentSize, + }), + ) }}>