@lynx-js/lynx-ui-scroll-view 3.131.0 → 3.132.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 +6 -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 +2 -2
- package/dist/index.jsx.map +1 -1
- package/dist/types/index.docs.d.ts +18 -9
- package/dist/types/index.docs.d.ts.map +1 -1
- package/dist/types/index.docs.jsx.map +1 -1
- package/package.json +2 -2
- package/src/ScrollViewWithBouncesHook.tsx +22 -5
- package/src/hooks/useBounce.tsx +164 -131
- package/src/index.tsx +4 -0
- package/src/types/index.docs.ts +18 -9
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,8 @@ declare function ScrollViewWithBouncesHook(props: {
|
|
|
7
7
|
elementProps: ScrollViewElementProps;
|
|
8
8
|
children?: ReactNode;
|
|
9
9
|
bounceableOptions?: BounceableBasicProps;
|
|
10
|
+
debugLog?: boolean;
|
|
11
|
+
enableRTL?: boolean;
|
|
10
12
|
sticky?: ReactElement;
|
|
11
13
|
}, _ref: ForwardedRef<ScrollViewRef>): import("react").JSX.Element;
|
|
12
14
|
export default ScrollViewWithBouncesHook;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScrollViewWithBouncesHook.d.ts","sourceRoot":"","sources":["../src/ScrollViewWithBouncesHook.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE3E,OAAO,0BAA0B,C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
|
import "@lynx-js/gesture-runtime";
|
|
2
2
|
import { useBounce } from "./hooks/useBounce.jsx";
|
|
3
3
|
function ScrollViewWithBouncesHook(props, _ref) {
|
|
4
|
-
const { children, bounceableOptions, sticky, elementProps } = props;
|
|
4
|
+
const { children, bounceableOptions, sticky, elementProps, debugLog = false, enableRTL = false } = props;
|
|
5
5
|
const horizontal = elementProps['scroll-x'] ?? false === elementProps['scroll-y'];
|
|
6
6
|
const scrollViewId = elementProps.id;
|
|
7
7
|
const { style } = elementProps;
|
|
@@ -27,14 +27,16 @@ function ScrollViewWithBouncesHook(props, _ref) {
|
|
|
27
27
|
}
|
|
28
28
|
const bounceMTSProps = useBounce({
|
|
29
29
|
bounceableOptions: bounceableProps,
|
|
30
|
+
debugLog,
|
|
31
|
+
enableRTL,
|
|
30
32
|
id: scrollViewId,
|
|
31
33
|
scrollOrientation: horizontal ? 'horizontal' : 'vertical'
|
|
32
34
|
});
|
|
33
35
|
if (enableBounce) {
|
|
34
|
-
if (bounceableProps.upperBounceItem) startBounceView = <view id={`${scrollViewId}-upperBounceWrapper`} style={`position:absolute;${horizontal ? 'right:100%' : 'bottom:100%'}; ${horizontal ? 'height:100%;' : 'width:100%;'};${horizontal ? 'width:max-content' : 'height:max-content'};`} main-thread:gesture={elementProps['main-thread:gesture']}>
|
|
36
|
+
if (bounceableProps.upperBounceItem) startBounceView = <view id={`${scrollViewId}-upperBounceWrapper`} style={`position:absolute;${horizontal ? enableRTL ? 'left:100%' : 'right:100%' : 'bottom:100%'}; ${horizontal ? 'height:100%;' : 'width:100%;'};${horizontal ? 'width:max-content' : 'height:max-content'};`} main-thread:gesture={elementProps['main-thread:gesture']}>
|
|
35
37
|
{bounceableProps.upperBounceItem}
|
|
36
38
|
</view>;
|
|
37
|
-
if (bounceableProps.lowerBounceItem) endBounceView = <view id={`${scrollViewId}-lowerBounceWrapper`} style={`position:absolute;${horizontal ? 'left:100%' : 'top:100%'}; ${horizontal ? 'height:100%;' : 'width:100%;'};${horizontal ? 'width:max-content' : 'height:max-content'};`} main-thread:gesture={elementProps['main-thread:gesture']}>
|
|
39
|
+
if (bounceableProps.lowerBounceItem) endBounceView = <view id={`${scrollViewId}-lowerBounceWrapper`} style={`position:absolute;${horizontal ? enableRTL ? 'right:100%' : 'left:100%' : 'top:100%'}; ${horizontal ? 'height:100%;' : 'width:100%;'};${horizontal ? 'width:max-content' : 'height:max-content'};`} main-thread:gesture={elementProps['main-thread:gesture']}>
|
|
38
40
|
{bounceableProps.lowerBounceItem}
|
|
39
41
|
</view>;
|
|
40
42
|
upperExposureView = <view style={`display: flex; flex-direction: column; overflow:hidden; height: ${horizontal ? '100%' : '1ppx'}; width: ${horizontal ? '1ppx' : '100%'};`} exposure-scene={scrollViewId} exposure-id='upperExposureView' id={`${scrollViewId}-upperExposureView`} main-thread:binduidisappear={bounceMTSProps.onUpperDisexposure} main-thread:binduiappear={bounceMTSProps.onUpperExposure} main-thread:gesture={elementProps['main-thread:gesture']}/>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScrollViewWithBouncesHook.jsx","sources":["webpack://@lynx-js/lynx-ui-scroll-view/./src/ScrollViewWithBouncesHook.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 type { ForwardedRef, ReactElement, ReactNode } from '@lynx-js/react'\n\nimport '@lynx-js/gesture-runtime'\nimport type {\n CSSProperties,\n ScrollViewProps as ScrollViewElementProps,\n} from '@lynx-js/types'\n\nimport { useBounce } from './hooks/useBounce'\nimport type {\n BounceableBasicProps,\n ScrollViewProps,\n ScrollViewRef,\n} from './types'\n\nexport type { ScrollViewProps, ScrollViewRef }\n\nfunction ScrollViewWithBouncesHook(\n props: {\n elementProps: ScrollViewElementProps\n children?: ReactNode\n bounceableOptions?: BounceableBasicProps\n sticky?: ReactElement\n },\n _ref: ForwardedRef<ScrollViewRef>,\n) {\n const {
|
|
1
|
+
{"version":3,"file":"ScrollViewWithBouncesHook.jsx","sources":["webpack://@lynx-js/lynx-ui-scroll-view/./src/ScrollViewWithBouncesHook.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 type { ForwardedRef, ReactElement, ReactNode } from '@lynx-js/react'\n\nimport '@lynx-js/gesture-runtime'\nimport type {\n CSSProperties,\n ScrollViewProps as ScrollViewElementProps,\n} from '@lynx-js/types'\n\nimport { useBounce } from './hooks/useBounce'\nimport type {\n BounceableBasicProps,\n ScrollViewProps,\n ScrollViewRef,\n} from './types'\n\nexport type { ScrollViewProps, ScrollViewRef }\n\nfunction ScrollViewWithBouncesHook(\n props: {\n elementProps: ScrollViewElementProps\n children?: ReactNode\n bounceableOptions?: BounceableBasicProps\n debugLog?: boolean\n enableRTL?: boolean\n sticky?: ReactElement\n },\n _ref: ForwardedRef<ScrollViewRef>,\n) {\n const {\n children,\n bounceableOptions,\n sticky,\n elementProps,\n debugLog = false,\n enableRTL = false,\n } = props\n // @ts-expect-error Compatible with older versions\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const horizontal = elementProps['scroll-x']\n // @ts-expect-error Compatible with older versions\n ?? elementProps['scroll-y'] === false\n const scrollViewId = elementProps.id\n const { style } = elementProps as { style: CSSProperties }\n // Initialize bounceableProps\n let enableBounce = false\n let bounceableProps: BounceableBasicProps = { enableBounces: false }\n let startBounceView, endBounceView, upperExposureView, lowerExposureView\n if (typeof bounceableOptions === 'boolean') {\n enableBounce = bounceableOptions\n bounceableProps = {\n enableBounces: true,\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 const bounceMTSProps = useBounce({\n bounceableOptions: bounceableProps,\n debugLog,\n enableRTL,\n id: scrollViewId,\n scrollOrientation: horizontal ? 'horizontal' : 'vertical',\n })\n if (enableBounce) {\n if (bounceableProps.upperBounceItem) {\n startBounceView = (\n <view\n id={`${scrollViewId}-upperBounceWrapper`}\n style={`position:absolute;${\n horizontal\n ? (enableRTL ? 'left:100%' : 'right:100%')\n : 'bottom:100%'\n }; ${horizontal ? 'height:100%;' : 'width:100%;'};${\n horizontal ? 'width:max-content' : 'height:max-content'\n };`}\n main-thread:gesture={elementProps['main-thread:gesture']}\n >\n {bounceableProps.upperBounceItem}\n </view>\n )\n }\n if (bounceableProps.lowerBounceItem) {\n endBounceView = (\n <view\n id={`${scrollViewId}-lowerBounceWrapper`}\n style={`position:absolute;${\n horizontal\n ? (enableRTL ? 'right:100%' : 'left:100%')\n : 'top:100%'\n }; ${horizontal ? 'height:100%;' : 'width:100%;'};${\n horizontal ? 'width:max-content' : 'height:max-content'\n };`}\n main-thread:gesture={elementProps['main-thread:gesture']}\n >\n {bounceableProps.lowerBounceItem}\n </view>\n )\n }\n upperExposureView = (\n <view\n style={`display: flex; flex-direction: column; overflow:hidden; height: ${\n horizontal ? '100%' : '1ppx'\n }; width: ${horizontal ? '1ppx' : '100%'};`}\n exposure-scene={scrollViewId}\n exposure-id='upperExposureView'\n id={`${scrollViewId}-upperExposureView`}\n main-thread:binduidisappear={bounceMTSProps.onUpperDisexposure}\n main-thread:binduiappear={bounceMTSProps.onUpperExposure}\n main-thread:gesture={elementProps['main-thread:gesture']}\n />\n )\n lowerExposureView = (\n <view\n style={`display: flex; flex-direction: column; overflow:hidden; height: ${\n horizontal ? '100%' : '1ppx'\n }; width: ${horizontal ? '1ppx' : '100%'};`}\n exposure-scene={scrollViewId}\n exposure-id='lowerExposureView'\n id={`${scrollViewId}-lowerExposureView`}\n main-thread:binduidisappear={bounceMTSProps.onLowerDisexposure}\n main-thread:binduiappear={bounceMTSProps.onLowerExposure}\n main-thread:gesture={elementProps['main-thread:gesture']}\n />\n )\n }\n\n return (\n <view\n id={`${scrollViewId}-BounceWrapper`}\n style={`display: flex; flex-direction: column; overflow:hidden; height: ${\n horizontal ? '100%' : `${style?.height}`\n }; width: ${horizontal ? `${style?.width}` : '100%'};`}\n main-thread:gesture={elementProps['main-thread:gesture']}\n >\n <scroll-view\n {...elementProps}\n {...bounceMTSProps}\n bounces={false}\n ios-enable-simultaneous-touch={true}\n // This is a workaround for using RL3.0-ver 0.110.1 and SDK-ver <=3.4. It will force the scroll-view to update after the BTS is ready and flush the 'name' prop along with __AddEvents. Otherwise, a pure __AddEvents will be discarded by the engine and won't trigger the flush of the prop_bundle. As a result, all events will be lost.\n // We do not use __MAIN_THREAD__ here to maintain compatibility with the old version of @lynx-js/react.\n name={__LEPUS__ ? 'lepus' : 'background'}\n >\n {upperExposureView}\n {sticky}\n {children}\n {lowerExposureView}\n </scroll-view>\n {startBounceView}\n {endBounceView}\n </view>\n )\n}\n\nexport default ScrollViewWithBouncesHook\n"],"names":["ScrollViewWithBouncesHook","props","_ref","children","bounceableOptions","sticky","elementProps","debugLog","enableRTL","horizontal","scrollViewId","style","enableBounce","bounceableProps","startBounceView","endBounceView","upperExposureView","lowerExposureView","bounceMTSProps","useBounce","view","scroll-view","__LEPUS__"],"mappings":";;AAqBA,SAASA,0BACPC,KAOC,EACDC,IAAiC;IAEjC,MAAM,EACJC,QAAQ,EACRC,iBAAiB,EACjBC,MAAM,EACNC,YAAY,EACZC,WAAW,KAAK,EAChBC,YAAY,KAAK,EAClB,GAAGP;IAGJ,MAAMQ,aAAaH,YAAY,CAAC,WAAW,IAEtCA,AAA6B,UAA7BA,YAAY,CAAC,WAAW;IAC7B,MAAMI,eAAeJ,aAAa,EAAE;IACpC,MAAM,EAAEK,KAAK,EAAE,GAAGL;IAElB,IAAIM,eAAe;IACnB,IAAIC,kB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C,gEAAgE,EACtEX,aAAa,SAAS,OACvB,SAAS,EAAEA,aAAa,SAAS,OAAO,CAAC,CAAC,EAC3C,gBAAgBC,cAChB,YAAY,oBACZ,IAAI,GAAGA,aAAa,kBAAkB,CAAC,EACvC,YAAY,iBAAiBQ,eAAe,kBAAkB,EAC9D,YAAY,cAAcA,eAAe,eAAe,EACxD,YAAY,SAASZ,YAAY,CAAC,sBAAsB;QAG5DW,qBACGG,KACC,OAAO,CAAC,gEAAgE,EACtEX,aAAa,SAAS,OACvB,SAAS,EAAEA,aAAa,SAAS,OAAO,CAAC,CAAC,EAC3C,gBAAgBC,cAChB,YAAY,oBACZ,IAAI,GAAGA,aAAa,kBAAkB,CAAC,EACvC,YAAY,iBAAiBQ,eAAe,kBAAkB,EAC9D,YAAY,cAAcA,eAAe,eAAe,EACxD,YAAY,SAASZ,YAAY,CAAC,sBAAsB;IAG9D;IAEA,QACGc,KACC,IAAI,GAAGV,aAAa,cAAc,CAAC,EACnC,OAAO,CAAC,gEAAgE,EACtED,aAAa,SAAS,GAAGE,OAAO,QAAQ,CACzC,SAAS,EAAEF,aAAa,GAAGE,OAAO,OAAO,GAAG,OAAO,CAAC,CAAC,EACtD,YAAY,SAASL,YAAY,CAAC,sBAAsB,EACzD;MACC,CAACe,aACE,GAAGf,YAAY,GACf,GAAGY,cAAc,EAClB,SAAS,OACT,+BAA+B,MAG/B,MAAMI,YAAY,UAAU,cAC7B;QACC,CAACN,kBAAkB;QACnB,CAACX,OAAO;QACR,CAACF,SAAS;QACV,CAACc,kBAAkB;MACrB,EAAEI,YAAY;MACd,CAACP,gBAAgB;MACjB,CAACC,cAAc;IACjB,EAAEK;AAEN;AAEA,sCAAepB"}
|
|
@@ -13,12 +13,13 @@ export interface BounceableBasicProps {
|
|
|
13
13
|
singleSidedBounce?: 'upper' | 'lower' | 'both' | 'iOSBounces' | 'none';
|
|
14
14
|
estimatedHeight?: number;
|
|
15
15
|
estimatedWidth?: number;
|
|
16
|
-
debugLog?: boolean;
|
|
17
16
|
validAnimationVersion?: boolean;
|
|
18
17
|
onScrollToBounces?: (e: scrollToBouncesInfo) => void;
|
|
19
18
|
}
|
|
20
19
|
export interface useBounceOptions {
|
|
21
20
|
bounceableOptions: BounceableBasicProps;
|
|
21
|
+
debugLog?: boolean;
|
|
22
|
+
enableRTL?: boolean;
|
|
22
23
|
/**
|
|
23
24
|
* idSelector of scroll container
|
|
24
25
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBounce.d.ts","sourceRoot":"","sources":["../../src/hooks/useBounce.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE1E,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAA;CAC7B;AAED,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,OAAO,CAAA;IACtB,wBAAwB,CAAC,EAAE,OAAO,CAAA;IAClC,0BAA0B,CAAC,EAAE,MAAM,CAAA;IACnC,wBAAwB,CAAC,EAAE,MAAM,CAAA;IAEjC,eAAe,CAAC,EAAE,GAAG,CAAA;IAErB,eAAe,CAAC,EAAE,GAAG,CAAA;IACrB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,iBAAiB,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,YAAY,GAAG,MAAM,CAAA;IACtE,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,
|
|
1
|
+
{"version":3,"file":"useBounce.d.ts","sourceRoot":"","sources":["../../src/hooks/useBounce.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE1E,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAA;CAC7B;AAED,MAAM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AW,KAAK,IAAI,CAAA;IACjD,eAAe,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAA;IAC9C,kBAAkB,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAA;CAClD;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,cAAc,CA0yBnE"}
|
package/dist/hooks/useBounce.jsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { runOnBackground, useMainThreadRef } from "@lynx-js/react";
|
|
2
|
-
import { selectorMT } from "@lynx-js/lynx-ui-common";
|
|
2
|
+
import { log, mtsLog, selectorMT } from "@lynx-js/lynx-ui-common";
|
|
3
3
|
function useBounce(options) {
|
|
4
4
|
const rubberC = useMainThreadRef(0.55);
|
|
5
5
|
const flingDeceleratingRate = useMainThreadRef(0.99);
|
|
6
6
|
const beta = useMainThreadRef(15);
|
|
7
|
-
const
|
|
7
|
+
const debugLogEnabled = Boolean(options.debugLog);
|
|
8
8
|
const singleSidedBounce = useMainThreadRef(options.bounceableOptions.singleSidedBounce ?? 'both');
|
|
9
9
|
const startTouch = useMainThreadRef(null);
|
|
10
10
|
const prevTouch = useMainThreadRef(null);
|
|
@@ -27,10 +27,12 @@ function useBounce(options) {
|
|
|
27
27
|
const { enableBounces, onScrollToBounces } = options.bounceableOptions;
|
|
28
28
|
const alwaysBouncing = options.bounceableOptions.alwaysBouncing ?? false;
|
|
29
29
|
const scrollOrientation = options.scrollOrientation ?? 'vertical';
|
|
30
|
+
const enableRTL = useMainThreadRef(options.enableRTL ?? false);
|
|
30
31
|
const enableBounceEventInFling = options.bounceableOptions.enableBounceEventInFling ?? true;
|
|
31
32
|
const startBounceTriggerDistance = options.bounceableOptions.startBounceTriggerDistance ?? 0;
|
|
32
33
|
const endBounceTriggerDistance = options.bounceableOptions.endBounceTriggerDistance ?? 0;
|
|
33
34
|
const temporaryValidVersionCheckForRAF = useMainThreadRef(options.bounceableOptions.validAnimationVersion ?? false);
|
|
35
|
+
log(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] init, enableBounces: ${enableBounces}, orientation: ${scrollOrientation}, enableRTL: ${options.enableRTL ?? false}`);
|
|
34
36
|
const bouncingStatus = {
|
|
35
37
|
inScrollingRange: 0,
|
|
36
38
|
upperBouncing: 1,
|
|
@@ -46,6 +48,10 @@ function useBounce(options) {
|
|
|
46
48
|
'main thread';
|
|
47
49
|
return 1.0 / Number(SystemInfo.pixelRatio);
|
|
48
50
|
}
|
|
51
|
+
function normalizedHorizontalValue(value) {
|
|
52
|
+
'main thread';
|
|
53
|
+
return enableRTL.current ? -value : value;
|
|
54
|
+
}
|
|
49
55
|
function isAndroid() {
|
|
50
56
|
'main thread';
|
|
51
57
|
return 'Android' === SystemInfo.platform;
|
|
@@ -60,7 +66,7 @@ function useBounce(options) {
|
|
|
60
66
|
}
|
|
61
67
|
function clearTouchInfo() {
|
|
62
68
|
'main thread';
|
|
63
|
-
|
|
69
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] clear touch info');
|
|
64
70
|
startTouch.current = null;
|
|
65
71
|
bouncingTouchStartPosition.current = 0;
|
|
66
72
|
prevTouch.current = null;
|
|
@@ -74,8 +80,8 @@ function useBounce(options) {
|
|
|
74
80
|
}
|
|
75
81
|
function getCurrentDelta(event) {
|
|
76
82
|
'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;
|
|
83
|
+
if (null !== startTouch.current) if (null === startBouncingTouch.current) return 'vertical' === scrollOrientation ? event.touches[0].pageY - startTouch.current[0].pageY : normalizedHorizontalValue(event.touches[0].pageX - startTouch.current[0].pageX);
|
|
84
|
+
else return 'vertical' === scrollOrientation ? event.touches[0].pageY - startBouncingTouch.current[0].pageY : normalizedHorizontalValue(event.touches[0].pageX - startBouncingTouch.current[0].pageX);
|
|
79
85
|
return 0;
|
|
80
86
|
}
|
|
81
87
|
function getBouncingStatus() {
|
|
@@ -83,7 +89,7 @@ function useBounce(options) {
|
|
|
83
89
|
const currentPosition = bouncingPositionInfo.current?.bouncingOffset ?? 0;
|
|
84
90
|
if (Boolean(toUpper.current) && Boolean(toLower.current)) return alwaysBouncing ? bouncingStatus.alwaysBouncing : bouncingStatus.noBouncing;
|
|
85
91
|
const initialLayoutPosition = 0;
|
|
86
|
-
|
|
92
|
+
mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] get bouncing status, initialLayoutPosition: ${initialLayoutPosition}, currentPosition: ${currentPosition}`);
|
|
87
93
|
if (currentPosition > initialLayoutPosition) return bouncingStatus.upperBouncing;
|
|
88
94
|
if (currentPosition < initialLayoutPosition) return bouncingStatus.lowerBouncing;
|
|
89
95
|
return bouncingStatus.inScrollingRange;
|
|
@@ -97,7 +103,7 @@ function useBounce(options) {
|
|
|
97
103
|
}
|
|
98
104
|
function bouncingSetStyle(offset) {
|
|
99
105
|
'main thread';
|
|
100
|
-
if (isNaN(Number(offset))) return void
|
|
106
|
+
if (isNaN(Number(offset))) return void mtsLog(true, '[lynx-ui-scroll-view][useBounce] ERROR! bouncingOffset is NaN');
|
|
101
107
|
if (isEmpty(bouncingPositionInfo.current)) bouncingPositionInfo.current.velocity = 0;
|
|
102
108
|
else {
|
|
103
109
|
const timeDiff = Date.now() - bouncingPositionInfo.current.timeStamp;
|
|
@@ -111,13 +117,16 @@ function useBounce(options) {
|
|
|
111
117
|
bouncingTouchStartPosition.current = {};
|
|
112
118
|
}
|
|
113
119
|
if (isVertical()) {
|
|
120
|
+
mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] apply transform, orientation: vertical, rawOffset: ${offset}, containerTransform: translateY(${offset}px)`);
|
|
114
121
|
selectorMT(containerID)?.setStyleProperty('transform', `translateY(${offset}px)`);
|
|
115
122
|
selectorMT(`${containerID}-upperBounceWrapper`)?.setStyleProperty('transform', `translateY(${offset}px)`);
|
|
116
123
|
selectorMT(`${containerID}-lowerBounceWrapper`)?.setStyleProperty('transform', `translateY(${offset}px)`);
|
|
117
124
|
} else {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
selectorMT(
|
|
125
|
+
const visualOffset = enableRTL.current ? -offset : offset;
|
|
126
|
+
mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] apply transform, orientation: horizontal, rawOffset: ${offset}, enableRTL: ${String(enableRTL.current)}, visualOffset: ${visualOffset}, containerTransform: translateX(${visualOffset}px)`);
|
|
127
|
+
selectorMT(containerID)?.setStyleProperty('transform', `translateX(${visualOffset}px)`);
|
|
128
|
+
selectorMT(`${containerID}-upperBounceWrapper`)?.setStyleProperty('transform', `translateX(${visualOffset}px)`);
|
|
129
|
+
selectorMT(`${containerID}-lowerBounceWrapper`)?.setStyleProperty('transform', `translateX(${visualOffset}px)`);
|
|
121
130
|
}
|
|
122
131
|
}
|
|
123
132
|
function onScrollToBouncesJS(info) {
|
|
@@ -125,7 +134,7 @@ function useBounce(options) {
|
|
|
125
134
|
}
|
|
126
135
|
function triggerScrollToBouncesEvent(isUpper) {
|
|
127
136
|
'main thread';
|
|
128
|
-
|
|
137
|
+
mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] trigger scrollToBounces, direction: ${isUpper ? 'upper' : 'lower'}`);
|
|
129
138
|
const info = {
|
|
130
139
|
direction: isUpper ? 'upper' : 'lower'
|
|
131
140
|
};
|
|
@@ -138,13 +147,13 @@ function useBounce(options) {
|
|
|
138
147
|
const deltaYForTouchStartPosition = scrollViewFrameSize * touchStartPosition / ((scrollViewFrameSize - touchStartPosition) * rubberC.current) || 0;
|
|
139
148
|
const deltaYForNextPosition = bouncingTouchStartPosition.current ? deltaYForTouchStartPosition + isNegative * delta : isNegative * delta;
|
|
140
149
|
const rubberBandingDistance = Math.max(0, (1.0 - 1.0 / (deltaYForNextPosition * rubberC.current / scrollViewFrameSize + 1.0)) * scrollViewFrameSize);
|
|
141
|
-
|
|
150
|
+
mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] rubber effect, scrollViewFrameSize: ${scrollViewFrameSize}, touchStartPosition: ${touchStartPosition}, deltaYForTouchStartPosition: ${deltaYForTouchStartPosition}, deltaYForNextPosition: ${deltaYForNextPosition}, rubberBandingDistance: ${rubberBandingDistance}`);
|
|
142
151
|
bouncingSetStyle(isNegative * rubberBandingDistance);
|
|
143
152
|
}
|
|
144
153
|
function triggerRubberEffectIfCrossingEdge(event) {
|
|
145
154
|
'main thread';
|
|
146
155
|
const delta = getCurrentDelta(event);
|
|
147
|
-
|
|
156
|
+
mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] check crossing edge, delta: ${delta}, toUpper: ${String(toUpper.current)}, toLower: ${String(toLower.current)}`);
|
|
148
157
|
if (true === toUpper.current && delta > 0 && ('both' === singleSidedBounce.current || 'upper' === singleSidedBounce.current)) {
|
|
149
158
|
enableScroll(false);
|
|
150
159
|
rubberEffect(delta > 0 ? 1 : -1, delta);
|
|
@@ -164,22 +173,20 @@ function useBounce(options) {
|
|
|
164
173
|
}
|
|
165
174
|
function bouncingBack() {
|
|
166
175
|
'main thread';
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
console.info('bounce back starts');
|
|
170
|
-
}
|
|
176
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] fling forward end');
|
|
177
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] bounce back starts');
|
|
171
178
|
const C1 = bouncingPositionInfo.current.bouncingOffset ?? 0;
|
|
172
179
|
const startTime = Date.now();
|
|
173
180
|
const touchingEndBouncingBackFrame = ()=>{
|
|
174
181
|
if (false === Boolean(touchingEndBouncingBackEnableFlag.current)) return;
|
|
175
182
|
const currentTime = Date.now() - startTime;
|
|
176
|
-
|
|
183
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touching end bouncing back frame');
|
|
177
184
|
const C2 = beta.current * C1;
|
|
178
185
|
const easedDistance = (C1 + currentTime / 1000 * C2) * Math.pow(Math.E, -beta.current * (currentTime / 1000));
|
|
179
186
|
bouncingSetStyle(easedDistance);
|
|
180
187
|
if (Math.abs(easedDistance) < threshold()) {
|
|
181
188
|
bouncingSetStyle(0);
|
|
182
|
-
|
|
189
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] bounce back ends');
|
|
183
190
|
} else customRequestAnimationFrame(touchingEndBouncingBackFrame);
|
|
184
191
|
};
|
|
185
192
|
customRequestAnimationFrame(touchingEndBouncingBackFrame);
|
|
@@ -188,7 +195,7 @@ function useBounce(options) {
|
|
|
188
195
|
function bounceableTouchStart(event) {
|
|
189
196
|
'main thread';
|
|
190
197
|
startTouch.current = event.touches;
|
|
191
|
-
|
|
198
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touch start');
|
|
192
199
|
bouncingTouchStartPosition.current = bouncingPositionInfo.current?.bouncingOffset ?? 0;
|
|
193
200
|
touchEndFrameEnableFlag.current = false;
|
|
194
201
|
touchingEndBouncingBackEnableFlag.current = false;
|
|
@@ -197,7 +204,7 @@ function useBounce(options) {
|
|
|
197
204
|
function bounceableTouchMove(event) {
|
|
198
205
|
'main thread';
|
|
199
206
|
prevTouch.current = event.touches;
|
|
200
|
-
if (null === startTouch.current)
|
|
207
|
+
if (null === startTouch.current) mtsLog(true, '[lynx-ui-scroll-view][useBounce] ERROR! touch not started');
|
|
201
208
|
else {
|
|
202
209
|
const delta = getCurrentDelta(event);
|
|
203
210
|
const currentBouncingStatus = getBouncingStatus();
|
|
@@ -205,19 +212,19 @@ function useBounce(options) {
|
|
|
205
212
|
case bouncingStatus.upperBouncing:
|
|
206
213
|
enableScroll(false);
|
|
207
214
|
rubberEffect(1, delta);
|
|
208
|
-
|
|
215
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touch move upper bouncing');
|
|
209
216
|
break;
|
|
210
217
|
case bouncingStatus.lowerBouncing:
|
|
211
218
|
enableScroll(false);
|
|
212
219
|
rubberEffect(-1, delta);
|
|
213
|
-
|
|
220
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touch move lower bouncing');
|
|
214
221
|
break;
|
|
215
222
|
case bouncingStatus.alwaysBouncing:
|
|
216
|
-
|
|
223
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touch move always bouncing');
|
|
217
224
|
if (alwaysBouncing) triggerRubberEffectIfCrossingEdge(event);
|
|
218
225
|
break;
|
|
219
226
|
case bouncingStatus.inScrollingRange:
|
|
220
|
-
|
|
227
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touch move in scrolling range');
|
|
221
228
|
triggerRubberEffectIfCrossingEdge(event);
|
|
222
229
|
break;
|
|
223
230
|
default:
|
|
@@ -229,7 +236,7 @@ function useBounce(options) {
|
|
|
229
236
|
'main thread';
|
|
230
237
|
clearTouchInfo();
|
|
231
238
|
enableScroll(true);
|
|
232
|
-
|
|
239
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touch end');
|
|
233
240
|
if (shouldBounceWhenTouchEnd(getBouncingStatus())) {
|
|
234
241
|
const startTime = Date.now();
|
|
235
242
|
const dragEndVelocity = bouncingPositionInfo.current?.velocity;
|
|
@@ -238,10 +245,10 @@ function useBounce(options) {
|
|
|
238
245
|
let currentVelocity = dragEndVelocity;
|
|
239
246
|
const touchEndProcessFrame = ()=>{
|
|
240
247
|
if (false === Boolean(touchEndFrameEnableFlag.current)) return;
|
|
241
|
-
|
|
248
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touch end process frame');
|
|
242
249
|
if (Math.abs(currentVelocity) <= threshold()) bouncingBack();
|
|
243
250
|
else {
|
|
244
|
-
|
|
251
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] fling down start');
|
|
245
252
|
const distance = dragEndPosition + dragEndVelocity * (Math.pow(flingDeceleratingRate.current, Date.now() - startTime) - 1) / Math.log(flingDeceleratingRate.current);
|
|
246
253
|
bouncingSetStyle(distance);
|
|
247
254
|
currentVelocity = dragEndVelocity * Math.pow(flingDeceleratingRate.current, Date.now() - startTime);
|
|
@@ -257,23 +264,25 @@ function useBounce(options) {
|
|
|
257
264
|
scrollX.current = event.detail.scrollLeft;
|
|
258
265
|
scrollY.current = event.detail.scrollTop;
|
|
259
266
|
if (!isEmpty(prevScroll.current)) {
|
|
260
|
-
const
|
|
267
|
+
const prev = prevScroll.current;
|
|
268
|
+
const timeDuration = Date.now() - prev.timestamp;
|
|
261
269
|
if (timeDuration > 0) {
|
|
262
|
-
const deltaY = isVertical() ? event.detail.scrollTop -
|
|
270
|
+
const deltaY = isVertical() ? event.detail.scrollTop - prev.detail.scrollTop : normalizedHorizontalValue(event.detail.scrollLeft - prev.detail.scrollLeft);
|
|
263
271
|
const velocity = deltaY / timeDuration;
|
|
264
272
|
if (Number.isFinite(velocity)) scrollVelocity.current = velocity;
|
|
265
273
|
}
|
|
266
274
|
}
|
|
275
|
+
mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] handle scroll near edge, scrollLeft: ${event.detail.scrollLeft}, scrollTop: ${event.detail.scrollTop}, velocity: ${scrollVelocity.current}`);
|
|
267
276
|
prevScroll.current = event;
|
|
268
277
|
}
|
|
269
278
|
function onUpperDisexposure(_event) {
|
|
270
279
|
'main thread';
|
|
271
|
-
|
|
280
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] upper disexposure');
|
|
272
281
|
toUpper.current = false;
|
|
273
282
|
}
|
|
274
283
|
function onUpperExposure(_event) {
|
|
275
284
|
'main thread';
|
|
276
|
-
|
|
285
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] upper exposure');
|
|
277
286
|
toUpper.current = true;
|
|
278
287
|
if ('upper' !== singleSidedBounce.current && 'both' !== singleSidedBounce.current) return;
|
|
279
288
|
if (prevScroll.current) {
|
|
@@ -283,19 +292,14 @@ function useBounce(options) {
|
|
|
283
292
|
const velocity = scrollVelocity.current;
|
|
284
293
|
let currentVelocity = velocity;
|
|
285
294
|
const startTime = Date.now();
|
|
286
|
-
|
|
295
|
+
mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] fling to upper event start, velocity: ${velocity}`);
|
|
287
296
|
let sentScrollToBouncesEvent = false;
|
|
288
297
|
const flingEndWithBouncingFrame = ()=>{
|
|
289
|
-
if (false === Boolean(flingEndWithBouncingEnableFlag.current))
|
|
290
|
-
if (debugLog.current) console.info('flingEndWithBouncingEnableFlag early return');
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
298
|
+
if (false === Boolean(flingEndWithBouncingEnableFlag.current)) return void mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] flingEndWithBouncingEnableFlag early return');
|
|
293
299
|
if (Math.abs(currentVelocity) <= threshold()) {
|
|
294
300
|
flingEndWithBouncingEnableFlag.current = false;
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
console.info('bouncing to upper event start');
|
|
298
|
-
}
|
|
301
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] fling to upper event end');
|
|
302
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] bouncing to upper event start');
|
|
299
303
|
bouncingBack();
|
|
300
304
|
} else {
|
|
301
305
|
const distance = currentVelocity * (Math.pow(flingDeceleratingRate.current, Date.now() - startTime) - 1) / Math.log(flingDeceleratingRate.current);
|
|
@@ -314,12 +318,12 @@ function useBounce(options) {
|
|
|
314
318
|
}
|
|
315
319
|
function onLowerDisexposure(_event) {
|
|
316
320
|
'main thread';
|
|
317
|
-
|
|
321
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] lower disexposure');
|
|
318
322
|
toLower.current = false;
|
|
319
323
|
}
|
|
320
324
|
function onLowerExposure(_event) {
|
|
321
325
|
'main thread';
|
|
322
|
-
|
|
326
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] lower exposure');
|
|
323
327
|
toLower.current = true;
|
|
324
328
|
if ('lower' !== singleSidedBounce.current && 'both' !== singleSidedBounce.current) return;
|
|
325
329
|
if (null !== prevTouch.current) {
|
|
@@ -327,23 +331,18 @@ function useBounce(options) {
|
|
|
327
331
|
startTouchBouncingDelta.current = bouncingPositionInfo.current?.bouncingOffset ?? 0;
|
|
328
332
|
} else if (enableBounceEventInFling && scrollVelocity.current > 0) {
|
|
329
333
|
const velocity = scrollVelocity.current;
|
|
330
|
-
|
|
334
|
+
mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] lower velocity: ${velocity}`);
|
|
331
335
|
if (Math.abs(velocity) > threshold()) {
|
|
332
336
|
let currentVelocity = velocity;
|
|
333
337
|
const startTime = Date.now();
|
|
334
|
-
|
|
338
|
+
mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] fling to lower event start, velocity: ${velocity}`);
|
|
335
339
|
let sentScrollToBouncesEvent = false;
|
|
336
340
|
const flingEndWithBouncingFrame = ()=>{
|
|
337
|
-
if (false === Boolean(flingEndWithBouncingEnableFlag.current))
|
|
338
|
-
if (debugLog.current) console.info('flingEndWithBouncingEnableFlag early return');
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
+
if (false === Boolean(flingEndWithBouncingEnableFlag.current)) return void mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] flingEndWithBouncingEnableFlag early return');
|
|
341
342
|
if (Math.abs(currentVelocity) <= threshold()) {
|
|
342
343
|
flingEndWithBouncingEnableFlag.current = false;
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
console.info('bouncing to lower event start');
|
|
346
|
-
}
|
|
344
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] fling to lower event end');
|
|
345
|
+
mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] bouncing to lower event start');
|
|
347
346
|
bouncingBack();
|
|
348
347
|
} else {
|
|
349
348
|
const distance = currentVelocity * (Math.pow(flingDeceleratingRate.current, Date.now() - startTime) - 1) / Math.log(flingDeceleratingRate.current);
|