@@ -202,6 +202,8 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
202
202
203
203
const { layoutRef, layoutStyle, layoutProps } = useLayout ( { props, hasSelfPercent, setWidth, setHeight, nodeRef : scrollViewRef , onLayout } )
204
204
205
+ const lastOffset = useRef ( 0 )
206
+
205
207
if ( scrollX && scrollY ) {
206
208
warn ( 'scroll-x and scroll-y cannot be set to true at the same time, Mpx will use the value of scroll-y as the criterion' )
207
209
}
@@ -259,7 +261,8 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
259
261
function onStartReached ( e : NativeSyntheticEvent < NativeScrollEvent > ) {
260
262
const { bindscrolltoupper } = props
261
263
const { offset } = scrollOptions . current
262
- if ( bindscrolltoupper && ( offset <= upperThreshold ) ) {
264
+ const isScrollingBackward = offset < lastOffset . current
265
+ if ( bindscrolltoupper && ( offset <= upperThreshold ) && isScrollingBackward ) {
263
266
if ( ! hasCallScrollToUpper . current ) {
264
267
bindscrolltoupper (
265
268
getCustomEvent ( 'scrolltoupper' , e , {
@@ -280,13 +283,14 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
280
283
const { bindscrolltolower } = props
281
284
const { contentLength, visibleLength, offset } = scrollOptions . current
282
285
const distanceFromEnd = contentLength - visibleLength - offset
283
- if ( bindscrolltolower && ( distanceFromEnd < lowerThreshold ) ) {
286
+ const isScrollingForward = offset > lastOffset . current
287
+ if ( bindscrolltolower && ( distanceFromEnd < lowerThreshold ) && isScrollingForward ) {
284
288
if ( ! hasCallScrollToLower . current ) {
285
289
hasCallScrollToLower . current = true
286
290
bindscrolltolower (
287
291
getCustomEvent ( 'scrolltolower' , e , {
288
292
detail : {
289
- direction : scrollX ? 'right' : 'botttom '
293
+ direction : scrollX ? 'right' : 'bottom '
290
294
} ,
291
295
layoutRef
292
296
} , props )
@@ -341,6 +345,8 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
341
345
onStartReached ( e )
342
346
onEndReached ( e )
343
347
updateIntersection ( )
348
+ // 在 onStartReached、onEndReached 执行完后更新 lastOffset
349
+ lastOffset . current = scrollOptions . current . offset
344
350
}
345
351
346
352
function onScrollEnd ( e : NativeSyntheticEvent < NativeScrollEvent > ) {
@@ -363,6 +369,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
363
369
onStartReached ( e )
364
370
onEndReached ( e )
365
371
updateIntersection ( )
372
+ lastOffset . current = scrollOptions . current . offset
366
373
}
367
374
function updateIntersection ( ) {
368
375
if ( enableTriggerIntersectionObserver && intersectionObservers ) {
0 commit comments