@lynx-js/lynx-ui-scroll-view 3.130.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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # @lynx-js/lynx-ui-scroll-view
2
2
 
3
+ ## 3.132.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add `enableRTL` support for horizontal bounce and refresh interactions. ([#160](https://github.com/lynx-family/lynx-ui/pull/160))
8
+
9
+ ## 3.131.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Migrate bounce and refresh hooks from common to ScrollView and FeedList. ([#119](https://github.com/lynx-family/lynx-ui/pull/119))
14
+
15
+ **BREAKING CHANGE**: `useBounce` and `useRefreshAndBounce` hooks are no longer exported from `@lynx-js/lynx-ui-common`.
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [[`bc167c5`](https://github.com/lynx-family/lynx-ui/commit/bc167c5d03cdb344156e897c4d2d69f95bf7d29b)]:
20
+ - @lynx-js/lynx-ui-common@3.131.0
21
+ - @lynx-js/lynx-ui-lazy-component@3.131.0
22
+
3
23
  ## 3.130.0
4
24
 
5
25
  ### Minor Changes
@@ -1,13 +1,14 @@
1
1
  import type { ForwardedRef, ReactElement, ReactNode } from '@lynx-js/react';
2
2
  import '@lynx-js/gesture-runtime';
3
- import type { BounceableBasicProps } from '@lynx-js/lynx-ui-common';
4
3
  import type { ScrollViewProps as ScrollViewElementProps } from '@lynx-js/types';
5
- import type { ScrollViewProps, ScrollViewRef } from './types';
4
+ import type { BounceableBasicProps, ScrollViewProps, ScrollViewRef } from './types';
6
5
  export type { ScrollViewProps, ScrollViewRef };
7
6
  declare function ScrollViewWithBouncesHook(props: {
8
7
  elementProps: ScrollViewElementProps;
9
8
  children?: ReactNode;
10
9
  bounceableOptions?: BounceableBasicProps;
10
+ debugLog?: boolean;
11
+ enableRTL?: boolean;
11
12
  sticky?: ReactElement;
12
13
  }, _ref: ForwardedRef<ScrollViewRef>): import("react").JSX.Element;
13
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,CAAA;AAEjC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AACnE,OAAO,KAAK,EAEV,eAAe,IAAI,sBAAsB,EAC1C,MAAM,gBAAgB,CAAA;AAEvB,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE7D,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,CAAA;AAE9C,iBAAS,yBAAyB,CAChC,KAAK,EAAE;IACL,YAAY,EAAE,sBAAsB,CAAA;IACpC,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,iBAAiB,CAAC,EAAE,oBAAoB,CAAA;IACxC,MAAM,CAAC,EAAE,YAAY,CAAA;CACtB,EACD,IAAI,EAAE,YAAY,CAAC,aAAa,CAAC,+BAuHlC;AAED,eAAe,yBAAyB,CAAA"}
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,CAAA;AACjC,OAAO,KAAK,EAEV,eAAe,IAAI,sBAAsB,EAC1C,MAAM,gBAAgB,CAAA;AAGvB,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EACf,aAAa,EACd,MAAM,SAAS,CAAA;AAEhB,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,CAAA;AAE9C,iBAAS,yBAAyB,CAChC,KAAK,EAAE;IACL,YAAY,EAAE,sBAAsB,CAAA;IACpC,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,iBAAiB,CAAC,EAAE,oBAAoB,CAAA;IACxC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,MAAM,CAAC,EAAE,YAAY,CAAA;CACtB,EACD,IAAI,EAAE,YAAY,CAAC,aAAa,CAAC,+BAsIlC;AAED,eAAe,yBAAyB,CAAA"}
@@ -1,7 +1,7 @@
1
1
  import "@lynx-js/gesture-runtime";
2
- import { useBounce } from "@lynx-js/lynx-ui-common";
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 { useBounce } from '@lynx-js/lynx-ui-common'\nimport type { BounceableBasicProps } from '@lynx-js/lynx-ui-common'\nimport type {\n CSSProperties,\n ScrollViewProps as ScrollViewElementProps,\n} from '@lynx-js/types'\n\nimport type { ScrollViewProps, ScrollViewRef } 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 { children, bounceableOptions, sticky, elementProps } = 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 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 ? 'right:100%' : '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;${horizontal ? 'left:100%' : 'top:100%'}; ${\n horizontal ? 'height:100%;' : 'width:100%;'\n };${horizontal ? 'width:max-content' : 'height:max-content'};`}\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","horizontal","scrollViewId","style","enableBounce","bounceableProps","startBounceView","endBounceView","upperExposureView","lowerExposureView","bounceMTSProps","useBounce","view","scroll-view","__LEPUS__"],"mappings":"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"}
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":"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"}
@@ -0,0 +1,44 @@
1
+ import type { CommonEvent, MainThread, ScrollEvent } from '@lynx-js/types';
2
+ export interface scrollToBouncesInfo {
3
+ direction: 'upper' | 'lower';
4
+ }
5
+ export interface BounceableBasicProps {
6
+ enableBounces: boolean;
7
+ enableBounceEventInFling?: boolean;
8
+ startBounceTriggerDistance?: number;
9
+ endBounceTriggerDistance?: number;
10
+ upperBounceItem?: any;
11
+ lowerBounceItem?: any;
12
+ alwaysBouncing?: boolean;
13
+ singleSidedBounce?: 'upper' | 'lower' | 'both' | 'iOSBounces' | 'none';
14
+ estimatedHeight?: number;
15
+ estimatedWidth?: number;
16
+ validAnimationVersion?: boolean;
17
+ onScrollToBounces?: (e: scrollToBouncesInfo) => void;
18
+ }
19
+ export interface useBounceOptions {
20
+ bounceableOptions: BounceableBasicProps;
21
+ debugLog?: boolean;
22
+ enableRTL?: boolean;
23
+ /**
24
+ * idSelector of scroll container
25
+ */
26
+ id?: string;
27
+ /**
28
+ * scroll direction
29
+ */
30
+ scrollOrientation: 'vertical' | 'horizontal';
31
+ }
32
+ export interface bounceHandlers {
33
+ 'main-thread:bindtouchstart': (event: MainThread.TouchEvent) => void;
34
+ 'main-thread:bindtouchend': () => void;
35
+ 'main-thread:bindtouchmove': (event: MainThread.TouchEvent) => void;
36
+ 'main-thread:bindlayoutchange': (event: CommonEvent) => void;
37
+ 'main-thread:bindscroll': (event: ScrollEvent) => void;
38
+ onUpperExposure: (_event: CommonEvent) => void;
39
+ onUpperDisexposure: (_event: CommonEvent) => void;
40
+ onLowerExposure: (_event: CommonEvent) => void;
41
+ onLowerDisexposure: (_event: CommonEvent) => void;
42
+ }
43
+ export declare function useBounce(options: useBounceOptions): bounceHandlers;
44
+ //# sourceMappingURL=useBounce.d.ts.map
@@ -0,0 +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,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,iBAAiB,CAAC,EAAE,CAAC,CAAC,EAAE,mBAAmB,KAAK,IAAI,CAAA;CACrD;AAED,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB,EAAE,oBAAoB,CAAA;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,iBAAiB,EAAE,UAAU,GAAG,YAAY,CAAA;CAC7C;AAED,MAAM,WAAW,cAAc;IAC7B,4BAA4B,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,UAAU,KAAK,IAAI,CAAA;IACpE,0BAA0B,EAAE,MAAM,IAAI,CAAA;IACtC,2BAA2B,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,UAAU,KAAK,IAAI,CAAA;IACnE,8BAA8B,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAA;IAC5D,wBAAwB,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAA;IACtD,eAAe,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAA;IAC9C,kBAAkB,EAAE,CAAC,MAAM,EAAE,WAAW,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"}
@@ -0,0 +1,382 @@
1
+ import { runOnBackground, useMainThreadRef } from "@lynx-js/react";
2
+ import { log, mtsLog, 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 debugLogEnabled = Boolean(options.debugLog);
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 enableRTL = useMainThreadRef(options.enableRTL ?? false);
31
+ const enableBounceEventInFling = options.bounceableOptions.enableBounceEventInFling ?? true;
32
+ const startBounceTriggerDistance = options.bounceableOptions.startBounceTriggerDistance ?? 0;
33
+ const endBounceTriggerDistance = options.bounceableOptions.endBounceTriggerDistance ?? 0;
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}`);
36
+ const bouncingStatus = {
37
+ inScrollingRange: 0,
38
+ upperBouncing: 1,
39
+ lowerBouncing: 2,
40
+ noBouncing: 3,
41
+ alwaysBouncing: 4
42
+ };
43
+ function isVertical() {
44
+ 'main thread';
45
+ return 'vertical' === scrollOrientation;
46
+ }
47
+ function threshold() {
48
+ 'main thread';
49
+ return 1.0 / Number(SystemInfo.pixelRatio);
50
+ }
51
+ function normalizedHorizontalValue(value) {
52
+ 'main thread';
53
+ return enableRTL.current ? -value : value;
54
+ }
55
+ function isAndroid() {
56
+ 'main thread';
57
+ return 'Android' === SystemInfo.platform;
58
+ }
59
+ function isEmpty(obj) {
60
+ 'main thread';
61
+ return !obj || 0 === Object.keys(obj).length;
62
+ }
63
+ function enableScroll(enable) {
64
+ 'main thread';
65
+ if (isAndroid()) selectorMT(containerID)?.setAttribute('enable-scroll', enable);
66
+ }
67
+ function clearTouchInfo() {
68
+ 'main thread';
69
+ mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] clear touch info');
70
+ startTouch.current = null;
71
+ bouncingTouchStartPosition.current = 0;
72
+ prevTouch.current = null;
73
+ startBouncingTouch.current = null;
74
+ startTouchBouncingDelta.current = 0;
75
+ }
76
+ function customRequestAnimationFrame(animationFunc) {
77
+ 'main thread';
78
+ if (temporaryValidVersionCheckForRAF.current) requestAnimationFrame(animationFunc);
79
+ else setTimeout(animationFunc, 8);
80
+ }
81
+ function getCurrentDelta(event) {
82
+ 'main thread';
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);
85
+ return 0;
86
+ }
87
+ function getBouncingStatus() {
88
+ 'main thread';
89
+ const currentPosition = bouncingPositionInfo.current?.bouncingOffset ?? 0;
90
+ if (Boolean(toUpper.current) && Boolean(toLower.current)) return alwaysBouncing ? bouncingStatus.alwaysBouncing : bouncingStatus.noBouncing;
91
+ const initialLayoutPosition = 0;
92
+ mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] get bouncing status, initialLayoutPosition: ${initialLayoutPosition}, currentPosition: ${currentPosition}`);
93
+ if (currentPosition > initialLayoutPosition) return bouncingStatus.upperBouncing;
94
+ if (currentPosition < initialLayoutPosition) return bouncingStatus.lowerBouncing;
95
+ return bouncingStatus.inScrollingRange;
96
+ }
97
+ function shouldBounceWhenTouchEnd(status) {
98
+ 'main thread';
99
+ if (status === bouncingStatus.inScrollingRange || status === bouncingStatus.noBouncing) return false;
100
+ if (status === bouncingStatus.upperBouncing || status === bouncingStatus.lowerBouncing) return true;
101
+ if (status === bouncingStatus.alwaysBouncing) return alwaysBouncing;
102
+ return false;
103
+ }
104
+ function bouncingSetStyle(offset) {
105
+ 'main thread';
106
+ if (isNaN(Number(offset))) return void mtsLog(true, '[lynx-ui-scroll-view][useBounce] ERROR! bouncingOffset is NaN');
107
+ if (isEmpty(bouncingPositionInfo.current)) bouncingPositionInfo.current.velocity = 0;
108
+ else {
109
+ const timeDiff = Date.now() - bouncingPositionInfo.current.timeStamp;
110
+ const offsetDiff = offset - bouncingPositionInfo.current.bouncingOffset || 0;
111
+ if (timeDiff > 0) bouncingPositionInfo.current.velocity = offsetDiff / timeDiff;
112
+ }
113
+ bouncingPositionInfo.current.bouncingOffset = offset;
114
+ bouncingPositionInfo.current.timeStamp = Date.now();
115
+ if (0 === offset && null !== prevTouch.current) {
116
+ startTouch.current = prevTouch.current;
117
+ bouncingTouchStartPosition.current = {};
118
+ }
119
+ if (isVertical()) {
120
+ mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] apply transform, orientation: vertical, rawOffset: ${offset}, containerTransform: translateY(${offset}px)`);
121
+ selectorMT(containerID)?.setStyleProperty('transform', `translateY(${offset}px)`);
122
+ selectorMT(`${containerID}-upperBounceWrapper`)?.setStyleProperty('transform', `translateY(${offset}px)`);
123
+ selectorMT(`${containerID}-lowerBounceWrapper`)?.setStyleProperty('transform', `translateY(${offset}px)`);
124
+ } else {
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)`);
130
+ }
131
+ }
132
+ function onScrollToBouncesJS(info) {
133
+ if (enableBounces && onScrollToBounces) onScrollToBounces(info);
134
+ }
135
+ function triggerScrollToBouncesEvent(isUpper) {
136
+ 'main thread';
137
+ mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] trigger scrollToBounces, direction: ${isUpper ? 'upper' : 'lower'}`);
138
+ const info = {
139
+ direction: isUpper ? 'upper' : 'lower'
140
+ };
141
+ runOnBackground(onScrollToBouncesJS)(info);
142
+ }
143
+ function rubberEffect(isNegative, delta) {
144
+ 'main thread';
145
+ const scrollViewFrameSize = isVertical() ? height.current : width.current;
146
+ const touchStartPosition = Math.abs(Number(isEmpty(startTouchBouncingDelta.current) ? bouncingTouchStartPosition.current : startTouchBouncingDelta.current));
147
+ const deltaYForTouchStartPosition = scrollViewFrameSize * touchStartPosition / ((scrollViewFrameSize - touchStartPosition) * rubberC.current) || 0;
148
+ const deltaYForNextPosition = bouncingTouchStartPosition.current ? deltaYForTouchStartPosition + isNegative * delta : isNegative * delta;
149
+ const rubberBandingDistance = Math.max(0, (1.0 - 1.0 / (deltaYForNextPosition * rubberC.current / scrollViewFrameSize + 1.0)) * scrollViewFrameSize);
150
+ mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] rubber effect, scrollViewFrameSize: ${scrollViewFrameSize}, touchStartPosition: ${touchStartPosition}, deltaYForTouchStartPosition: ${deltaYForTouchStartPosition}, deltaYForNextPosition: ${deltaYForNextPosition}, rubberBandingDistance: ${rubberBandingDistance}`);
151
+ bouncingSetStyle(isNegative * rubberBandingDistance);
152
+ }
153
+ function triggerRubberEffectIfCrossingEdge(event) {
154
+ 'main thread';
155
+ const delta = getCurrentDelta(event);
156
+ mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] check crossing edge, delta: ${delta}, toUpper: ${String(toUpper.current)}, toLower: ${String(toLower.current)}`);
157
+ if (true === toUpper.current && delta > 0 && ('both' === singleSidedBounce.current || 'upper' === singleSidedBounce.current)) {
158
+ enableScroll(false);
159
+ rubberEffect(delta > 0 ? 1 : -1, delta);
160
+ }
161
+ if (true === toLower.current && delta < 0 && ('both' === singleSidedBounce.current || 'lower' === singleSidedBounce.current)) {
162
+ enableScroll(false);
163
+ rubberEffect(delta > 0 ? 1 : -1, delta);
164
+ }
165
+ enableScroll(true);
166
+ }
167
+ function isOverTriggerDistance() {
168
+ 'main thread';
169
+ const bouncingTop = bouncingPositionInfo.current.bouncingOffset ?? 0;
170
+ const triggerDistance = bouncingPositionInfo.current?.bouncingOffset > 0 ? startBounceTriggerDistance : endBounceTriggerDistance;
171
+ const delta = Math.abs(bouncingTop) - Math.abs(triggerDistance);
172
+ return delta > threshold();
173
+ }
174
+ function bouncingBack() {
175
+ 'main thread';
176
+ mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] fling forward end');
177
+ mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] bounce back starts');
178
+ const C1 = bouncingPositionInfo.current.bouncingOffset ?? 0;
179
+ const startTime = Date.now();
180
+ const touchingEndBouncingBackFrame = ()=>{
181
+ if (false === Boolean(touchingEndBouncingBackEnableFlag.current)) return;
182
+ const currentTime = Date.now() - startTime;
183
+ mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touching end bouncing back frame');
184
+ const C2 = beta.current * C1;
185
+ const easedDistance = (C1 + currentTime / 1000 * C2) * Math.pow(Math.E, -beta.current * (currentTime / 1000));
186
+ bouncingSetStyle(easedDistance);
187
+ if (Math.abs(easedDistance) < threshold()) {
188
+ bouncingSetStyle(0);
189
+ mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] bounce back ends');
190
+ } else customRequestAnimationFrame(touchingEndBouncingBackFrame);
191
+ };
192
+ customRequestAnimationFrame(touchingEndBouncingBackFrame);
193
+ touchingEndBouncingBackEnableFlag.current = true;
194
+ }
195
+ function bounceableTouchStart(event) {
196
+ 'main thread';
197
+ startTouch.current = event.touches;
198
+ mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touch start');
199
+ bouncingTouchStartPosition.current = bouncingPositionInfo.current?.bouncingOffset ?? 0;
200
+ touchEndFrameEnableFlag.current = false;
201
+ touchingEndBouncingBackEnableFlag.current = false;
202
+ flingEndWithBouncingEnableFlag.current = false;
203
+ }
204
+ function bounceableTouchMove(event) {
205
+ 'main thread';
206
+ prevTouch.current = event.touches;
207
+ if (null === startTouch.current) mtsLog(true, '[lynx-ui-scroll-view][useBounce] ERROR! touch not started');
208
+ else {
209
+ const delta = getCurrentDelta(event);
210
+ const currentBouncingStatus = getBouncingStatus();
211
+ switch(currentBouncingStatus){
212
+ case bouncingStatus.upperBouncing:
213
+ enableScroll(false);
214
+ rubberEffect(1, delta);
215
+ mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touch move upper bouncing');
216
+ break;
217
+ case bouncingStatus.lowerBouncing:
218
+ enableScroll(false);
219
+ rubberEffect(-1, delta);
220
+ mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touch move lower bouncing');
221
+ break;
222
+ case bouncingStatus.alwaysBouncing:
223
+ mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touch move always bouncing');
224
+ if (alwaysBouncing) triggerRubberEffectIfCrossingEdge(event);
225
+ break;
226
+ case bouncingStatus.inScrollingRange:
227
+ mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touch move in scrolling range');
228
+ triggerRubberEffectIfCrossingEdge(event);
229
+ break;
230
+ default:
231
+ break;
232
+ }
233
+ }
234
+ }
235
+ function bounceableTouchEnd() {
236
+ 'main thread';
237
+ clearTouchInfo();
238
+ enableScroll(true);
239
+ mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touch end');
240
+ if (shouldBounceWhenTouchEnd(getBouncingStatus())) {
241
+ const startTime = Date.now();
242
+ const dragEndVelocity = bouncingPositionInfo.current?.velocity;
243
+ const dragEndPosition = bouncingPositionInfo.current?.bouncingOffset ?? 0;
244
+ if (isOverTriggerDistance()) triggerScrollToBouncesEvent(bouncingPositionInfo.current?.bouncingOffset > 0);
245
+ let currentVelocity = dragEndVelocity;
246
+ const touchEndProcessFrame = ()=>{
247
+ if (false === Boolean(touchEndFrameEnableFlag.current)) return;
248
+ mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] touch end process frame');
249
+ if (Math.abs(currentVelocity) <= threshold()) bouncingBack();
250
+ else {
251
+ mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] fling down start');
252
+ const distance = dragEndPosition + dragEndVelocity * (Math.pow(flingDeceleratingRate.current, Date.now() - startTime) - 1) / Math.log(flingDeceleratingRate.current);
253
+ bouncingSetStyle(distance);
254
+ currentVelocity = dragEndVelocity * Math.pow(flingDeceleratingRate.current, Date.now() - startTime);
255
+ if (touchEndFrameEnableFlag.current) customRequestAnimationFrame(touchEndProcessFrame);
256
+ }
257
+ };
258
+ customRequestAnimationFrame(touchEndProcessFrame);
259
+ touchEndFrameEnableFlag.current = true;
260
+ }
261
+ }
262
+ function bounceableHandleScroll(event) {
263
+ 'main thread';
264
+ scrollX.current = event.detail.scrollLeft;
265
+ scrollY.current = event.detail.scrollTop;
266
+ if (!isEmpty(prevScroll.current)) {
267
+ const prev = prevScroll.current;
268
+ const timeDuration = Date.now() - prev.timestamp;
269
+ if (timeDuration > 0) {
270
+ const deltaY = isVertical() ? event.detail.scrollTop - prev.detail.scrollTop : normalizedHorizontalValue(event.detail.scrollLeft - prev.detail.scrollLeft);
271
+ const velocity = deltaY / timeDuration;
272
+ if (Number.isFinite(velocity)) scrollVelocity.current = velocity;
273
+ }
274
+ }
275
+ mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] handle scroll near edge, scrollLeft: ${event.detail.scrollLeft}, scrollTop: ${event.detail.scrollTop}, velocity: ${scrollVelocity.current}`);
276
+ prevScroll.current = event;
277
+ }
278
+ function onUpperDisexposure(_event) {
279
+ 'main thread';
280
+ mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] upper disexposure');
281
+ toUpper.current = false;
282
+ }
283
+ function onUpperExposure(_event) {
284
+ 'main thread';
285
+ mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] upper exposure');
286
+ toUpper.current = true;
287
+ if ('upper' !== singleSidedBounce.current && 'both' !== singleSidedBounce.current) return;
288
+ if (prevScroll.current) {
289
+ startBouncingTouch.current = prevTouch.current;
290
+ startTouchBouncingDelta.current = bouncingPositionInfo.current?.bouncingOffset ?? 0;
291
+ } else if (Math.abs(scrollVelocity.current) > threshold()) {
292
+ const velocity = scrollVelocity.current;
293
+ let currentVelocity = velocity;
294
+ const startTime = Date.now();
295
+ mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] fling to upper event start, velocity: ${velocity}`);
296
+ let sentScrollToBouncesEvent = false;
297
+ const flingEndWithBouncingFrame = ()=>{
298
+ if (false === Boolean(flingEndWithBouncingEnableFlag.current)) return void mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] flingEndWithBouncingEnableFlag early return');
299
+ if (Math.abs(currentVelocity) <= threshold()) {
300
+ flingEndWithBouncingEnableFlag.current = false;
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');
303
+ bouncingBack();
304
+ } else {
305
+ const distance = currentVelocity * (Math.pow(flingDeceleratingRate.current, Date.now() - startTime) - 1) / Math.log(flingDeceleratingRate.current);
306
+ bouncingSetStyle(-distance);
307
+ if (!sentScrollToBouncesEvent && isOverTriggerDistance()) {
308
+ triggerScrollToBouncesEvent(bouncingPositionInfo.current?.bouncingOffset > 0);
309
+ sentScrollToBouncesEvent = true;
310
+ }
311
+ currentVelocity = velocity * Math.pow(flingDeceleratingRate.current, Date.now() - startTime);
312
+ if (flingEndWithBouncingEnableFlag.current) customRequestAnimationFrame(flingEndWithBouncingFrame);
313
+ }
314
+ };
315
+ customRequestAnimationFrame(flingEndWithBouncingFrame);
316
+ flingEndWithBouncingEnableFlag.current = true;
317
+ }
318
+ }
319
+ function onLowerDisexposure(_event) {
320
+ 'main thread';
321
+ mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] lower disexposure');
322
+ toLower.current = false;
323
+ }
324
+ function onLowerExposure(_event) {
325
+ 'main thread';
326
+ mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] lower exposure');
327
+ toLower.current = true;
328
+ if ('lower' !== singleSidedBounce.current && 'both' !== singleSidedBounce.current) return;
329
+ if (null !== prevTouch.current) {
330
+ startBouncingTouch.current = prevTouch.current;
331
+ startTouchBouncingDelta.current = bouncingPositionInfo.current?.bouncingOffset ?? 0;
332
+ } else if (enableBounceEventInFling && scrollVelocity.current > 0) {
333
+ const velocity = scrollVelocity.current;
334
+ mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] lower velocity: ${velocity}`);
335
+ if (Math.abs(velocity) > threshold()) {
336
+ let currentVelocity = velocity;
337
+ const startTime = Date.now();
338
+ mtsLog(debugLogEnabled, `[lynx-ui-scroll-view][useBounce] fling to lower event start, velocity: ${velocity}`);
339
+ let sentScrollToBouncesEvent = false;
340
+ const flingEndWithBouncingFrame = ()=>{
341
+ if (false === Boolean(flingEndWithBouncingEnableFlag.current)) return void mtsLog(debugLogEnabled, '[lynx-ui-scroll-view][useBounce] flingEndWithBouncingEnableFlag early return');
342
+ if (Math.abs(currentVelocity) <= threshold()) {
343
+ flingEndWithBouncingEnableFlag.current = false;
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');
346
+ bouncingBack();
347
+ } else {
348
+ const distance = currentVelocity * (Math.pow(flingDeceleratingRate.current, Date.now() - startTime) - 1) / Math.log(flingDeceleratingRate.current);
349
+ bouncingSetStyle(-distance);
350
+ if (!sentScrollToBouncesEvent && isOverTriggerDistance()) {
351
+ triggerScrollToBouncesEvent(bouncingPositionInfo.current?.bouncingOffset > 0);
352
+ sentScrollToBouncesEvent = true;
353
+ }
354
+ currentVelocity = velocity * Math.pow(flingDeceleratingRate.current, Date.now() - startTime);
355
+ if (flingEndWithBouncingEnableFlag) customRequestAnimationFrame(flingEndWithBouncingFrame);
356
+ }
357
+ };
358
+ customRequestAnimationFrame(flingEndWithBouncingFrame);
359
+ flingEndWithBouncingEnableFlag.current = true;
360
+ }
361
+ }
362
+ }
363
+ function bounceableLayoutChange(event) {
364
+ 'main thread';
365
+ height.current = (isAndroid() ? event.params?.height : event.detail?.height) ?? 0;
366
+ width.current = (isAndroid() ? event.params?.width : event.detail?.width) ?? 0;
367
+ }
368
+ return {
369
+ 'main-thread:bindtouchstart': bounceableTouchStart,
370
+ 'main-thread:bindtouchend': bounceableTouchEnd,
371
+ 'main-thread:bindtouchmove': bounceableTouchMove,
372
+ 'main-thread:bindlayoutchange': bounceableLayoutChange,
373
+ 'main-thread:bindscroll': bounceableHandleScroll,
374
+ onUpperExposure,
375
+ onUpperDisexposure,
376
+ onLowerExposure,
377
+ onLowerDisexposure
378
+ };
379
+ }
380
+ export { useBounce };
381
+
382
+ //# sourceMappingURL=useBounce.jsx.map