@lynx-js/lynx-ui-scroll-view 0.0.0 → 3.131.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 +35 -0
- package/LICENSE +201 -0
- package/README.md +46 -0
- package/dist/ScrollViewBasic.d.ts +9 -0
- package/dist/ScrollViewBasic.d.ts.map +1 -0
- package/dist/ScrollViewBasic.jsx +11 -0
- package/dist/ScrollViewBasic.jsx.map +1 -0
- package/dist/ScrollViewWithBouncesHook.d.ts +13 -0
- package/dist/ScrollViewWithBouncesHook.d.ts.map +1 -0
- package/dist/ScrollViewWithBouncesHook.jsx +57 -0
- package/dist/ScrollViewWithBouncesHook.jsx.map +1 -0
- package/dist/hooks/useBounce.d.ts +43 -0
- package/dist/hooks/useBounce.d.ts.map +1 -0
- package/dist/hooks/useBounce.jsx +383 -0
- package/dist/hooks/useBounce.jsx.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.jsx +94 -0
- package/dist/index.jsx.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.docs.d.ts +364 -0
- package/dist/types/index.docs.d.ts.map +1 -0
- package/dist/types/index.docs.jsx +6 -0
- package/dist/types/index.docs.jsx.map +1 -0
- package/package.json +48 -4
- package/src/ScrollViewBasic.tsx +32 -0
- package/src/ScrollViewWithBouncesHook.tsx +150 -0
- package/src/hooks/useBounce.tsx +834 -0
- package/src/index.tsx +240 -0
- package/src/types/index.docs.ts +397 -0
- package/src/types/index.ts +5 -0
- package/tsconfig.docs.json +7 -0
- package/tsconfig.json +9 -0
- /package/{index.js → dist/types/index.jsx} +0 -0
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { runOnBackground, useMainThreadRef } from "@lynx-js/react";
|
|
2
|
+
import { selectorMT } from "@lynx-js/lynx-ui-common";
|
|
3
|
+
function useBounce(options) {
|
|
4
|
+
const rubberC = useMainThreadRef(0.55);
|
|
5
|
+
const flingDeceleratingRate = useMainThreadRef(0.99);
|
|
6
|
+
const beta = useMainThreadRef(15);
|
|
7
|
+
const debugLog = useMainThreadRef(options.bounceableOptions.debugLog ?? false);
|
|
8
|
+
const singleSidedBounce = useMainThreadRef(options.bounceableOptions.singleSidedBounce ?? 'both');
|
|
9
|
+
const startTouch = useMainThreadRef(null);
|
|
10
|
+
const prevTouch = useMainThreadRef(null);
|
|
11
|
+
const scrollVelocity = useMainThreadRef(0);
|
|
12
|
+
const bouncingPositionInfo = useMainThreadRef({});
|
|
13
|
+
const startBouncingTouch = useMainThreadRef(null);
|
|
14
|
+
const startTouchBouncingDelta = useMainThreadRef({});
|
|
15
|
+
const bouncingTouchStartPosition = useMainThreadRef({});
|
|
16
|
+
const prevScroll = useMainThreadRef({});
|
|
17
|
+
const height = useMainThreadRef(options.bounceableOptions.estimatedHeight ?? SystemInfo.pixelHeight / SystemInfo.pixelRatio);
|
|
18
|
+
const width = useMainThreadRef(options.bounceableOptions.estimatedWidth ?? SystemInfo.pixelWidth / SystemInfo.pixelRatio);
|
|
19
|
+
const scrollX = useMainThreadRef(0);
|
|
20
|
+
const scrollY = useMainThreadRef(0);
|
|
21
|
+
const touchEndFrameEnableFlag = useMainThreadRef(false);
|
|
22
|
+
const touchingEndBouncingBackEnableFlag = useMainThreadRef(false);
|
|
23
|
+
const flingEndWithBouncingEnableFlag = useMainThreadRef(false);
|
|
24
|
+
const toUpper = useMainThreadRef(false);
|
|
25
|
+
const toLower = useMainThreadRef(false);
|
|
26
|
+
const containerID = options.id ?? 'bounceableContainer';
|
|
27
|
+
const { enableBounces, onScrollToBounces } = options.bounceableOptions;
|
|
28
|
+
const alwaysBouncing = options.bounceableOptions.alwaysBouncing ?? false;
|
|
29
|
+
const scrollOrientation = options.scrollOrientation ?? 'vertical';
|
|
30
|
+
const enableBounceEventInFling = options.bounceableOptions.enableBounceEventInFling ?? true;
|
|
31
|
+
const startBounceTriggerDistance = options.bounceableOptions.startBounceTriggerDistance ?? 0;
|
|
32
|
+
const endBounceTriggerDistance = options.bounceableOptions.endBounceTriggerDistance ?? 0;
|
|
33
|
+
const temporaryValidVersionCheckForRAF = useMainThreadRef(options.bounceableOptions.validAnimationVersion ?? false);
|
|
34
|
+
const bouncingStatus = {
|
|
35
|
+
inScrollingRange: 0,
|
|
36
|
+
upperBouncing: 1,
|
|
37
|
+
lowerBouncing: 2,
|
|
38
|
+
noBouncing: 3,
|
|
39
|
+
alwaysBouncing: 4
|
|
40
|
+
};
|
|
41
|
+
function isVertical() {
|
|
42
|
+
'main thread';
|
|
43
|
+
return 'vertical' === scrollOrientation;
|
|
44
|
+
}
|
|
45
|
+
function threshold() {
|
|
46
|
+
'main thread';
|
|
47
|
+
return 1.0 / Number(SystemInfo.pixelRatio);
|
|
48
|
+
}
|
|
49
|
+
function isAndroid() {
|
|
50
|
+
'main thread';
|
|
51
|
+
return 'Android' === SystemInfo.platform;
|
|
52
|
+
}
|
|
53
|
+
function isEmpty(obj) {
|
|
54
|
+
'main thread';
|
|
55
|
+
return !obj || 0 === Object.keys(obj).length;
|
|
56
|
+
}
|
|
57
|
+
function enableScroll(enable) {
|
|
58
|
+
'main thread';
|
|
59
|
+
if (isAndroid()) selectorMT(containerID)?.setAttribute('enable-scroll', enable);
|
|
60
|
+
}
|
|
61
|
+
function clearTouchInfo() {
|
|
62
|
+
'main thread';
|
|
63
|
+
if (debugLog.current) console.info('clearTouchInfo');
|
|
64
|
+
startTouch.current = null;
|
|
65
|
+
bouncingTouchStartPosition.current = 0;
|
|
66
|
+
prevTouch.current = null;
|
|
67
|
+
startBouncingTouch.current = null;
|
|
68
|
+
startTouchBouncingDelta.current = 0;
|
|
69
|
+
}
|
|
70
|
+
function customRequestAnimationFrame(animationFunc) {
|
|
71
|
+
'main thread';
|
|
72
|
+
if (temporaryValidVersionCheckForRAF.current) requestAnimationFrame(animationFunc);
|
|
73
|
+
else setTimeout(animationFunc, 8);
|
|
74
|
+
}
|
|
75
|
+
function getCurrentDelta(event) {
|
|
76
|
+
'main thread';
|
|
77
|
+
if (null !== startTouch.current) if (null === startBouncingTouch.current) return 'vertical' === scrollOrientation ? event.touches[0].pageY - startTouch.current[0].pageY : event.touches[0].pageX - startTouch.current[0].pageX;
|
|
78
|
+
else return 'vertical' === scrollOrientation ? event.touches[0].pageY - startBouncingTouch.current[0].pageY : event.touches[0].pageX - startBouncingTouch.current[0].pageX;
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
function getBouncingStatus() {
|
|
82
|
+
'main thread';
|
|
83
|
+
const currentPosition = bouncingPositionInfo.current?.bouncingOffset ?? 0;
|
|
84
|
+
if (Boolean(toUpper.current) && Boolean(toLower.current)) return alwaysBouncing ? bouncingStatus.alwaysBouncing : bouncingStatus.noBouncing;
|
|
85
|
+
const initialLayoutPosition = 0;
|
|
86
|
+
if (debugLog.current) console.info('getBouncingStatus', initialLayoutPosition, 'currentPosition', currentPosition);
|
|
87
|
+
if (currentPosition > initialLayoutPosition) return bouncingStatus.upperBouncing;
|
|
88
|
+
if (currentPosition < initialLayoutPosition) return bouncingStatus.lowerBouncing;
|
|
89
|
+
return bouncingStatus.inScrollingRange;
|
|
90
|
+
}
|
|
91
|
+
function shouldBounceWhenTouchEnd(status) {
|
|
92
|
+
'main thread';
|
|
93
|
+
if (status === bouncingStatus.inScrollingRange || status === bouncingStatus.noBouncing) return false;
|
|
94
|
+
if (status === bouncingStatus.upperBouncing || status === bouncingStatus.lowerBouncing) return true;
|
|
95
|
+
if (status === bouncingStatus.alwaysBouncing) return alwaysBouncing;
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
function bouncingSetStyle(offset) {
|
|
99
|
+
'main thread';
|
|
100
|
+
if (isNaN(Number(offset))) return void console.info('ERROR! bouncingOffset is NaN');
|
|
101
|
+
if (isEmpty(bouncingPositionInfo.current)) bouncingPositionInfo.current.velocity = 0;
|
|
102
|
+
else {
|
|
103
|
+
const timeDiff = Date.now() - bouncingPositionInfo.current.timeStamp;
|
|
104
|
+
const offsetDiff = offset - bouncingPositionInfo.current.bouncingOffset || 0;
|
|
105
|
+
if (timeDiff > 0) bouncingPositionInfo.current.velocity = offsetDiff / timeDiff;
|
|
106
|
+
}
|
|
107
|
+
bouncingPositionInfo.current.bouncingOffset = offset;
|
|
108
|
+
bouncingPositionInfo.current.timeStamp = Date.now();
|
|
109
|
+
if (0 === offset && null !== prevTouch.current) {
|
|
110
|
+
startTouch.current = prevTouch.current;
|
|
111
|
+
bouncingTouchStartPosition.current = {};
|
|
112
|
+
}
|
|
113
|
+
if (isVertical()) {
|
|
114
|
+
selectorMT(containerID)?.setStyleProperty('transform', `translateY(${offset}px)`);
|
|
115
|
+
selectorMT(`${containerID}-upperBounceWrapper`)?.setStyleProperty('transform', `translateY(${offset}px)`);
|
|
116
|
+
selectorMT(`${containerID}-lowerBounceWrapper`)?.setStyleProperty('transform', `translateY(${offset}px)`);
|
|
117
|
+
} else {
|
|
118
|
+
selectorMT(containerID)?.setStyleProperty('transform', `translateX(${offset}px)`);
|
|
119
|
+
selectorMT(`${containerID}-upperBounceWrapper`)?.setStyleProperty('transform', `translateX(${offset}px)`);
|
|
120
|
+
selectorMT(`${containerID}-lowerBounceWrapper`)?.setStyleProperty('transform', `translateX(${offset}px)`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function onScrollToBouncesJS(info) {
|
|
124
|
+
if (enableBounces && onScrollToBounces) onScrollToBounces(info);
|
|
125
|
+
}
|
|
126
|
+
function triggerScrollToBouncesEvent(isUpper) {
|
|
127
|
+
'main thread';
|
|
128
|
+
if (debugLog.current) console.info('triggerScrollToBouncesEvent', isUpper ? 'upper' : 'lower');
|
|
129
|
+
const info = {
|
|
130
|
+
direction: isUpper ? 'upper' : 'lower'
|
|
131
|
+
};
|
|
132
|
+
runOnBackground(onScrollToBouncesJS)(info);
|
|
133
|
+
}
|
|
134
|
+
function rubberEffect(isNegative, delta) {
|
|
135
|
+
'main thread';
|
|
136
|
+
const scrollViewFrameSize = isVertical() ? height.current : width.current;
|
|
137
|
+
const touchStartPosition = Math.abs(Number(isEmpty(startTouchBouncingDelta.current) ? bouncingTouchStartPosition.current : startTouchBouncingDelta.current));
|
|
138
|
+
const deltaYForTouchStartPosition = scrollViewFrameSize * touchStartPosition / ((scrollViewFrameSize - touchStartPosition) * rubberC.current) || 0;
|
|
139
|
+
const deltaYForNextPosition = bouncingTouchStartPosition.current ? deltaYForTouchStartPosition + isNegative * delta : isNegative * delta;
|
|
140
|
+
const rubberBandingDistance = Math.max(0, (1.0 - 1.0 / (deltaYForNextPosition * rubberC.current / scrollViewFrameSize + 1.0)) * scrollViewFrameSize);
|
|
141
|
+
if (debugLog.current) console.info('rubberEffect', 'scrollViewFrameSize', scrollViewFrameSize, 'touchStartPosition', touchStartPosition, 'deltaYForTouchStartPosition', deltaYForTouchStartPosition, 'deltaYForNextPosition', deltaYForNextPosition, 'rubberBandingDistance', rubberBandingDistance);
|
|
142
|
+
bouncingSetStyle(isNegative * rubberBandingDistance);
|
|
143
|
+
}
|
|
144
|
+
function triggerRubberEffectIfCrossingEdge(event) {
|
|
145
|
+
'main thread';
|
|
146
|
+
const delta = getCurrentDelta(event);
|
|
147
|
+
if (debugLog.current) console.info('isCrossingEdge', 'delta', delta, 'toUpper', toUpper.current, 'toLower', toLower.current);
|
|
148
|
+
if (true === toUpper.current && delta > 0 && ('both' === singleSidedBounce.current || 'upper' === singleSidedBounce.current)) {
|
|
149
|
+
enableScroll(false);
|
|
150
|
+
rubberEffect(delta > 0 ? 1 : -1, delta);
|
|
151
|
+
}
|
|
152
|
+
if (true === toLower.current && delta < 0 && ('both' === singleSidedBounce.current || 'lower' === singleSidedBounce.current)) {
|
|
153
|
+
enableScroll(false);
|
|
154
|
+
rubberEffect(delta > 0 ? 1 : -1, delta);
|
|
155
|
+
}
|
|
156
|
+
enableScroll(true);
|
|
157
|
+
}
|
|
158
|
+
function isOverTriggerDistance() {
|
|
159
|
+
'main thread';
|
|
160
|
+
const bouncingTop = bouncingPositionInfo.current.bouncingOffset ?? 0;
|
|
161
|
+
const triggerDistance = bouncingPositionInfo.current?.bouncingOffset > 0 ? startBounceTriggerDistance : endBounceTriggerDistance;
|
|
162
|
+
const delta = Math.abs(bouncingTop) - Math.abs(triggerDistance);
|
|
163
|
+
return delta > threshold();
|
|
164
|
+
}
|
|
165
|
+
function bouncingBack() {
|
|
166
|
+
'main thread';
|
|
167
|
+
if (debugLog.current) {
|
|
168
|
+
console.info('fling forward end');
|
|
169
|
+
console.info('bounce back starts');
|
|
170
|
+
}
|
|
171
|
+
const C1 = bouncingPositionInfo.current.bouncingOffset ?? 0;
|
|
172
|
+
const startTime = Date.now();
|
|
173
|
+
const touchingEndBouncingBackFrame = ()=>{
|
|
174
|
+
if (false === Boolean(touchingEndBouncingBackEnableFlag.current)) return;
|
|
175
|
+
const currentTime = Date.now() - startTime;
|
|
176
|
+
if (debugLog.current) console.info('touchingEndBouncingBackFrame');
|
|
177
|
+
const C2 = beta.current * C1;
|
|
178
|
+
const easedDistance = (C1 + currentTime / 1000 * C2) * Math.pow(Math.E, -beta.current * (currentTime / 1000));
|
|
179
|
+
bouncingSetStyle(easedDistance);
|
|
180
|
+
if (Math.abs(easedDistance) < threshold()) {
|
|
181
|
+
bouncingSetStyle(0);
|
|
182
|
+
if (debugLog.current) console.info('bounce back ends');
|
|
183
|
+
} else customRequestAnimationFrame(touchingEndBouncingBackFrame);
|
|
184
|
+
};
|
|
185
|
+
customRequestAnimationFrame(touchingEndBouncingBackFrame);
|
|
186
|
+
touchingEndBouncingBackEnableFlag.current = true;
|
|
187
|
+
}
|
|
188
|
+
function bounceableTouchStart(event) {
|
|
189
|
+
'main thread';
|
|
190
|
+
startTouch.current = event.touches;
|
|
191
|
+
if (debugLog.current) console.info('bounceableTouchStart');
|
|
192
|
+
bouncingTouchStartPosition.current = bouncingPositionInfo.current?.bouncingOffset ?? 0;
|
|
193
|
+
touchEndFrameEnableFlag.current = false;
|
|
194
|
+
touchingEndBouncingBackEnableFlag.current = false;
|
|
195
|
+
flingEndWithBouncingEnableFlag.current = false;
|
|
196
|
+
}
|
|
197
|
+
function bounceableTouchMove(event) {
|
|
198
|
+
'main thread';
|
|
199
|
+
prevTouch.current = event.touches;
|
|
200
|
+
if (null === startTouch.current) console.info('ERROR! touch not started');
|
|
201
|
+
else {
|
|
202
|
+
const delta = getCurrentDelta(event);
|
|
203
|
+
const currentBouncingStatus = getBouncingStatus();
|
|
204
|
+
switch(currentBouncingStatus){
|
|
205
|
+
case bouncingStatus.upperBouncing:
|
|
206
|
+
enableScroll(false);
|
|
207
|
+
rubberEffect(1, delta);
|
|
208
|
+
if (debugLog.current) console.info('bounceableTouchMove upperBouncing');
|
|
209
|
+
break;
|
|
210
|
+
case bouncingStatus.lowerBouncing:
|
|
211
|
+
enableScroll(false);
|
|
212
|
+
rubberEffect(-1, delta);
|
|
213
|
+
if (debugLog.current) console.info('bounceableTouchMove lowerBouncing');
|
|
214
|
+
break;
|
|
215
|
+
case bouncingStatus.alwaysBouncing:
|
|
216
|
+
if (debugLog.current) console.info('bounceableTouchMove alwaysBouncing');
|
|
217
|
+
if (alwaysBouncing) triggerRubberEffectIfCrossingEdge(event);
|
|
218
|
+
break;
|
|
219
|
+
case bouncingStatus.inScrollingRange:
|
|
220
|
+
if (debugLog.current) console.info('bounceableTouchMove inScrollingRange');
|
|
221
|
+
triggerRubberEffectIfCrossingEdge(event);
|
|
222
|
+
break;
|
|
223
|
+
default:
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function bounceableTouchEnd() {
|
|
229
|
+
'main thread';
|
|
230
|
+
clearTouchInfo();
|
|
231
|
+
enableScroll(true);
|
|
232
|
+
if (debugLog.current) console.info('bounceableTouchEnd');
|
|
233
|
+
if (shouldBounceWhenTouchEnd(getBouncingStatus())) {
|
|
234
|
+
const startTime = Date.now();
|
|
235
|
+
const dragEndVelocity = bouncingPositionInfo.current?.velocity;
|
|
236
|
+
const dragEndPosition = bouncingPositionInfo.current?.bouncingOffset ?? 0;
|
|
237
|
+
if (isOverTriggerDistance()) triggerScrollToBouncesEvent(bouncingPositionInfo.current?.bouncingOffset > 0);
|
|
238
|
+
let currentVelocity = dragEndVelocity;
|
|
239
|
+
const touchEndProcessFrame = ()=>{
|
|
240
|
+
if (false === Boolean(touchEndFrameEnableFlag.current)) return;
|
|
241
|
+
if (debugLog.current) console.info('touchEndProcessFrame');
|
|
242
|
+
if (Math.abs(currentVelocity) <= threshold()) bouncingBack();
|
|
243
|
+
else {
|
|
244
|
+
if (debugLog.current) console.info('fling down start');
|
|
245
|
+
const distance = dragEndPosition + dragEndVelocity * (Math.pow(flingDeceleratingRate.current, Date.now() - startTime) - 1) / Math.log(flingDeceleratingRate.current);
|
|
246
|
+
bouncingSetStyle(distance);
|
|
247
|
+
currentVelocity = dragEndVelocity * Math.pow(flingDeceleratingRate.current, Date.now() - startTime);
|
|
248
|
+
if (touchEndFrameEnableFlag.current) customRequestAnimationFrame(touchEndProcessFrame);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
customRequestAnimationFrame(touchEndProcessFrame);
|
|
252
|
+
touchEndFrameEnableFlag.current = true;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function bounceableHandleScroll(event) {
|
|
256
|
+
'main thread';
|
|
257
|
+
scrollX.current = event.detail.scrollLeft;
|
|
258
|
+
scrollY.current = event.detail.scrollTop;
|
|
259
|
+
if (!isEmpty(prevScroll.current)) {
|
|
260
|
+
const timeDuration = Date.now() - prevScroll.current.timestamp;
|
|
261
|
+
if (timeDuration > 0) {
|
|
262
|
+
const deltaY = isVertical() ? event.detail.scrollTop - prevScroll.current.detail.scrollTop : event.detail.scrollLeft - prevScroll.current.detail.scrollLeft;
|
|
263
|
+
const velocity = deltaY / timeDuration;
|
|
264
|
+
if (Number.isFinite(velocity)) scrollVelocity.current = velocity;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
prevScroll.current = event;
|
|
268
|
+
}
|
|
269
|
+
function onUpperDisexposure(_event) {
|
|
270
|
+
'main thread';
|
|
271
|
+
if (debugLog.current) console.info('upper disexposure');
|
|
272
|
+
toUpper.current = false;
|
|
273
|
+
}
|
|
274
|
+
function onUpperExposure(_event) {
|
|
275
|
+
'main thread';
|
|
276
|
+
if (debugLog.current) console.info('upper exposure');
|
|
277
|
+
toUpper.current = true;
|
|
278
|
+
if ('upper' !== singleSidedBounce.current && 'both' !== singleSidedBounce.current) return;
|
|
279
|
+
if (prevScroll.current) {
|
|
280
|
+
startBouncingTouch.current = prevTouch.current;
|
|
281
|
+
startTouchBouncingDelta.current = bouncingPositionInfo.current?.bouncingOffset ?? 0;
|
|
282
|
+
} else if (Math.abs(scrollVelocity.current) > threshold()) {
|
|
283
|
+
const velocity = scrollVelocity.current;
|
|
284
|
+
let currentVelocity = velocity;
|
|
285
|
+
const startTime = Date.now();
|
|
286
|
+
if (debugLog.current) console.info('fling to upper event start with velocity', velocity);
|
|
287
|
+
let sentScrollToBouncesEvent = false;
|
|
288
|
+
const flingEndWithBouncingFrame = ()=>{
|
|
289
|
+
if (false === Boolean(flingEndWithBouncingEnableFlag.current)) {
|
|
290
|
+
if (debugLog.current) console.info('flingEndWithBouncingEnableFlag early return');
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (Math.abs(currentVelocity) <= threshold()) {
|
|
294
|
+
flingEndWithBouncingEnableFlag.current = false;
|
|
295
|
+
if (debugLog.current) {
|
|
296
|
+
console.info('fling to upper event end');
|
|
297
|
+
console.info('bouncing to upper event start');
|
|
298
|
+
}
|
|
299
|
+
bouncingBack();
|
|
300
|
+
} else {
|
|
301
|
+
const distance = currentVelocity * (Math.pow(flingDeceleratingRate.current, Date.now() - startTime) - 1) / Math.log(flingDeceleratingRate.current);
|
|
302
|
+
bouncingSetStyle(-distance);
|
|
303
|
+
if (!sentScrollToBouncesEvent && isOverTriggerDistance()) {
|
|
304
|
+
triggerScrollToBouncesEvent(bouncingPositionInfo.current?.bouncingOffset > 0);
|
|
305
|
+
sentScrollToBouncesEvent = true;
|
|
306
|
+
}
|
|
307
|
+
currentVelocity = velocity * Math.pow(flingDeceleratingRate.current, Date.now() - startTime);
|
|
308
|
+
if (flingEndWithBouncingEnableFlag.current) customRequestAnimationFrame(flingEndWithBouncingFrame);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
customRequestAnimationFrame(flingEndWithBouncingFrame);
|
|
312
|
+
flingEndWithBouncingEnableFlag.current = true;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function onLowerDisexposure(_event) {
|
|
316
|
+
'main thread';
|
|
317
|
+
if (debugLog.current) console.info('lower disexposure');
|
|
318
|
+
toLower.current = false;
|
|
319
|
+
}
|
|
320
|
+
function onLowerExposure(_event) {
|
|
321
|
+
'main thread';
|
|
322
|
+
if (debugLog.current) console.info('lower exposure');
|
|
323
|
+
toLower.current = true;
|
|
324
|
+
if ('lower' !== singleSidedBounce.current && 'both' !== singleSidedBounce.current) return;
|
|
325
|
+
if (null !== prevTouch.current) {
|
|
326
|
+
startBouncingTouch.current = prevTouch.current;
|
|
327
|
+
startTouchBouncingDelta.current = bouncingPositionInfo.current?.bouncingOffset ?? 0;
|
|
328
|
+
} else if (enableBounceEventInFling && scrollVelocity.current > 0) {
|
|
329
|
+
const velocity = scrollVelocity.current;
|
|
330
|
+
if (debugLog.current) console.info('lower velocity', velocity);
|
|
331
|
+
if (Math.abs(velocity) > threshold()) {
|
|
332
|
+
let currentVelocity = velocity;
|
|
333
|
+
const startTime = Date.now();
|
|
334
|
+
if (debugLog.current) console.info('fling to lower event start with velocity', velocity);
|
|
335
|
+
let sentScrollToBouncesEvent = false;
|
|
336
|
+
const flingEndWithBouncingFrame = ()=>{
|
|
337
|
+
if (false === Boolean(flingEndWithBouncingEnableFlag.current)) {
|
|
338
|
+
if (debugLog.current) console.info('flingEndWithBouncingEnableFlag early return');
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (Math.abs(currentVelocity) <= threshold()) {
|
|
342
|
+
flingEndWithBouncingEnableFlag.current = false;
|
|
343
|
+
if (debugLog.current) {
|
|
344
|
+
console.info('fling to lower event end');
|
|
345
|
+
console.info('bouncing to lower event start');
|
|
346
|
+
}
|
|
347
|
+
bouncingBack();
|
|
348
|
+
} else {
|
|
349
|
+
const distance = currentVelocity * (Math.pow(flingDeceleratingRate.current, Date.now() - startTime) - 1) / Math.log(flingDeceleratingRate.current);
|
|
350
|
+
bouncingSetStyle(-distance);
|
|
351
|
+
if (!sentScrollToBouncesEvent && isOverTriggerDistance()) {
|
|
352
|
+
triggerScrollToBouncesEvent(bouncingPositionInfo.current?.bouncingOffset > 0);
|
|
353
|
+
sentScrollToBouncesEvent = true;
|
|
354
|
+
}
|
|
355
|
+
currentVelocity = velocity * Math.pow(flingDeceleratingRate.current, Date.now() - startTime);
|
|
356
|
+
if (flingEndWithBouncingEnableFlag) customRequestAnimationFrame(flingEndWithBouncingFrame);
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
customRequestAnimationFrame(flingEndWithBouncingFrame);
|
|
360
|
+
flingEndWithBouncingEnableFlag.current = true;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function bounceableLayoutChange(event) {
|
|
365
|
+
'main thread';
|
|
366
|
+
height.current = (isAndroid() ? event.params?.height : event.detail?.height) ?? 0;
|
|
367
|
+
width.current = (isAndroid() ? event.params?.width : event.detail?.width) ?? 0;
|
|
368
|
+
}
|
|
369
|
+
return {
|
|
370
|
+
'main-thread:bindtouchstart': bounceableTouchStart,
|
|
371
|
+
'main-thread:bindtouchend': bounceableTouchEnd,
|
|
372
|
+
'main-thread:bindtouchmove': bounceableTouchMove,
|
|
373
|
+
'main-thread:bindlayoutchange': bounceableLayoutChange,
|
|
374
|
+
'main-thread:bindscroll': bounceableHandleScroll,
|
|
375
|
+
onUpperExposure,
|
|
376
|
+
onUpperDisexposure,
|
|
377
|
+
onLowerExposure,
|
|
378
|
+
onLowerDisexposure
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
export { useBounce };
|
|
382
|
+
|
|
383
|
+
//# sourceMappingURL=useBounce.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks/useBounce.jsx","sources":["webpack://@lynx-js/lynx-ui-scroll-view/./src/hooks/useBounce.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { runOnBackground, useMainThreadRef } from '@lynx-js/react'\n\nimport { selectorMT } from '@lynx-js/lynx-ui-common'\nimport type { CommonEvent, MainThread, ScrollEvent } from '@lynx-js/types'\n\nexport interface scrollToBouncesInfo {\n direction: 'upper' | 'lower'\n}\n\nexport interface BounceableBasicProps {\n enableBounces: boolean\n enableBounceEventInFling?: boolean\n startBounceTriggerDistance?: number\n endBounceTriggerDistance?: number\n // biome-ignore lint/suspicious/noExplicitAny: expected\n upperBounceItem?: any\n // biome-ignore lint/suspicious/noExplicitAny: expected\n lowerBounceItem?: any\n alwaysBouncing?: boolean\n singleSidedBounce?: 'upper' | 'lower' | 'both' | 'iOSBounces' | 'none'\n estimatedHeight?: number\n estimatedWidth?: number\n debugLog?: boolean\n validAnimationVersion?: boolean\n onScrollToBounces?: (e: scrollToBouncesInfo) => void\n}\n\nexport interface useBounceOptions {\n bounceableOptions: BounceableBasicProps\n /**\n * idSelector of scroll container\n */\n id?: string\n /**\n * scroll direction\n */\n scrollOrientation: 'vertical' | 'horizontal'\n}\n\nexport interface bounceHandlers {\n 'main-thread:bindtouchstart': (event: MainThread.TouchEvent) => void\n 'main-thread:bindtouchend': () => void\n 'main-thread:bindtouchmove': (event: MainThread.TouchEvent) => void\n 'main-thread:bindlayoutchange': (event: CommonEvent) => void\n 'main-thread:bindscroll': (event: ScrollEvent) => void\n onUpperExposure: (_event: CommonEvent) => void\n onUpperDisexposure: (_event: CommonEvent) => void\n onLowerExposure: (_event: CommonEvent) => void\n onLowerDisexposure: (_event: CommonEvent) => void\n}\n\nexport function useBounce(options: useBounceOptions): bounceHandlers {\n // Control the damping coefficient during rubber effect. The smaller it is, the harder the spring effect.\n const rubberC = useMainThreadRef(0.55)\n // Control the fling deceleration coefficient during dropdown. The smaller it is, the faster it stops.\n const flingDeceleratingRate = useMainThreadRef(0.99)\n // The rebound coefficient during bounce back, the larger it is, the faster the rebound speed.\n const beta = useMainThreadRef(15)\n\n const debugLog = useMainThreadRef(\n options.bounceableOptions.debugLog ?? false,\n )\n\n const singleSidedBounce = useMainThreadRef(\n options.bounceableOptions.singleSidedBounce ?? 'both',\n )\n\n // The starting point of current touch procedure\n const startTouch = useMainThreadRef<MainThread.TouchEvent['touches'] | null>(\n null,\n )\n // Record the previous touch and clear it on touchEnd. If current is not empty, then it means that the scrollable object is being dragged.\n const prevTouch = useMainThreadRef<MainThread.TouchEvent['touches'] | null>(\n null,\n )\n\n // Current scroll velocity.\n const scrollVelocity = useMainThreadRef(0)\n // Current bouncing position.\n const bouncingPositionInfo = useMainThreadRef({})\n\n // If reaches edge and bouncing starts during dragging, save the touch point and calculate later touch delta for rubberEffect.\n const startBouncingTouch = useMainThreadRef<\n MainThread.TouchEvent['touches'] | null\n >(null)\n // If reaches edge and bouncing starts during dragging, save current bouncingPosition and continues rubberEffect's calculation from this point.\n const startTouchBouncingDelta = useMainThreadRef({})\n // when touch starts during bouncing, save current bouncingPosition and continues rubberEffect's calculation from this point.\n const bouncingTouchStartPosition = useMainThreadRef({})\n\n // Used to record the previous scroll position and calculate current scroll velocity.\n const prevScroll = useMainThreadRef({})\n\n // scroll container's basic info.\n const height = useMainThreadRef(\n options.bounceableOptions.estimatedHeight\n ?? SystemInfo.pixelHeight / SystemInfo.pixelRatio,\n )\n const width = useMainThreadRef(\n options.bounceableOptions.estimatedWidth\n ?? SystemInfo.pixelWidth / SystemInfo.pixelRatio,\n )\n const scrollX = useMainThreadRef(0)\n const scrollY = useMainThreadRef(0)\n\n // Flags for ending bouncing animation.\n const touchEndFrameEnableFlag = useMainThreadRef(false)\n const touchingEndBouncingBackEnableFlag = useMainThreadRef(false)\n const flingEndWithBouncingEnableFlag = useMainThreadRef(false)\n\n // Flags for reaches upper/lower edge.\n // When content's size is smaller than viewport, these two flags are both true.\n const toUpper = useMainThreadRef(false)\n const toLower = useMainThreadRef(false)\n\n // Read from props\n const containerID = options.id ?? 'bounceableContainer'\n const { enableBounces, onScrollToBounces } = options.bounceableOptions\n const alwaysBouncing = options.bounceableOptions.alwaysBouncing ?? false\n const scrollOrientation = options.scrollOrientation ?? 'vertical'\n const enableBounceEventInFling =\n options.bounceableOptions.enableBounceEventInFling ?? true\n const startBounceTriggerDistance =\n options.bounceableOptions.startBounceTriggerDistance ?? 0\n const endBounceTriggerDistance =\n options.bounceableOptions.endBounceTriggerDistance ?? 0\n // Temporary workaround as requestAnimationFrame will crash below Lynx 2.15.2.\n const temporaryValidVersionCheckForRAF = useMainThreadRef(\n options.bounceableOptions.validAnimationVersion ?? false,\n )\n\n const bouncingStatus = {\n inScrollingRange: 0,\n upperBouncing: 1,\n lowerBouncing: 2,\n noBouncing: 3,\n alwaysBouncing: 4,\n }\n\n function isVertical() {\n 'main thread'\n return scrollOrientation === 'vertical'\n }\n\n function threshold() {\n 'main thread'\n return 1.0 / Number(SystemInfo.pixelRatio)\n }\n\n function isAndroid() {\n 'main thread'\n return SystemInfo.platform === 'Android'\n }\n\n function isEmpty(obj: Record<string, unknown>) {\n 'main thread'\n return !obj || Object.keys(obj).length === 0\n }\n\n function enableScroll(enable: boolean) {\n 'main thread'\n // Android will trigger scroll during bouncing, cancel it while bouncing.\n if (isAndroid()) {\n selectorMT(containerID)?.setAttribute('enable-scroll', enable)\n }\n }\n\n // Clear all temps when a touch procedure ends.\n function clearTouchInfo() {\n 'main thread'\n if (debugLog.current) {\n console.info('clearTouchInfo')\n }\n startTouch.current = null\n bouncingTouchStartPosition.current = 0\n prevTouch.current = null\n startBouncingTouch.current = null\n startTouchBouncingDelta.current = 0\n }\n\n // Temporary workaround as requestAnimationFrame will crash below Lynx 2.15.2.\n function customRequestAnimationFrame(animationFunc: () => void) {\n 'main thread'\n if (temporaryValidVersionCheckForRAF.current) {\n requestAnimationFrame(animationFunc)\n } else {\n setTimeout(animationFunc, 8)\n }\n }\n\n // Calculate current touch delta based on 'startPoint'. The startPoint here should be startBouncingTouch which means this bouncing effect happens during a touch procedure.\n function getCurrentDelta(event: MainThread.TouchEvent) {\n 'main thread'\n if (startTouch.current !== null) {\n if (startBouncingTouch.current === null) {\n return scrollOrientation === 'vertical'\n ? event.touches[0].pageY - startTouch.current[0].pageY\n : event.touches[0].pageX - startTouch.current[0].pageX\n } else {\n return scrollOrientation === 'vertical'\n ? event.touches[0].pageY - startBouncingTouch.current[0].pageY\n : event.touches[0].pageX - startBouncingTouch.current[0].pageX\n }\n }\n return 0\n }\n\n // Key bouncing status judgement.\n function getBouncingStatus() {\n 'main thread'\n // @ts-expect-error Expected\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const currentPosition = bouncingPositionInfo.current?.bouncingOffset ?? 0\n if (Boolean(toUpper.current) && Boolean(toLower.current)) {\n return alwaysBouncing\n ? bouncingStatus.alwaysBouncing\n : bouncingStatus.noBouncing\n }\n\n // upper bouncing\n const initialLayoutPosition = 0\n if (debugLog.current) {\n console.info(\n 'getBouncingStatus',\n initialLayoutPosition,\n 'currentPosition',\n currentPosition,\n )\n }\n\n if (currentPosition > initialLayoutPosition) {\n return bouncingStatus.upperBouncing\n }\n\n // bottom bouncing\n if (currentPosition < initialLayoutPosition) {\n return bouncingStatus.lowerBouncing\n }\n return bouncingStatus.inScrollingRange\n }\n\n // Whether fling and bouncing back step should be triggered.\n function shouldBounceWhenTouchEnd(status: number) {\n 'main thread'\n if (\n status === bouncingStatus.inScrollingRange\n || status === bouncingStatus.noBouncing\n ) {\n return false\n }\n\n if (\n status === bouncingStatus.upperBouncing\n || status === bouncingStatus.lowerBouncing\n ) {\n return true\n }\n\n if (status === bouncingStatus.alwaysBouncing) {\n return alwaysBouncing\n }\n return false\n }\n\n // Use translate to implement real bouncing effect\n function bouncingSetStyle(offset: number) {\n 'main thread'\n if (isNaN(Number(offset))) {\n console.info('ERROR! bouncingOffset is NaN')\n return\n }\n // update bouncingPositionInfo first\n if (isEmpty(bouncingPositionInfo.current)) {\n // @ts-expect-error expected\n bouncingPositionInfo.current.velocity = 0\n } else {\n // @ts-expect-error expected\n const timeDiff = Date.now() - bouncingPositionInfo.current.timeStamp\n // @ts-expect-error expected\n const offsetDiff = offset - bouncingPositionInfo.current.bouncingOffset\n || 0\n if (timeDiff > 0) {\n // @ts-expect-error expected\n bouncingPositionInfo.current.velocity = offsetDiff / timeDiff\n }\n // If timeDiff <= 0, we keep the previous velocity to maintain momentum continuity.\n }\n // @ts-expect-error expected\n bouncingPositionInfo.current.bouncingOffset = offset\n // @ts-expect-error expected\n bouncingPositionInfo.current.timeStamp = Date.now()\n // When bouncing effect ends, clear startTouch and bouncingTouchStartPosition\n if (offset === 0 && prevTouch.current !== null) {\n startTouch.current = prevTouch.current\n bouncingTouchStartPosition.current = {}\n }\n // trigger translate\n if (isVertical()) {\n selectorMT(containerID)?.setStyleProperty(\n 'transform',\n `translateY(${offset}px)`,\n )\n selectorMT(`${containerID}-upperBounceWrapper`)?.setStyleProperty(\n 'transform',\n `translateY(${offset}px)`,\n )\n selectorMT(`${containerID}-lowerBounceWrapper`)?.setStyleProperty(\n 'transform',\n `translateY(${offset}px)`,\n )\n } else {\n selectorMT(containerID)?.setStyleProperty(\n 'transform',\n `translateX(${offset}px)`,\n )\n selectorMT(`${containerID}-upperBounceWrapper`)?.setStyleProperty(\n 'transform',\n `translateX(${offset}px)`,\n )\n selectorMT(`${containerID}-lowerBounceWrapper`)?.setStyleProperty(\n 'transform',\n `translateX(${offset}px)`,\n )\n }\n }\n\n function onScrollToBouncesJS(info: scrollToBouncesInfo) {\n if (enableBounces && onScrollToBounces) {\n onScrollToBounces(info)\n }\n }\n\n // send the scrollToBounces event\n function triggerScrollToBouncesEvent(isUpper: boolean) {\n 'main thread'\n if (debugLog.current) {\n console.info('triggerScrollToBouncesEvent', isUpper ? 'upper' : 'lower')\n }\n\n const info: scrollToBouncesInfo = {\n direction: isUpper ? 'upper' : 'lower',\n }\n runOnBackground(onScrollToBouncesJS)(info)\n }\n\n function rubberEffect(isNegative: 1 | -1, delta: number) {\n 'main thread'\n const scrollViewFrameSize = isVertical() ? height.current : width.current\n // If the touchStartPosition is not zero, it means this rubber effect happens during a touch or another bouncing effect. So the real 'start delta' should be recalculated.\n const touchStartPosition = Math.abs(\n Number(\n isEmpty(startTouchBouncingDelta.current)\n ? bouncingTouchStartPosition.current\n : startTouchBouncingDelta.current,\n ),\n )\n // This deltaYForTouchStartPosition is the inverse function of rubberEffect function\n const deltaYForTouchStartPosition =\n (scrollViewFrameSize * touchStartPosition)\n / ((scrollViewFrameSize - touchStartPosition) * rubberC.current) || 0\n // Here it calculate the next touchDelta. deltaYForNextPosition = (touch point where bouncing happens + corresponding touch delta where previous bouncing position locates)\n // This isNegative is used to handle the upper/lower bounce. RubberEffect function is different in the range (-inf,0) and [0, inf). We only use the [0, inf) part.\n const deltaYForNextPosition = bouncingTouchStartPosition.current\n ? deltaYForTouchStartPosition + isNegative * delta\n : isNegative * delta\n // Real calculation. Note that we don't use the raw touchDelta for calculating, instead, we use deltaYForNextPosition.\n const rubberBandingDistance = Math.max(\n 0,\n (1.0\n - 1.0\n / ((deltaYForNextPosition * rubberC.current) / scrollViewFrameSize\n + 1.0))\n * scrollViewFrameSize,\n )\n if (debugLog.current) {\n console.info(\n 'rubberEffect',\n 'scrollViewFrameSize',\n scrollViewFrameSize,\n 'touchStartPosition',\n touchStartPosition,\n 'deltaYForTouchStartPosition',\n deltaYForTouchStartPosition,\n 'deltaYForNextPosition',\n deltaYForNextPosition,\n 'rubberBandingDistance',\n rubberBandingDistance,\n )\n }\n\n bouncingSetStyle(isNegative * rubberBandingDistance)\n }\n\n function triggerRubberEffectIfCrossingEdge(event: MainThread.TouchEvent) {\n 'main thread'\n const delta = getCurrentDelta(event)\n if (debugLog.current) {\n console.info(\n 'isCrossingEdge',\n 'delta',\n delta,\n 'toUpper',\n toUpper.current,\n 'toLower',\n toLower.current,\n )\n }\n\n // Crossing top range\n if (\n toUpper.current === true && delta > 0\n && (singleSidedBounce.current === 'both'\n || singleSidedBounce.current === 'upper')\n ) {\n enableScroll(false)\n rubberEffect(delta > 0 ? 1 : -1, delta)\n }\n\n // Crossing bottom range\n if (\n toLower.current === true && delta < 0\n && (singleSidedBounce.current === 'both'\n || singleSidedBounce.current === 'lower')\n ) {\n enableScroll(false)\n rubberEffect(delta > 0 ? 1 : -1, delta)\n }\n enableScroll(true)\n }\n\n // return true if scrollToBounces should be sent\n function isOverTriggerDistance() {\n 'main thread'\n // @ts-expect-error expected\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const bouncingTop: number = bouncingPositionInfo.current.bouncingOffset ?? 0\n const triggerDistance =\n // @ts-expect-error expected\n bouncingPositionInfo.current?.bouncingOffset > 0\n ? startBounceTriggerDistance\n : endBounceTriggerDistance\n const delta = Math.abs(bouncingTop) - Math.abs(triggerDistance)\n return delta > threshold()\n }\n\n function bouncingBack() {\n 'main thread'\n if (debugLog.current) {\n console.info('fling forward end')\n\n console.info('bounce back starts')\n }\n\n // step3: bounce back\n // @ts-expect-error expected\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const C1 = bouncingPositionInfo.current.bouncingOffset ?? 0\n const startTime = Date.now()\n const touchingEndBouncingBackFrame = () => {\n if (Boolean(touchingEndBouncingBackEnableFlag.current) === false) {\n return\n }\n const currentTime = Date.now() - startTime\n if (debugLog.current) {\n console.info('touchingEndBouncingBackFrame')\n }\n\n // critical damping\n const C2 = beta.current * C1\n const easedDistance = (C1 + C2 * (currentTime / 1000))\n * Math.pow(Math.E, -beta.current * (currentTime / 1000))\n bouncingSetStyle(easedDistance)\n if (Math.abs(easedDistance) < threshold()) {\n // Make sure it backs to 0\n bouncingSetStyle(0)\n if (debugLog.current) {\n console.info('bounce back ends')\n }\n } else {\n customRequestAnimationFrame(touchingEndBouncingBackFrame)\n }\n }\n\n customRequestAnimationFrame(touchingEndBouncingBackFrame)\n touchingEndBouncingBackEnableFlag.current = true\n }\n\n // bindtouchstart. Save startTouch and bouncingPosition if a bouncing effect is happening.\n function bounceableTouchStart(event: MainThread.TouchEvent) {\n 'main thread'\n startTouch.current = event.touches\n if (debugLog.current) {\n console.info('bounceableTouchStart')\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n bouncingTouchStartPosition.current =\n // @ts-expect-error expected\n bouncingPositionInfo.current?.bouncingOffset ?? 0\n // reset all animation flags. No animation should play during a touch.\n touchEndFrameEnableFlag.current = false\n touchingEndBouncingBackEnableFlag.current = false\n flingEndWithBouncingEnableFlag.current = false\n }\n\n function bounceableTouchMove(event: MainThread.TouchEvent) {\n 'main thread'\n prevTouch.current = event.touches\n if (startTouch.current === null) {\n // It means current situation is illegal. A touchMove event happens without a touchStart event beforehand. Or a touchMove event happens after a touchEnd event.\n console.info('ERROR! touch not started')\n } else {\n const delta = getCurrentDelta(event)\n const currentBouncingStatus = getBouncingStatus()\n // Judge the status and trigger rubberEffect. The TouchMove should only consider rubberEffect and nothing else.\n switch (currentBouncingStatus) {\n case bouncingStatus.upperBouncing: {\n enableScroll(false)\n rubberEffect(1, delta)\n if (debugLog.current) {\n console.info('bounceableTouchMove upperBouncing')\n }\n break\n }\n case bouncingStatus.lowerBouncing: {\n enableScroll(false)\n rubberEffect(-1, delta)\n if (debugLog.current) {\n console.info('bounceableTouchMove lowerBouncing')\n }\n break\n }\n case bouncingStatus.alwaysBouncing: {\n if (debugLog.current) {\n console.info('bounceableTouchMove alwaysBouncing')\n }\n if (alwaysBouncing) {\n triggerRubberEffectIfCrossingEdge(event)\n }\n break\n }\n case bouncingStatus.inScrollingRange: {\n if (debugLog.current) {\n console.info('bounceableTouchMove inScrollingRange')\n }\n triggerRubberEffectIfCrossingEdge(event)\n break\n }\n default:\n break\n }\n }\n }\n\n // bindtouchend. In touchEnd event the fling forward animation and bouncingBack animation should be triggered if necessary.\n function bounceableTouchEnd() {\n 'main thread'\n // Reset the state. The touch information should be reset, and we should no longer ban the enable-scroll.\n clearTouchInfo()\n enableScroll(true)\n if (debugLog.current) {\n console.info('bounceableTouchEnd')\n }\n if (shouldBounceWhenTouchEnd(getBouncingStatus())) {\n const startTime = Date.now()\n // @ts-expect-error expected\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const dragEndVelocity = bouncingPositionInfo.current?.velocity\n // @ts-expect-error expected\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const dragEndPosition = bouncingPositionInfo.current?.bouncingOffset ?? 0\n // Send scrolltobounces event.\n if (isOverTriggerDistance()) {\n triggerScrollToBouncesEvent(\n // @ts-expect-error expected\n bouncingPositionInfo.current?.bouncingOffset > 0,\n )\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n let currentVelocity: number = dragEndVelocity\n const touchEndProcessFrame = () => {\n if (Boolean(touchEndFrameEnableFlag.current) === false) {\n return\n }\n if (debugLog.current) {\n console.info('touchEndProcessFrame')\n }\n if (Math.abs(currentVelocity) <= threshold()) {\n // If the velocity is already under threshold, skip fling and start step3: bounce back.\n bouncingBack()\n } else {\n // If the drag end with a velocity, start fling to consume it.\n // step 2: fling down\n if (debugLog.current) {\n console.info('fling down start')\n }\n // This function is obtained by integrating the velocity function with a deceleration rate of flingDeceleratingRate.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const distance: number = dragEndPosition\n + (dragEndVelocity\n * (Math.pow(\n flingDeceleratingRate.current,\n Date.now() - startTime,\n )\n - 1))\n / Math.log(flingDeceleratingRate.current)\n bouncingSetStyle(distance)\n currentVelocity = dragEndVelocity\n * Math.pow(flingDeceleratingRate.current, Date.now() - startTime)\n if (touchEndFrameEnableFlag.current) {\n customRequestAnimationFrame(touchEndProcessFrame)\n }\n }\n }\n customRequestAnimationFrame(touchEndProcessFrame)\n touchEndFrameEnableFlag.current = true\n }\n }\n\n // Save the bindscroll info and calculate velocity.\n function bounceableHandleScroll(event: ScrollEvent) {\n 'main thread'\n scrollX.current = event.detail.scrollLeft\n scrollY.current = event.detail.scrollTop\n if (!isEmpty(prevScroll.current)) {\n // @ts-expect-error expected\n const timeDuration = Date.now() - prevScroll.current.timestamp\n if (timeDuration > 0) {\n const deltaY = isVertical() // @ts-expect-error expected\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n ? event.detail.scrollTop - prevScroll.current.detail.scrollTop // @ts-expect-error expected\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n : event.detail.scrollLeft - prevScroll.current.detail.scrollLeft\n const velocity = deltaY / timeDuration\n if (Number.isFinite(velocity)) {\n scrollVelocity.current = velocity\n }\n }\n }\n prevScroll.current = event\n }\n\n function onUpperDisexposure(_event: CommonEvent) {\n 'main thread'\n if (debugLog.current) {\n console.info('upper disexposure')\n }\n toUpper.current = false\n }\n\n // Handle scrolltoupper event.\n function onUpperExposure(_event: CommonEvent) {\n 'main thread'\n if (debugLog.current) {\n console.info('upper exposure')\n }\n toUpper.current = true\n if (\n singleSidedBounce.current !== 'upper'\n && singleSidedBounce.current !== 'both'\n ) {\n return\n }\n if (prevScroll.current) {\n // reaches edge during touch\n startBouncingTouch.current = prevTouch.current\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n startTouchBouncingDelta.current =\n // @ts-expect-error expected\n bouncingPositionInfo.current?.bouncingOffset ?? 0\n } else if (Math.abs(scrollVelocity.current) > threshold()) {\n // reaches edge during fling\n const velocity = scrollVelocity.current\n let currentVelocity = velocity\n const startTime = Date.now()\n if (debugLog.current) {\n console.info('fling to upper event start with velocity', velocity)\n }\n let sentScrollToBouncesEvent = false // only sent scrollToBounces once\n const flingEndWithBouncingFrame = () => {\n if (Boolean(flingEndWithBouncingEnableFlag.current) === false) {\n if (debugLog.current) {\n console.info('flingEndWithBouncingEnableFlag early return')\n }\n return\n }\n if (Math.abs(currentVelocity) <= threshold()) {\n flingEndWithBouncingEnableFlag.current = false\n if (debugLog.current) {\n console.info('fling to upper event end')\n\n console.info('bouncing to upper event start')\n }\n bouncingBack()\n } else {\n // step 1: fling\n const distance = (currentVelocity\n * (Math.pow(flingDeceleratingRate.current, Date.now() - startTime)\n - 1))\n / Math.log(flingDeceleratingRate.current)\n bouncingSetStyle(-distance)\n if (!sentScrollToBouncesEvent && isOverTriggerDistance()) {\n triggerScrollToBouncesEvent(\n // @ts-expect-error expected\n bouncingPositionInfo.current?.bouncingOffset > 0,\n )\n sentScrollToBouncesEvent = true\n }\n currentVelocity = velocity\n * Math.pow(flingDeceleratingRate.current, Date.now() - startTime)\n if (flingEndWithBouncingEnableFlag.current) {\n customRequestAnimationFrame(flingEndWithBouncingFrame)\n }\n }\n }\n customRequestAnimationFrame(flingEndWithBouncingFrame)\n flingEndWithBouncingEnableFlag.current = true\n }\n }\n\n function onLowerDisexposure(_event: CommonEvent) {\n 'main thread'\n if (debugLog.current) {\n console.info('lower disexposure')\n }\n toLower.current = false\n }\n\n function onLowerExposure(_event: CommonEvent) {\n 'main thread'\n if (debugLog.current) {\n console.info('lower exposure')\n }\n toLower.current = true\n if (\n singleSidedBounce.current !== 'lower'\n && singleSidedBounce.current !== 'both'\n ) {\n return\n }\n // reaches lower during dragging\n if (prevTouch.current !== null) {\n startBouncingTouch.current = prevTouch.current\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n startTouchBouncingDelta.current =\n // @ts-expect-error expected\n bouncingPositionInfo.current?.bouncingOffset ?? 0\n } else if (enableBounceEventInFling && scrollVelocity.current > 0) {\n const velocity = scrollVelocity.current\n if (debugLog.current) {\n console.info('lower velocity', velocity)\n }\n\n // scroll to end with velocity, start bouncing effect\n if (Math.abs(velocity) > threshold()) {\n let currentVelocity = velocity\n const startTime = Date.now()\n if (debugLog.current) {\n console.info('fling to lower event start with velocity', velocity)\n }\n let sentScrollToBouncesEvent = false // only sent scrollToBounces once\n const flingEndWithBouncingFrame = () => {\n if (Boolean(flingEndWithBouncingEnableFlag.current) === false) {\n if (debugLog.current) {\n console.info('flingEndWithBouncingEnableFlag early return')\n }\n return\n }\n if (Math.abs(currentVelocity) <= threshold()) {\n flingEndWithBouncingEnableFlag.current = false\n if (debugLog.current) {\n console.info('fling to lower event end')\n\n console.info('bouncing to lower event start')\n }\n bouncingBack()\n } else {\n // step 1: fling\n const distance = (currentVelocity\n * (Math.pow(\n flingDeceleratingRate.current,\n Date.now() - startTime,\n )\n - 1))\n / Math.log(flingDeceleratingRate.current)\n bouncingSetStyle(-distance)\n if (!sentScrollToBouncesEvent && isOverTriggerDistance()) {\n triggerScrollToBouncesEvent(\n // @ts-expect-error expected\n bouncingPositionInfo.current?.bouncingOffset > 0,\n )\n sentScrollToBouncesEvent = true\n }\n currentVelocity = velocity\n * Math.pow(flingDeceleratingRate.current, Date.now() - startTime)\n if (flingEndWithBouncingEnableFlag) {\n customRequestAnimationFrame(flingEndWithBouncingFrame)\n }\n }\n }\n customRequestAnimationFrame(flingEndWithBouncingFrame)\n flingEndWithBouncingEnableFlag.current = true\n }\n }\n }\n\n // Used to get the size of scroll container.\n function bounceableLayoutChange(event: CommonEvent) {\n 'main thread'\n // @ts-expect-error expected\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n height.current = (isAndroid() ? event.params?.height : event.detail?.height)\n ?? 0\n // @ts-expect-error expected\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access\n width.current = (isAndroid() ? event.params?.width : event.detail?.width)\n ?? 0\n }\n\n return {\n 'main-thread:bindtouchstart': bounceableTouchStart,\n 'main-thread:bindtouchend': bounceableTouchEnd,\n 'main-thread:bindtouchmove': bounceableTouchMove,\n 'main-thread:bindlayoutchange': bounceableLayoutChange,\n 'main-thread:bindscroll': bounceableHandleScroll,\n onUpperExposure,\n onUpperDisexposure,\n onLowerExposure,\n onLowerDisexposure,\n }\n}\n"],"names":["useBounce","options","rubberC","useMainThreadRef","flingDeceleratingRate","beta","debugLog","singleSidedBounce","startTouch","prevTouch","scrollVelocity","bouncingPositionInfo","startBouncingTouch","startTouchBouncingDelta","bouncingTouchStartPosition","prevScroll","height","SystemInfo","width","scrollX","scrollY","touchEndFrameEnableFlag","touchingEndBouncingBackEnableFlag","flingEndWithBouncingEnableFlag","toUpper","toLower","containerID","enableBounces","onScrollToBounces","alwaysBouncing","scrollOrientation","enableBounceEventInFling","startBounceTriggerDistance","endBounceTriggerDistance","temporaryValidVersionCheckForRAF","bouncingStatus","isVertical","threshold","Number","isAndroid","isEmpty","obj","Object","enableScroll","enable","selectorMT","clearTouchInfo","console","customRequestAnimationFrame","animationFunc","requestAnimationFrame","setTimeout","getCurrentDelta","event","getBouncingStatus","currentPosition","Boolean","initialLayoutPosition","shouldBounceWhenTouchEnd","status","bouncingSetStyle","offset","isNaN","timeDiff","Date","offsetDiff","onScrollToBouncesJS","info","triggerScrollToBouncesEvent","isUpper","runOnBackground","rubberEffect","isNegative","delta","scrollViewFrameSize","touchStartPosition","Math","deltaYForTouchStartPosition","deltaYForNextPosition","rubberBandingDistance","triggerRubberEffectIfCrossingEdge","isOverTriggerDistance","bouncingTop","triggerDistance","bouncingBack","C1","startTime","touchingEndBouncingBackFrame","currentTime","C2","easedDistance","bounceableTouchStart","bounceableTouchMove","currentBouncingStatus","bounceableTouchEnd","dragEndVelocity","dragEndPosition","currentVelocity","touchEndProcessFrame","distance","bounceableHandleScroll","timeDuration","deltaY","velocity","onUpperDisexposure","_event","onUpperExposure","sentScrollToBouncesEvent","flingEndWithBouncingFrame","onLowerDisexposure","onLowerExposure","bounceableLayoutChange"],"mappings":";;AAuDO,SAASA,UAAUC,OAAyB;IAEjD,MAAMC,UAAUC,iB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|
|
2
|
+
import type { ScrollViewProps, ScrollViewRef, ScrollView as ScrollViewType } from './types';
|
|
3
|
+
export type { ScrollViewProps, ScrollViewRef };
|
|
4
|
+
export { useBounce } from './hooks/useBounce';
|
|
5
|
+
export type { bounceHandlers } from './hooks/useBounce';
|
|
6
|
+
export type { BounceableBasicProps } from './types';
|
|
7
|
+
export declare const ScrollView: ScrollViewType;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAOA,OAAO,0BAA0B,CAAA;AAkBjC,OAAO,KAAK,EAEV,eAAe,EACf,aAAa,EACb,UAAU,IAAI,cAAc,EAC7B,MAAM,SAAS,CAAA;AAEhB,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,YAAY,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAEnD,eAAO,MAAM,UAAU,EAAuC,cAAc,CAAA"}
|
package/dist/index.jsx
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { forwardRef, memo, useRef } from "@lynx-js/react";
|
|
2
|
+
import "@lynx-js/gesture-runtime";
|
|
3
|
+
import { ExposureEventsMapping, LayoutEventsMapping, ScrollEventsMapping, TouchEventsMapping, useRegisteredEvents } from "@lynx-js/lynx-ui-common";
|
|
4
|
+
import { LazyComponent } from "@lynx-js/lynx-ui-lazy-component";
|
|
5
|
+
import ScrollViewBasic from "./ScrollViewBasic.jsx";
|
|
6
|
+
import ScrollViewWithBouncesHook from "./ScrollViewWithBouncesHook.jsx";
|
|
7
|
+
import { useBounce } from "./hooks/useBounce.jsx";
|
|
8
|
+
const ScrollView = memo(forwardRef(ScrollViewImpl));
|
|
9
|
+
const ScrollViewEventMapping = {
|
|
10
|
+
onContentSizeChange: 'bindcontentsizechanged'
|
|
11
|
+
};
|
|
12
|
+
function ScrollViewImpl(props, _ref) {
|
|
13
|
+
const { scrollviewId = 'scrollview', horizontal = false, style, children, scrollOrientation, lazyOptions, className = '', bounceableOptions = {
|
|
14
|
+
enableBounces: true,
|
|
15
|
+
singleSidedBounce: 'iOSBounces'
|
|
16
|
+
}, enableScroll = true, enableScrollMonitor = false, scrollMonitorTag, sticky, scrollPropagationBehavior = 'native', temporaryBlockScrollClass = 'BDXLynxViewPager', temporaryBlockScrollTag = 0, temporaryNestedScroll, androidTouchSlop, 'main-thread:gesture': gesture } = props;
|
|
17
|
+
const scrollViewRegisteredEvents = useRef({
|
|
18
|
+
...ScrollEventsMapping,
|
|
19
|
+
...ExposureEventsMapping,
|
|
20
|
+
...TouchEventsMapping,
|
|
21
|
+
...LayoutEventsMapping,
|
|
22
|
+
...ScrollViewEventMapping
|
|
23
|
+
});
|
|
24
|
+
const normalizedLazyOptions = lazyOptions ? {
|
|
25
|
+
firstScreenItemCount: 1,
|
|
26
|
+
...lazyOptions
|
|
27
|
+
} : void 0;
|
|
28
|
+
const registerEvents = useRegisteredEvents(props, scrollViewRegisteredEvents.current);
|
|
29
|
+
const isHorizontal = ()=>scrollOrientation ? 'horizontal' === scrollOrientation : horizontal;
|
|
30
|
+
let enableBounce = false;
|
|
31
|
+
let bounceableProps = {
|
|
32
|
+
enableBounces: false
|
|
33
|
+
};
|
|
34
|
+
if ('boolean' == typeof bounceableOptions) {
|
|
35
|
+
enableBounce = bounceableOptions;
|
|
36
|
+
bounceableProps = {
|
|
37
|
+
enableBounces: enableBounce,
|
|
38
|
+
singleSidedBounce: 'both',
|
|
39
|
+
alwaysBouncing: true,
|
|
40
|
+
validAnimationVersion: true
|
|
41
|
+
};
|
|
42
|
+
} else if ('object' == typeof bounceableOptions) {
|
|
43
|
+
enableBounce = bounceableOptions.enableBounces;
|
|
44
|
+
bounceableProps = bounceableOptions;
|
|
45
|
+
bounceableProps.singleSidedBounce = bounceableOptions.singleSidedBounce ?? 'both';
|
|
46
|
+
bounceableProps.alwaysBouncing = bounceableOptions.alwaysBouncing ?? true;
|
|
47
|
+
bounceableProps.validAnimationVersion = bounceableOptions.validAnimationVersion ?? true;
|
|
48
|
+
}
|
|
49
|
+
const platformBounces = enableBounce && bounceableProps?.singleSidedBounce === 'iOSBounces';
|
|
50
|
+
const shouldEnableNested = ()=>{
|
|
51
|
+
if ('iOS' === SystemInfo.platform && 'propagate' !== scrollPropagationBehavior) return false;
|
|
52
|
+
return true;
|
|
53
|
+
};
|
|
54
|
+
const renderChildren = (children, lazyOptions)=>{
|
|
55
|
+
if (!Array.isArray(children)) return children;
|
|
56
|
+
const lazy = lazyOptions?.enableLazy;
|
|
57
|
+
return children.map((item, index)=>{
|
|
58
|
+
if (lazy && index >= Number(lazyOptions?.firstScreenItemCount)) return <LazyComponent key={`${scrollviewId}_lazy_${index}`} scene={lazyOptions?.scene} pid={`pid_${index}`} estimatedStyle={lazyOptions?.estimatedItemStyle} top={lazyOptions?.exposureTop} bottom={lazyOptions?.exposureBottom} left={lazyOptions?.exposureLeft} right={lazyOptions?.exposureRight}>
|
|
59
|
+
{item}
|
|
60
|
+
</LazyComponent>;
|
|
61
|
+
return item;
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
const elementProps = {
|
|
65
|
+
id: scrollviewId,
|
|
66
|
+
'scroll-x': isHorizontal(),
|
|
67
|
+
'scroll-y': !isHorizontal(),
|
|
68
|
+
'enable-scroll-monitor': enableScrollMonitor,
|
|
69
|
+
'scroll-monitor-tag': scrollMonitorTag,
|
|
70
|
+
'main-thread:gesture': gesture,
|
|
71
|
+
'force-can-scroll': 'preventPropagate' === scrollPropagationBehavior,
|
|
72
|
+
'ios-block-gesture-class': 'preventPropagate' === scrollPropagationBehavior ? temporaryBlockScrollClass : '',
|
|
73
|
+
'ios-recognized-view-tag': 'preventPropagate' === scrollPropagationBehavior ? temporaryBlockScrollTag : 0,
|
|
74
|
+
'enable-nested-scroll': 'Android' === SystemInfo.platform ? temporaryNestedScroll ?? true : shouldEnableNested(),
|
|
75
|
+
'enable-new-nested': true,
|
|
76
|
+
className: className,
|
|
77
|
+
style: style,
|
|
78
|
+
bounces: platformBounces,
|
|
79
|
+
'enable-scroll': enableScroll,
|
|
80
|
+
...void 0 !== androidTouchSlop && {
|
|
81
|
+
'android-touch-slop': androidTouchSlop
|
|
82
|
+
},
|
|
83
|
+
...registerEvents
|
|
84
|
+
};
|
|
85
|
+
if (enableBounce && 'iOSBounces' !== bounceableProps.singleSidedBounce && 'none' !== bounceableProps.singleSidedBounce) return <ScrollViewWithBouncesHook elementProps={elementProps} bounceableOptions={bounceableProps} sticky={sticky}>
|
|
86
|
+
{renderChildren(children, normalizedLazyOptions)}
|
|
87
|
+
</ScrollViewWithBouncesHook>;
|
|
88
|
+
return <ScrollViewBasic elementProps={elementProps} sticky={sticky}>
|
|
89
|
+
{renderChildren(children, normalizedLazyOptions)}
|
|
90
|
+
</ScrollViewBasic>;
|
|
91
|
+
}
|
|
92
|
+
export { ScrollView, useBounce };
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=index.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.jsx","sources":["webpack://@lynx-js/lynx-ui-scroll-view/./src/index.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { forwardRef, memo, useRef } from '@lynx-js/react'\nimport type { ForwardedRef, ReactNode } from '@lynx-js/react'\n\nimport '@lynx-js/gesture-runtime'\nimport type { GestureKind } from '@lynx-js/gesture-runtime'\nimport type { LazyOptions } from '@lynx-js/lynx-ui-common'\nimport {\n ExposureEventsMapping,\n LayoutEventsMapping,\n ScrollEventsMapping,\n TouchEventsMapping,\n useRegisteredEvents,\n} from '@lynx-js/lynx-ui-common'\nimport { LazyComponent } from '@lynx-js/lynx-ui-lazy-component'\nimport type {\n CSSProperties,\n ScrollViewProps as ScrollViewElementProps,\n} from '@lynx-js/types'\n\nimport ScrollViewBasic from './ScrollViewBasic'\nimport ScrollViewWithBouncesHook from './ScrollViewWithBouncesHook'\nimport type {\n BounceableBasicProps,\n ScrollViewProps,\n ScrollViewRef,\n ScrollView as ScrollViewType,\n} from './types'\n\nexport type { ScrollViewProps, ScrollViewRef }\nexport { useBounce } from './hooks/useBounce'\nexport type { bounceHandlers } from './hooks/useBounce'\nexport type { BounceableBasicProps } from './types'\n\nexport const ScrollView = memo(forwardRef(ScrollViewImpl)) as ScrollViewType\n\nconst ScrollViewEventMapping: Record<string, string> = {\n onContentSizeChange: 'bindcontentsizechanged',\n}\n\n/**\n * @example\n * ```javascript\n * <ScrollView\n scene={`viewpager_${index1}`}\n style={{ width: '100%', height: '100%' }}\n estimatedItemStyle={{ width: '100%', height: '800px' }}\n scrollOrientation='vertical'\n exposureRight=\"50px\"\n exposureBottom=\"220px\"\n >\n {scrollview.map((item, index) => (\n <view\n style={`width:100%;height:580rpx;`}\n >\n <text>{`slot-${index}`}</text>\n </view>\n ))}\n </ScrollView>\n * ```\n */\nfunction ScrollViewImpl(\n props: ScrollViewProps,\n _ref: ForwardedRef<ScrollViewRef>,\n) {\n const {\n scrollviewId = 'scrollview',\n horizontal = false,\n style,\n children,\n scrollOrientation,\n lazyOptions,\n className = '',\n bounceableOptions = {\n enableBounces: true,\n singleSidedBounce: 'iOSBounces',\n },\n enableScroll = true,\n enableScrollMonitor = false,\n scrollMonitorTag,\n sticky,\n scrollPropagationBehavior = 'native',\n temporaryBlockScrollClass = 'BDXLynxViewPager',\n temporaryBlockScrollTag = 0,\n temporaryNestedScroll,\n androidTouchSlop,\n 'main-thread:gesture': gesture,\n } = props\n // generates binding events dynamically\n const scrollViewRegisteredEvents = useRef<Record<string, string>>({\n ...ScrollEventsMapping,\n ...ExposureEventsMapping,\n ...TouchEventsMapping,\n ...LayoutEventsMapping,\n ...ScrollViewEventMapping,\n })\n const normalizedLazyOptions: LazyOptions | undefined = lazyOptions\n ? { firstScreenItemCount: 1, ...lazyOptions }\n : undefined\n const registerEvents = useRegisteredEvents(\n props,\n scrollViewRegisteredEvents.current,\n )\n\n const isHorizontal = () => {\n return scrollOrientation ? scrollOrientation === 'horizontal' : horizontal\n }\n\n // Initialize bounceableProps\n let enableBounce = false\n let bounceableProps: BounceableBasicProps = { enableBounces: false }\n if (typeof bounceableOptions === 'boolean') {\n // Initialize the default value if the bounceableOptions is simply 'true' without specific options\n enableBounce = bounceableOptions\n bounceableProps = {\n enableBounces: enableBounce,\n singleSidedBounce: 'both',\n alwaysBouncing: true,\n validAnimationVersion: true,\n }\n } else if (typeof bounceableOptions === 'object') {\n enableBounce = bounceableOptions.enableBounces\n bounceableProps = bounceableOptions\n bounceableProps.singleSidedBounce = bounceableOptions.singleSidedBounce\n ?? 'both'\n bounceableProps.alwaysBouncing = bounceableOptions.alwaysBouncing ?? true\n bounceableProps.validAnimationVersion =\n bounceableOptions.validAnimationVersion ?? true\n }\n // Only when the enableBounces is true and singleSidedBounce is set to 'iOSBounces' will it use default bounces effect on iOS.\n const platformBounces = enableBounce\n && bounceableProps?.singleSidedBounce === 'iOSBounces'\n\n const shouldEnableNested = () => {\n if (\n SystemInfo.platform === 'iOS' && scrollPropagationBehavior !== 'propagate'\n ) {\n return false\n }\n return true\n }\n\n const renderChildren = (\n children: ReactNode,\n lazyOptions: LazyOptions | undefined,\n ) => {\n if (!Array.isArray(children)) {\n return children\n }\n const lazy = lazyOptions?.enableLazy\n return children.map((item: ReactNode, index: number) => {\n if (lazy && index >= Number(lazyOptions?.firstScreenItemCount)) {\n return (\n <LazyComponent\n key={`${scrollviewId}_lazy_${index}`}\n scene={lazyOptions?.scene}\n pid={`pid_${index}`}\n estimatedStyle={lazyOptions?.estimatedItemStyle}\n top={lazyOptions?.exposureTop}\n bottom={lazyOptions?.exposureBottom}\n left={lazyOptions?.exposureLeft}\n right={lazyOptions?.exposureRight}\n >\n {item}\n </LazyComponent>\n )\n }\n return item\n })\n }\n\n // These props will be spread directly to <scroll-view> element. Make sure it's valid\n type ExtendedScrollViewElementProps = ScrollViewElementProps & {\n 'scroll-x': boolean\n 'scroll-y': boolean\n }\n const elementProps: ExtendedScrollViewElementProps & {\n 'enable-scroll-monitor': boolean\n 'scroll-monitor-tag'?: string\n 'main-thread:gesture'?: GestureKind\n 'enable-new-nested'?: boolean\n 'enable-nested-scroll'?: boolean\n 'force-can-scroll'?: boolean\n 'ios-block-gesture-class'?: string\n 'ios-recognized-view-tag'?: number\n 'className'?: string\n 'style'?: CSSProperties\n 'bounces'?: boolean\n } = {\n 'id': scrollviewId,\n 'scroll-x': isHorizontal(),\n 'scroll-y': !isHorizontal(),\n 'enable-scroll-monitor': enableScrollMonitor,\n 'scroll-monitor-tag': scrollMonitorTag,\n 'main-thread:gesture': gesture as GestureKind,\n 'force-can-scroll': scrollPropagationBehavior === 'preventPropagate',\n 'ios-block-gesture-class': scrollPropagationBehavior === 'preventPropagate'\n ? temporaryBlockScrollClass\n : '',\n 'ios-recognized-view-tag': scrollPropagationBehavior === 'preventPropagate'\n ? temporaryBlockScrollTag\n : 0,\n 'enable-nested-scroll': SystemInfo.platform === 'Android'\n ? (temporaryNestedScroll ?? true)\n : shouldEnableNested(),\n 'enable-new-nested': true,\n 'className': className,\n 'style': style,\n 'bounces': platformBounces,\n 'enable-scroll': enableScroll,\n ...(androidTouchSlop !== undefined\n && { 'android-touch-slop': androidTouchSlop }),\n ...registerEvents,\n }\n\n if (\n enableBounce\n && bounceableProps.singleSidedBounce !== 'iOSBounces'\n && bounceableProps.singleSidedBounce !== 'none'\n ) {\n return (\n <ScrollViewWithBouncesHook\n elementProps={elementProps}\n bounceableOptions={bounceableProps}\n sticky={sticky}\n >\n {renderChildren(children, normalizedLazyOptions)}\n </ScrollViewWithBouncesHook>\n )\n } else {\n return (\n <ScrollViewBasic elementProps={elementProps} sticky={sticky}>\n {renderChildren(children, normalizedLazyOptions)}\n </ScrollViewBasic>\n )\n }\n}\n"],"names":["ScrollView","memo","forwardRef","ScrollViewImpl","ScrollViewEventMapping","props","_ref","scrollviewId","horizontal","style","children","scrollOrientation","lazyOptions","className","bounceableOptions","enableScroll","enableScrollMonitor","scrollMonitorTag","sticky","scrollPropagationBehavior","temporaryBlockScrollClass","temporaryBlockScrollTag","temporaryNestedScroll","androidTouchSlop","gesture","scrollViewRegisteredEvents","useRef","ScrollEventsMapping","ExposureEventsMapping","TouchEventsMapping","LayoutEventsMapping","normalizedLazyOptions","undefined","registerEvents","useRegisteredEvents","isHorizontal","enableBounce","bounceableProps","platformBounces","shouldEnableNested","SystemInfo","renderChildren","Array","lazy","item","index","Number","LazyComponent","elementProps","ScrollViewWithBouncesHook","ScrollViewBasic"],"mappings":";;;;;;;AAqCO,MAAMA,aAAaC,KAAKC,WAAWC;AAE1C,MAAMC,yBAAiD;IACrD,qBAAqB;AACvB;AAuBA,SAASD,eACPE,KAAsB,EACtBC,IAAiC;IAEjC,MAAM,EACJC,eAAe,YAAY,EAC3BC,aAAa,KAAK,EAClBC,KAAK,EACLC,QAAQ,EACRC,iBAAiB,EACjBC,WAAW,EACXC,YAAY,EAAE,EACdC,oBAAoB;QAClB,eAAe;QACf,mBAAmB;IACrB,CAAC,EACDC,eAAe,IAAI,EACnBC,sBAAsB,KAAK,EAC3BC,gBAAgB,EAChBC,MAAM,EACNC,4BAA4B,QAAQ,EACpCC,4BAA4B,kBAAkB,EAC9CC,0BAA0B,CAAC,EAC3BC,qBAAqB,EACrBC,gBAAgB,EAChB,uBAAuBC,OAAO,EAC/B,GAAGnB;IAEJ,MAAMoB,6BAA6BC,OAA+B;QAChE,GAAGC,mBAAmB;QACtB,GAAGC,qBAAqB;QACxB,GAAGC,kBAAkB;QACrB,GAAGC,mBAAmB;QACtB,GAAG1B,sBAAsB;IAC3B;IACA,MAAM2B,wBAAiDnB,cACnD;QAAE,sBAAsB;QAAG,GAAGA,WAAW;IAAC,I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,OAAOH;QACT;IACF;IAOA,MAAMI,eAYF;QACF,IAAMzC;QACN,YAAY4B;QACZ,YAAY,CAACA;QACb,yBAAyBnB;QACzB,sBAAsBC;QACtB,uBAAuBO;QACvB,oBAAoBL,AAA8B,uBAA9BA;QACpB,2BAA2BA,AAA8B,uBAA9BA,4BACvBC,4BACA;QACJ,2BAA2BD,AAA8B,uBAA9BA,4BACvBE,0BACA;QACJ,wBAAwBmB,AAAwB,cAAxBA,WAAW,QAAQ,GACtClB,yBAAyB,OAC1BiB;QACJ,qBAAqB;QACrB,WAAa1B;QACb,OAASJ;QACT,SAAW6B;QACX,iBAAiBvB;QACjB,GAAIQ,AAAqBS,WAArBT,oBACC;YAAE,sBAAsBA;QAAiB,CAAC;QAC/C,GAAGU,cAAc;IACnB;IAEA,IACEG,gBACGC,AAAsC,iBAAtCA,gBAAgB,iBAAiB,IACjCA,AAAsC,WAAtCA,gBAAgB,iBAAiB,EAEpC,QACGY,0BACC,cAAcD,cACd,mBAAmBX,iBACnB,QAAQnB,QACT;QACC,CAACuB,eAAe/B,UAAUqB,uBAAuB;MACnD,EAAEkB;IAGJ,QACGC,gBAAgB,cAAcF,cAAc,QAAQ9B,QAAQ;QAC3D,CAACuB,eAAe/B,UAAUqB,uBAAuB;MACnD,EAAEmB;AAGR"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAIA,mBAAmB,cAAc,CAAA"}
|