1+ /**
2+ * Original Code
3+ * @link https://github.com/facebook/react-native/blob/main/packages/virtualized-lists/Lists/VirtualizedList.js
4+ */
5+
16import type { NativeScrollEvent , NativeSyntheticEvent , VirtualizedListProps } from 'react-native' ;
27import type { EnhancedScrollViewProps } from './types' ;
38import React , { ComponentType , useRef } from 'react' ;
@@ -47,19 +52,6 @@ export function useBiDirectional<P extends Partial<VirtualizedListProps<any> & E
4752 const sentEndForContentLength = useRef ( 0 ) ;
4853 const sentStartForContentLength = useRef ( 0 ) ;
4954
50- function maybeRecallOnEdgeReached ( key : 'distanceFromStart' | 'distanceFromEnd' , threshold : number ) {
51- const distanceFromEdge = getDistanceFrom (
52- scrollMetrics . current . offset ,
53- scrollMetrics . current . visibleLength ,
54- scrollMetrics . current . contentLength
55- ) [ key ] ;
56-
57- if ( distanceFromEdge <= threshold ) {
58- const lazyOnEdgeReached = key === 'distanceFromStart' ? lazyOnStartReached : lazyOnEndReached ;
59- lazyOnEdgeReached ( distanceFromEdge ) ;
60- }
61- }
62-
6355 function updateScrollMetrics ( metrics : Partial < ScrollMetrics > ) {
6456 if ( typeof metrics . offset === 'number' ) {
6557 scrollMetrics . current . offset = metrics . offset ;
@@ -105,7 +97,7 @@ export function useBiDirectional<P extends Partial<VirtualizedListProps<any> & E
10597 return p . promise ;
10698 }
10799
108- const maybeCallOnEdgeReached = ( offset : number , visibleLength : number , contentLength : number ) => {
100+ function maybeCallOnEdgeReached ( offset : number , visibleLength : number , contentLength : number ) {
109101 if ( visibleLength < 0 || contentLength < 0 ) return ;
110102
111103 const { onEndReached, onStartReached } = props ;
@@ -154,9 +146,22 @@ export function useBiDirectional<P extends Partial<VirtualizedListProps<any> & E
154146 sentStartForContentLength . current = 0 ;
155147 }
156148 }
157- } ;
149+ }
158150
159- const onScroll = ( e : NativeSyntheticEvent < NativeScrollEvent > ) => {
151+ function maybeRecallOnEdgeReached ( key : 'distanceFromStart' | 'distanceFromEnd' , threshold : number ) {
152+ const distanceFromEdge = getDistanceFrom (
153+ scrollMetrics . current . offset ,
154+ scrollMetrics . current . visibleLength ,
155+ scrollMetrics . current . contentLength
156+ ) [ key ] ;
157+
158+ if ( distanceFromEdge <= threshold ) {
159+ const lazyOnEdgeReached = key === 'distanceFromStart' ? lazyOnStartReached : lazyOnEndReached ;
160+ lazyOnEdgeReached ( distanceFromEdge ) ;
161+ }
162+ }
163+
164+ function onScroll ( e : NativeSyntheticEvent < NativeScrollEvent > ) {
160165 props . onScroll ?.( e ) ;
161166
162167 const { contentOffset, contentSize, layoutMeasurement } = e . nativeEvent ;
@@ -167,14 +172,14 @@ export function useBiDirectional<P extends Partial<VirtualizedListProps<any> & E
167172
168173 maybeCallOnEdgeReached ( offset , visibleLength , contentLength ) ;
169174 updateScrollMetrics ( { offset, visibleLength, contentLength, timestamp : e . timeStamp } ) ;
170- } ;
175+ }
171176
172- const onContentSizeChange = ( w : number , h : number ) => {
177+ function onContentSizeChange ( w : number , h : number ) {
173178 props . onContentSizeChange ?.( w , h ) ;
174179 updateScrollMetrics ( { contentLength : isHorizontal ? w : h } ) ;
175- } ;
180+ }
176181
177- const renderScrollView = ( ) => {
182+ function renderScrollView ( ) {
178183 return (
179184 < Component
180185 { ...props }
@@ -184,7 +189,7 @@ export function useBiDirectional<P extends Partial<VirtualizedListProps<any> & E
184189 onEndReached = { null }
185190 />
186191 ) ;
187- } ;
192+ }
188193
189194 return {
190195 renderScrollView,
0 commit comments