@lynx-js/lynx-ui-scroll-view 3.131.0 → 3.133.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/ScrollViewWithBouncesHook.d.ts +2 -0
- package/dist/ScrollViewWithBouncesHook.d.ts.map +1 -1
- package/dist/ScrollViewWithBouncesHook.jsx +5 -3
- package/dist/ScrollViewWithBouncesHook.jsx.map +1 -1
- package/dist/hooks/useBounce.d.ts +2 -1
- package/dist/hooks/useBounce.d.ts.map +1 -1
- package/dist/hooks/useBounce.jsx +52 -53
- package/dist/hooks/useBounce.jsx.map +1 -1
- package/dist/index.jsx +9 -4
- package/dist/index.jsx.map +1 -1
- package/dist/types/index.docs.d.ts +27 -10
- package/dist/types/index.docs.d.ts.map +1 -1
- package/dist/types/index.docs.jsx.map +1 -1
- package/package.json +4 -4
- package/src/ScrollViewWithBouncesHook.tsx +22 -5
- package/src/hooks/useBounce.tsx +164 -131
- package/src/index.tsx +10 -1
- package/src/types/index.docs.ts +27 -10
package/src/hooks/useBounce.tsx
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { runOnBackground, useMainThreadRef } from '@lynx-js/react'
|
|
6
6
|
|
|
7
|
-
import { selectorMT } from '@lynx-js/lynx-ui-common'
|
|
7
|
+
import { log, mtsLog, selectorMT } from '@lynx-js/lynx-ui-common'
|
|
8
8
|
import type { CommonEvent, MainThread, ScrollEvent } from '@lynx-js/types'
|
|
9
9
|
|
|
10
10
|
export interface scrollToBouncesInfo {
|
|
@@ -24,13 +24,14 @@ export interface BounceableBasicProps {
|
|
|
24
24
|
singleSidedBounce?: 'upper' | 'lower' | 'both' | 'iOSBounces' | 'none'
|
|
25
25
|
estimatedHeight?: number
|
|
26
26
|
estimatedWidth?: number
|
|
27
|
-
debugLog?: boolean
|
|
28
27
|
validAnimationVersion?: boolean
|
|
29
28
|
onScrollToBounces?: (e: scrollToBouncesInfo) => void
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
export interface useBounceOptions {
|
|
33
32
|
bounceableOptions: BounceableBasicProps
|
|
33
|
+
debugLog?: boolean
|
|
34
|
+
enableRTL?: boolean
|
|
34
35
|
/**
|
|
35
36
|
* idSelector of scroll container
|
|
36
37
|
*/
|
|
@@ -61,9 +62,7 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
61
62
|
// The rebound coefficient during bounce back, the larger it is, the faster the rebound speed.
|
|
62
63
|
const beta = useMainThreadRef(15)
|
|
63
64
|
|
|
64
|
-
const
|
|
65
|
-
options.bounceableOptions.debugLog ?? false,
|
|
66
|
-
)
|
|
65
|
+
const debugLogEnabled = Boolean(options.debugLog)
|
|
67
66
|
|
|
68
67
|
const singleSidedBounce = useMainThreadRef(
|
|
69
68
|
options.bounceableOptions.singleSidedBounce ?? 'both',
|
|
@@ -122,6 +121,7 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
122
121
|
const { enableBounces, onScrollToBounces } = options.bounceableOptions
|
|
123
122
|
const alwaysBouncing = options.bounceableOptions.alwaysBouncing ?? false
|
|
124
123
|
const scrollOrientation = options.scrollOrientation ?? 'vertical'
|
|
124
|
+
const enableRTL = useMainThreadRef(options.enableRTL ?? false)
|
|
125
125
|
const enableBounceEventInFling =
|
|
126
126
|
options.bounceableOptions.enableBounceEventInFling ?? true
|
|
127
127
|
const startBounceTriggerDistance =
|
|
@@ -132,6 +132,12 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
132
132
|
const temporaryValidVersionCheckForRAF = useMainThreadRef(
|
|
133
133
|
options.bounceableOptions.validAnimationVersion ?? false,
|
|
134
134
|
)
|
|
135
|
+
log(
|
|
136
|
+
debugLogEnabled,
|
|
137
|
+
`[lynx-ui-scroll-view][useBounce] init, enableBounces: ${enableBounces}, orientation: ${scrollOrientation}, enableRTL: ${
|
|
138
|
+
options.enableRTL ?? false
|
|
139
|
+
}`,
|
|
140
|
+
)
|
|
135
141
|
|
|
136
142
|
const bouncingStatus = {
|
|
137
143
|
inScrollingRange: 0,
|
|
@@ -151,6 +157,11 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
151
157
|
return 1.0 / Number(SystemInfo.pixelRatio)
|
|
152
158
|
}
|
|
153
159
|
|
|
160
|
+
function normalizedHorizontalValue(value: number) {
|
|
161
|
+
'main thread'
|
|
162
|
+
return enableRTL.current ? -value : value
|
|
163
|
+
}
|
|
164
|
+
|
|
154
165
|
function isAndroid() {
|
|
155
166
|
'main thread'
|
|
156
167
|
return SystemInfo.platform === 'Android'
|
|
@@ -172,9 +183,7 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
172
183
|
// Clear all temps when a touch procedure ends.
|
|
173
184
|
function clearTouchInfo() {
|
|
174
185
|
'main thread'
|
|
175
|
-
|
|
176
|
-
console.info('clearTouchInfo')
|
|
177
|
-
}
|
|
186
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] clear touch info')
|
|
178
187
|
startTouch.current = null
|
|
179
188
|
bouncingTouchStartPosition.current = 0
|
|
180
189
|
prevTouch.current = null
|
|
@@ -199,11 +208,15 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
199
208
|
if (startBouncingTouch.current === null) {
|
|
200
209
|
return scrollOrientation === 'vertical'
|
|
201
210
|
? event.touches[0].pageY - startTouch.current[0].pageY
|
|
202
|
-
:
|
|
211
|
+
: normalizedHorizontalValue(
|
|
212
|
+
event.touches[0].pageX - startTouch.current[0].pageX,
|
|
213
|
+
)
|
|
203
214
|
} else {
|
|
204
215
|
return scrollOrientation === 'vertical'
|
|
205
216
|
? event.touches[0].pageY - startBouncingTouch.current[0].pageY
|
|
206
|
-
:
|
|
217
|
+
: normalizedHorizontalValue(
|
|
218
|
+
event.touches[0].pageX - startBouncingTouch.current[0].pageX,
|
|
219
|
+
)
|
|
207
220
|
}
|
|
208
221
|
}
|
|
209
222
|
return 0
|
|
@@ -223,14 +236,10 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
223
236
|
|
|
224
237
|
// upper bouncing
|
|
225
238
|
const initialLayoutPosition = 0
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
'currentPosition',
|
|
231
|
-
currentPosition,
|
|
232
|
-
)
|
|
233
|
-
}
|
|
239
|
+
mtsLog(
|
|
240
|
+
debugLogEnabled,
|
|
241
|
+
`[lynx-ui-scroll-view][useBounce] get bouncing status, initialLayoutPosition: ${initialLayoutPosition}, currentPosition: ${currentPosition}`,
|
|
242
|
+
)
|
|
234
243
|
|
|
235
244
|
if (currentPosition > initialLayoutPosition) {
|
|
236
245
|
return bouncingStatus.upperBouncing
|
|
@@ -270,7 +279,10 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
270
279
|
function bouncingSetStyle(offset: number) {
|
|
271
280
|
'main thread'
|
|
272
281
|
if (isNaN(Number(offset))) {
|
|
273
|
-
|
|
282
|
+
mtsLog(
|
|
283
|
+
true,
|
|
284
|
+
'[lynx-ui-scroll-view][useBounce] ERROR! bouncingOffset is NaN',
|
|
285
|
+
)
|
|
274
286
|
return
|
|
275
287
|
}
|
|
276
288
|
// update bouncingPositionInfo first
|
|
@@ -300,6 +312,10 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
300
312
|
}
|
|
301
313
|
// trigger translate
|
|
302
314
|
if (isVertical()) {
|
|
315
|
+
mtsLog(
|
|
316
|
+
debugLogEnabled,
|
|
317
|
+
`[lynx-ui-scroll-view][useBounce] apply transform, orientation: vertical, rawOffset: ${offset}, containerTransform: translateY(${offset}px)`,
|
|
318
|
+
)
|
|
303
319
|
selectorMT(containerID)?.setStyleProperty(
|
|
304
320
|
'transform',
|
|
305
321
|
`translateY(${offset}px)`,
|
|
@@ -313,17 +329,24 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
313
329
|
`translateY(${offset}px)`,
|
|
314
330
|
)
|
|
315
331
|
} else {
|
|
332
|
+
const visualOffset = enableRTL.current ? -offset : offset
|
|
333
|
+
mtsLog(
|
|
334
|
+
debugLogEnabled,
|
|
335
|
+
`[lynx-ui-scroll-view][useBounce] apply transform, orientation: horizontal, rawOffset: ${offset}, enableRTL: ${
|
|
336
|
+
String(enableRTL.current)
|
|
337
|
+
}, visualOffset: ${visualOffset}, containerTransform: translateX(${visualOffset}px)`,
|
|
338
|
+
)
|
|
316
339
|
selectorMT(containerID)?.setStyleProperty(
|
|
317
340
|
'transform',
|
|
318
|
-
`translateX(${
|
|
341
|
+
`translateX(${visualOffset}px)`,
|
|
319
342
|
)
|
|
320
343
|
selectorMT(`${containerID}-upperBounceWrapper`)?.setStyleProperty(
|
|
321
344
|
'transform',
|
|
322
|
-
`translateX(${
|
|
345
|
+
`translateX(${visualOffset}px)`,
|
|
323
346
|
)
|
|
324
347
|
selectorMT(`${containerID}-lowerBounceWrapper`)?.setStyleProperty(
|
|
325
348
|
'transform',
|
|
326
|
-
`translateX(${
|
|
349
|
+
`translateX(${visualOffset}px)`,
|
|
327
350
|
)
|
|
328
351
|
}
|
|
329
352
|
}
|
|
@@ -337,9 +360,12 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
337
360
|
// send the scrollToBounces event
|
|
338
361
|
function triggerScrollToBouncesEvent(isUpper: boolean) {
|
|
339
362
|
'main thread'
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
363
|
+
mtsLog(
|
|
364
|
+
debugLogEnabled,
|
|
365
|
+
`[lynx-ui-scroll-view][useBounce] trigger scrollToBounces, direction: ${
|
|
366
|
+
isUpper ? 'upper' : 'lower'
|
|
367
|
+
}`,
|
|
368
|
+
)
|
|
343
369
|
|
|
344
370
|
const info: scrollToBouncesInfo = {
|
|
345
371
|
direction: isUpper ? 'upper' : 'lower',
|
|
@@ -376,21 +402,10 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
376
402
|
+ 1.0))
|
|
377
403
|
* scrollViewFrameSize,
|
|
378
404
|
)
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
scrollViewFrameSize,
|
|
384
|
-
'touchStartPosition',
|
|
385
|
-
touchStartPosition,
|
|
386
|
-
'deltaYForTouchStartPosition',
|
|
387
|
-
deltaYForTouchStartPosition,
|
|
388
|
-
'deltaYForNextPosition',
|
|
389
|
-
deltaYForNextPosition,
|
|
390
|
-
'rubberBandingDistance',
|
|
391
|
-
rubberBandingDistance,
|
|
392
|
-
)
|
|
393
|
-
}
|
|
405
|
+
mtsLog(
|
|
406
|
+
debugLogEnabled,
|
|
407
|
+
`[lynx-ui-scroll-view][useBounce] rubber effect, scrollViewFrameSize: ${scrollViewFrameSize}, touchStartPosition: ${touchStartPosition}, deltaYForTouchStartPosition: ${deltaYForTouchStartPosition}, deltaYForNextPosition: ${deltaYForNextPosition}, rubberBandingDistance: ${rubberBandingDistance}`,
|
|
408
|
+
)
|
|
394
409
|
|
|
395
410
|
bouncingSetStyle(isNegative * rubberBandingDistance)
|
|
396
411
|
}
|
|
@@ -398,17 +413,12 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
398
413
|
function triggerRubberEffectIfCrossingEdge(event: MainThread.TouchEvent) {
|
|
399
414
|
'main thread'
|
|
400
415
|
const delta = getCurrentDelta(event)
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
toUpper.current,
|
|
408
|
-
'toLower',
|
|
409
|
-
toLower.current,
|
|
410
|
-
)
|
|
411
|
-
}
|
|
416
|
+
mtsLog(
|
|
417
|
+
debugLogEnabled,
|
|
418
|
+
`[lynx-ui-scroll-view][useBounce] check crossing edge, delta: ${delta}, toUpper: ${
|
|
419
|
+
String(toUpper.current)
|
|
420
|
+
}, toLower: ${String(toLower.current)}`,
|
|
421
|
+
)
|
|
412
422
|
|
|
413
423
|
// Crossing top range
|
|
414
424
|
if (
|
|
@@ -449,11 +459,14 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
449
459
|
|
|
450
460
|
function bouncingBack() {
|
|
451
461
|
'main thread'
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
462
|
+
mtsLog(
|
|
463
|
+
debugLogEnabled,
|
|
464
|
+
'[lynx-ui-scroll-view][useBounce] fling forward end',
|
|
465
|
+
)
|
|
466
|
+
mtsLog(
|
|
467
|
+
debugLogEnabled,
|
|
468
|
+
'[lynx-ui-scroll-view][useBounce] bounce back starts',
|
|
469
|
+
)
|
|
457
470
|
|
|
458
471
|
// step3: bounce back
|
|
459
472
|
// @ts-expect-error expected
|
|
@@ -465,9 +478,10 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
465
478
|
return
|
|
466
479
|
}
|
|
467
480
|
const currentTime = Date.now() - startTime
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
481
|
+
mtsLog(
|
|
482
|
+
debugLogEnabled,
|
|
483
|
+
'[lynx-ui-scroll-view][useBounce] touching end bouncing back frame',
|
|
484
|
+
)
|
|
471
485
|
|
|
472
486
|
// critical damping
|
|
473
487
|
const C2 = beta.current * C1
|
|
@@ -477,9 +491,10 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
477
491
|
if (Math.abs(easedDistance) < threshold()) {
|
|
478
492
|
// Make sure it backs to 0
|
|
479
493
|
bouncingSetStyle(0)
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
494
|
+
mtsLog(
|
|
495
|
+
debugLogEnabled,
|
|
496
|
+
'[lynx-ui-scroll-view][useBounce] bounce back ends',
|
|
497
|
+
)
|
|
483
498
|
} else {
|
|
484
499
|
customRequestAnimationFrame(touchingEndBouncingBackFrame)
|
|
485
500
|
}
|
|
@@ -493,9 +508,7 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
493
508
|
function bounceableTouchStart(event: MainThread.TouchEvent) {
|
|
494
509
|
'main thread'
|
|
495
510
|
startTouch.current = event.touches
|
|
496
|
-
|
|
497
|
-
console.info('bounceableTouchStart')
|
|
498
|
-
}
|
|
511
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touch start')
|
|
499
512
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
500
513
|
bouncingTouchStartPosition.current =
|
|
501
514
|
// @ts-expect-error expected
|
|
@@ -511,7 +524,7 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
511
524
|
prevTouch.current = event.touches
|
|
512
525
|
if (startTouch.current === null) {
|
|
513
526
|
// It means current situation is illegal. A touchMove event happens without a touchStart event beforehand. Or a touchMove event happens after a touchEnd event.
|
|
514
|
-
|
|
527
|
+
mtsLog(true, '[lynx-ui-scroll-view][useBounce] ERROR! touch not started')
|
|
515
528
|
} else {
|
|
516
529
|
const delta = getCurrentDelta(event)
|
|
517
530
|
const currentBouncingStatus = getBouncingStatus()
|
|
@@ -520,32 +533,36 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
520
533
|
case bouncingStatus.upperBouncing: {
|
|
521
534
|
enableScroll(false)
|
|
522
535
|
rubberEffect(1, delta)
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
536
|
+
mtsLog(
|
|
537
|
+
debugLogEnabled,
|
|
538
|
+
'[lynx-ui-scroll-view][useBounce] touch move upper bouncing',
|
|
539
|
+
)
|
|
526
540
|
break
|
|
527
541
|
}
|
|
528
542
|
case bouncingStatus.lowerBouncing: {
|
|
529
543
|
enableScroll(false)
|
|
530
544
|
rubberEffect(-1, delta)
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
545
|
+
mtsLog(
|
|
546
|
+
debugLogEnabled,
|
|
547
|
+
'[lynx-ui-scroll-view][useBounce] touch move lower bouncing',
|
|
548
|
+
)
|
|
534
549
|
break
|
|
535
550
|
}
|
|
536
551
|
case bouncingStatus.alwaysBouncing: {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
552
|
+
mtsLog(
|
|
553
|
+
debugLogEnabled,
|
|
554
|
+
'[lynx-ui-scroll-view][useBounce] touch move always bouncing',
|
|
555
|
+
)
|
|
540
556
|
if (alwaysBouncing) {
|
|
541
557
|
triggerRubberEffectIfCrossingEdge(event)
|
|
542
558
|
}
|
|
543
559
|
break
|
|
544
560
|
}
|
|
545
561
|
case bouncingStatus.inScrollingRange: {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
562
|
+
mtsLog(
|
|
563
|
+
debugLogEnabled,
|
|
564
|
+
'[lynx-ui-scroll-view][useBounce] touch move in scrolling range',
|
|
565
|
+
)
|
|
549
566
|
triggerRubberEffectIfCrossingEdge(event)
|
|
550
567
|
break
|
|
551
568
|
}
|
|
@@ -561,9 +578,7 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
561
578
|
// Reset the state. The touch information should be reset, and we should no longer ban the enable-scroll.
|
|
562
579
|
clearTouchInfo()
|
|
563
580
|
enableScroll(true)
|
|
564
|
-
|
|
565
|
-
console.info('bounceableTouchEnd')
|
|
566
|
-
}
|
|
581
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touch end')
|
|
567
582
|
if (shouldBounceWhenTouchEnd(getBouncingStatus())) {
|
|
568
583
|
const startTime = Date.now()
|
|
569
584
|
// @ts-expect-error expected
|
|
@@ -585,18 +600,20 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
585
600
|
if (Boolean(touchEndFrameEnableFlag.current) === false) {
|
|
586
601
|
return
|
|
587
602
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
603
|
+
mtsLog(
|
|
604
|
+
debugLogEnabled,
|
|
605
|
+
'[lynx-ui-scroll-view][useBounce] touch end process frame',
|
|
606
|
+
)
|
|
591
607
|
if (Math.abs(currentVelocity) <= threshold()) {
|
|
592
608
|
// If the velocity is already under threshold, skip fling and start step3: bounce back.
|
|
593
609
|
bouncingBack()
|
|
594
610
|
} else {
|
|
595
611
|
// If the drag end with a velocity, start fling to consume it.
|
|
596
612
|
// step 2: fling down
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
613
|
+
mtsLog(
|
|
614
|
+
debugLogEnabled,
|
|
615
|
+
'[lynx-ui-scroll-view][useBounce] fling down start',
|
|
616
|
+
)
|
|
600
617
|
// This function is obtained by integrating the velocity function with a deceleration rate of flingDeceleratingRate.
|
|
601
618
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
602
619
|
const distance: number = dragEndPosition
|
|
@@ -626,37 +643,43 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
626
643
|
scrollX.current = event.detail.scrollLeft
|
|
627
644
|
scrollY.current = event.detail.scrollTop
|
|
628
645
|
if (!isEmpty(prevScroll.current)) {
|
|
629
|
-
|
|
630
|
-
|
|
646
|
+
const prev = prevScroll.current as {
|
|
647
|
+
timestamp: number
|
|
648
|
+
detail: { scrollTop: number, scrollLeft: number }
|
|
649
|
+
}
|
|
650
|
+
const timeDuration = Date.now() - prev.timestamp
|
|
631
651
|
if (timeDuration > 0) {
|
|
632
|
-
const deltaY = isVertical()
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
652
|
+
const deltaY = isVertical()
|
|
653
|
+
? event.detail.scrollTop - prev.detail.scrollTop
|
|
654
|
+
: normalizedHorizontalValue(
|
|
655
|
+
event.detail.scrollLeft - prev.detail.scrollLeft,
|
|
656
|
+
)
|
|
637
657
|
const velocity = deltaY / timeDuration
|
|
638
658
|
if (Number.isFinite(velocity)) {
|
|
639
659
|
scrollVelocity.current = velocity
|
|
640
660
|
}
|
|
641
661
|
}
|
|
642
662
|
}
|
|
663
|
+
mtsLog(
|
|
664
|
+
debugLogEnabled,
|
|
665
|
+
`[lynx-ui-scroll-view][useBounce] handle scroll near edge, scrollLeft: ${event.detail.scrollLeft}, scrollTop: ${event.detail.scrollTop}, velocity: ${scrollVelocity.current}`,
|
|
666
|
+
)
|
|
643
667
|
prevScroll.current = event
|
|
644
668
|
}
|
|
645
669
|
|
|
646
670
|
function onUpperDisexposure(_event: CommonEvent) {
|
|
647
671
|
'main thread'
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
672
|
+
mtsLog(
|
|
673
|
+
debugLogEnabled,
|
|
674
|
+
'[lynx-ui-scroll-view][useBounce] upper disexposure',
|
|
675
|
+
)
|
|
651
676
|
toUpper.current = false
|
|
652
677
|
}
|
|
653
678
|
|
|
654
679
|
// Handle scrolltoupper event.
|
|
655
680
|
function onUpperExposure(_event: CommonEvent) {
|
|
656
681
|
'main thread'
|
|
657
|
-
|
|
658
|
-
console.info('upper exposure')
|
|
659
|
-
}
|
|
682
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] upper exposure')
|
|
660
683
|
toUpper.current = true
|
|
661
684
|
if (
|
|
662
685
|
singleSidedBounce.current !== 'upper'
|
|
@@ -676,24 +699,29 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
676
699
|
const velocity = scrollVelocity.current
|
|
677
700
|
let currentVelocity = velocity
|
|
678
701
|
const startTime = Date.now()
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
702
|
+
mtsLog(
|
|
703
|
+
debugLogEnabled,
|
|
704
|
+
`[lynx-ui-scroll-view][useBounce] fling to upper event start, velocity: ${velocity}`,
|
|
705
|
+
)
|
|
682
706
|
let sentScrollToBouncesEvent = false // only sent scrollToBounces once
|
|
683
707
|
const flingEndWithBouncingFrame = () => {
|
|
684
708
|
if (Boolean(flingEndWithBouncingEnableFlag.current) === false) {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
709
|
+
mtsLog(
|
|
710
|
+
debugLogEnabled,
|
|
711
|
+
'[lynx-ui-scroll-view][useBounce] flingEndWithBouncingEnableFlag early return',
|
|
712
|
+
)
|
|
688
713
|
return
|
|
689
714
|
}
|
|
690
715
|
if (Math.abs(currentVelocity) <= threshold()) {
|
|
691
716
|
flingEndWithBouncingEnableFlag.current = false
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
717
|
+
mtsLog(
|
|
718
|
+
debugLogEnabled,
|
|
719
|
+
'[lynx-ui-scroll-view][useBounce] fling to upper event end',
|
|
720
|
+
)
|
|
721
|
+
mtsLog(
|
|
722
|
+
debugLogEnabled,
|
|
723
|
+
'[lynx-ui-scroll-view][useBounce] bouncing to upper event start',
|
|
724
|
+
)
|
|
697
725
|
bouncingBack()
|
|
698
726
|
} else {
|
|
699
727
|
// step 1: fling
|
|
@@ -723,17 +751,16 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
723
751
|
|
|
724
752
|
function onLowerDisexposure(_event: CommonEvent) {
|
|
725
753
|
'main thread'
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
754
|
+
mtsLog(
|
|
755
|
+
debugLogEnabled,
|
|
756
|
+
'[lynx-ui-scroll-view][useBounce] lower disexposure',
|
|
757
|
+
)
|
|
729
758
|
toLower.current = false
|
|
730
759
|
}
|
|
731
760
|
|
|
732
761
|
function onLowerExposure(_event: CommonEvent) {
|
|
733
762
|
'main thread'
|
|
734
|
-
|
|
735
|
-
console.info('lower exposure')
|
|
736
|
-
}
|
|
763
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] lower exposure')
|
|
737
764
|
toLower.current = true
|
|
738
765
|
if (
|
|
739
766
|
singleSidedBounce.current !== 'lower'
|
|
@@ -750,32 +777,38 @@ export function useBounce(options: useBounceOptions): bounceHandlers {
|
|
|
750
777
|
bouncingPositionInfo.current?.bouncingOffset ?? 0
|
|
751
778
|
} else if (enableBounceEventInFling && scrollVelocity.current > 0) {
|
|
752
779
|
const velocity = scrollVelocity.current
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
780
|
+
mtsLog(
|
|
781
|
+
debugLogEnabled,
|
|
782
|
+
`[lynx-ui-scroll-view][useBounce] lower velocity: ${velocity}`,
|
|
783
|
+
)
|
|
756
784
|
|
|
757
785
|
// scroll to end with velocity, start bouncing effect
|
|
758
786
|
if (Math.abs(velocity) > threshold()) {
|
|
759
787
|
let currentVelocity = velocity
|
|
760
788
|
const startTime = Date.now()
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
789
|
+
mtsLog(
|
|
790
|
+
debugLogEnabled,
|
|
791
|
+
`[lynx-ui-scroll-view][useBounce] fling to lower event start, velocity: ${velocity}`,
|
|
792
|
+
)
|
|
764
793
|
let sentScrollToBouncesEvent = false // only sent scrollToBounces once
|
|
765
794
|
const flingEndWithBouncingFrame = () => {
|
|
766
795
|
if (Boolean(flingEndWithBouncingEnableFlag.current) === false) {
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
796
|
+
mtsLog(
|
|
797
|
+
debugLogEnabled,
|
|
798
|
+
'[lynx-ui-scroll-view][useBounce] flingEndWithBouncingEnableFlag early return',
|
|
799
|
+
)
|
|
770
800
|
return
|
|
771
801
|
}
|
|
772
802
|
if (Math.abs(currentVelocity) <= threshold()) {
|
|
773
803
|
flingEndWithBouncingEnableFlag.current = false
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
804
|
+
mtsLog(
|
|
805
|
+
debugLogEnabled,
|
|
806
|
+
'[lynx-ui-scroll-view][useBounce] fling to lower event end',
|
|
807
|
+
)
|
|
808
|
+
mtsLog(
|
|
809
|
+
debugLogEnabled,
|
|
810
|
+
'[lynx-ui-scroll-view][useBounce] bouncing to lower event start',
|
|
811
|
+
)
|
|
779
812
|
bouncingBack()
|
|
780
813
|
} else {
|
|
781
814
|
// step 1: fling
|
package/src/index.tsx
CHANGED
|
@@ -39,6 +39,7 @@ export const ScrollView = memo(forwardRef(ScrollViewImpl)) as ScrollViewType
|
|
|
39
39
|
|
|
40
40
|
const ScrollViewEventMapping: Record<string, string> = {
|
|
41
41
|
onContentSizeChange: 'bindcontentsizechanged',
|
|
42
|
+
onWheel: 'bindwheel',
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
/**
|
|
@@ -74,6 +75,8 @@ function ScrollViewImpl(
|
|
|
74
75
|
scrollOrientation,
|
|
75
76
|
lazyOptions,
|
|
76
77
|
className = '',
|
|
78
|
+
debugLog = false,
|
|
79
|
+
enableRTL = false,
|
|
77
80
|
bounceableOptions = {
|
|
78
81
|
enableBounces: true,
|
|
79
82
|
singleSidedBounce: 'iOSBounces',
|
|
@@ -104,6 +107,10 @@ function ScrollViewImpl(
|
|
|
104
107
|
props,
|
|
105
108
|
scrollViewRegisteredEvents.current,
|
|
106
109
|
)
|
|
110
|
+
const normalizedStyle: CSSProperties = {
|
|
111
|
+
zIndex: 0,
|
|
112
|
+
...style,
|
|
113
|
+
}
|
|
107
114
|
|
|
108
115
|
const isHorizontal = () => {
|
|
109
116
|
return scrollOrientation ? scrollOrientation === 'horizontal' : horizontal
|
|
@@ -208,7 +215,7 @@ function ScrollViewImpl(
|
|
|
208
215
|
: shouldEnableNested(),
|
|
209
216
|
'enable-new-nested': true,
|
|
210
217
|
'className': className,
|
|
211
|
-
'style':
|
|
218
|
+
'style': normalizedStyle,
|
|
212
219
|
'bounces': platformBounces,
|
|
213
220
|
'enable-scroll': enableScroll,
|
|
214
221
|
...(androidTouchSlop !== undefined
|
|
@@ -225,6 +232,8 @@ function ScrollViewImpl(
|
|
|
225
232
|
<ScrollViewWithBouncesHook
|
|
226
233
|
elementProps={elementProps}
|
|
227
234
|
bounceableOptions={bounceableProps}
|
|
235
|
+
debugLog={debugLog}
|
|
236
|
+
enableRTL={enableRTL}
|
|
228
237
|
sticky={sticky}
|
|
229
238
|
>
|
|
230
239
|
{renderChildren(children, normalizedLazyOptions)}
|
package/src/types/index.docs.ts
CHANGED
|
@@ -14,7 +14,7 @@ import type {
|
|
|
14
14
|
ComponentBasicProps,
|
|
15
15
|
LazyOptions,
|
|
16
16
|
} from '@lynx-js/lynx-ui-common'
|
|
17
|
-
import type { CSSProperties } from '@lynx-js/types'
|
|
17
|
+
import type { CSSProperties, CommonEvent } from '@lynx-js/types'
|
|
18
18
|
|
|
19
19
|
export type ScrollView = (props: ScrollViewProps) => ReactElement
|
|
20
20
|
|
|
@@ -212,6 +212,24 @@ export interface ScrollViewProps
|
|
|
212
212
|
* @iOS
|
|
213
213
|
*/
|
|
214
214
|
bounceableOptions?: boolean | BounceableBasicProps
|
|
215
|
+
/**
|
|
216
|
+
* Whether horizontal bounce direction should be mirrored in RTL mode.
|
|
217
|
+
* @zh 是否在 RTL 模式下镜像水平回弹方向。
|
|
218
|
+
* @defaultValue false
|
|
219
|
+
* @Android
|
|
220
|
+
* @iOS
|
|
221
|
+
* @Harmony
|
|
222
|
+
*/
|
|
223
|
+
enableRTL?: boolean
|
|
224
|
+
/**
|
|
225
|
+
* Display debug logs for bounce interactions.
|
|
226
|
+
* @zh 显示回弹交互的调试日志。
|
|
227
|
+
* @defaultValue false
|
|
228
|
+
* @Android
|
|
229
|
+
* @iOS
|
|
230
|
+
* @Harmony
|
|
231
|
+
*/
|
|
232
|
+
debugLog?: boolean
|
|
215
233
|
/**
|
|
216
234
|
* Controls whether scroll events propagate to parent containers. For now, 'preventPropagate' needs to be used together with temporaryBlockScrollClass and temporaryBlockScrollTag on iOS.
|
|
217
235
|
* @zh 控制滚动事件是否向父级容器传递。'preventPropagate' 在 iOS 上暂时需与 temporaryBlockScrollClass 和 temporaryBlockScrollTag 配合使用。
|
|
@@ -268,6 +286,14 @@ export interface ScrollViewProps
|
|
|
268
286
|
onContentSizeChange?: (res: {
|
|
269
287
|
detail: { scrollWidth: number, scrollHeight: number }
|
|
270
288
|
}) => void
|
|
289
|
+
/**
|
|
290
|
+
* Send when a wheel event is triggered on the scroll-view.
|
|
291
|
+
* @zh 当 scroll-view 触发滚轮事件时发送。
|
|
292
|
+
* @eventProperty
|
|
293
|
+
* @PC
|
|
294
|
+
* @Web
|
|
295
|
+
*/
|
|
296
|
+
onWheel?: (e: CommonEvent) => void
|
|
271
297
|
}
|
|
272
298
|
|
|
273
299
|
export interface scrollToBouncesInfo {
|
|
@@ -362,15 +388,6 @@ export interface BounceableBasicProps {
|
|
|
362
388
|
* @Harmony
|
|
363
389
|
*/
|
|
364
390
|
estimatedWidth?: number
|
|
365
|
-
/**
|
|
366
|
-
* Display debug logs. Open it when you find a bug.
|
|
367
|
-
* @zh 显示调试日志。当您发现错误时,请打开此选项。
|
|
368
|
-
* @defaultValue false
|
|
369
|
-
* @iOS
|
|
370
|
-
* @Android
|
|
371
|
-
* @Harmony
|
|
372
|
-
*/
|
|
373
|
-
debugLog?: boolean
|
|
374
391
|
/**
|
|
375
392
|
* requestAnimationFrame don't work under lynx version 2.15.2. This switch should be opened when the version is higher than 2.15.2.
|
|
376
393
|
* @zh `requestAnimationFrame` 在 lynx 2.15.2 以下版本中不起作用。当版本高于 2.15.2 时,应打开此开关。
|