Skip to content
This repository was archived by the owner on Aug 13, 2024. It is now read-only.

Commit 39d06b3

Browse files
committed
fix: should call maybeCallOnEdgeReached in onLayout handler
1 parent 128aa12 commit 39d06b3

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/useBiDirectional.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Original Code
33
* @link https://github.com/facebook/react-native/blob/main/packages/virtualized-lists/Lists/VirtualizedList.js
44
*/
5-
import type { NativeScrollEvent, NativeSyntheticEvent, VirtualizedListProps } from 'react-native';
5+
import type { LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent, VirtualizedListProps } from 'react-native';
66
import React, { ComponentType, useRef } from 'react';
77
import { deferred } from './deferred';
88
import type { EnhancedScrollViewProps } from './types';
@@ -173,15 +173,30 @@ export function useBiDirectional<P extends Partial<VirtualizedListProps<any> & E
173173

174174
function onContentSizeChange(w: number, h: number) {
175175
props.onContentSizeChange?.(w, h);
176+
176177
updateScrollMetrics({ contentLength: isHorizontal ? w : h });
177178
}
178179

180+
function onLayout(e: LayoutChangeEvent) {
181+
props.onLayout?.(e);
182+
183+
if (scrollMetrics.current.visibleLength === -1) {
184+
updateScrollMetrics({ visibleLength: isHorizontal ? e.nativeEvent.layout.width : e.nativeEvent.layout.height });
185+
maybeCallOnEdgeReached(
186+
scrollMetrics.current.offset,
187+
scrollMetrics.current.visibleLength,
188+
scrollMetrics.current.contentLength
189+
);
190+
}
191+
}
192+
179193
function renderScrollView() {
180194
return (
181195
<Component
182196
{...props}
183197
ref={scrollRef()}
184198
onScroll={onScroll}
199+
onLayout={onLayout}
185200
onContentSizeChange={onContentSizeChange}
186201
onEndReached={null}
187202
/>

0 commit comments

Comments
 (0)