@lynx-js/lynx-ui-common 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.
Files changed (35) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/hooks/index.d.ts +0 -3
  3. package/dist/hooks/index.d.ts.map +1 -1
  4. package/dist/hooks/index.jsx +1 -3
  5. package/dist/hooks/index.jsx.map +1 -1
  6. package/dist/types/interfaces/BaseScrollEvents.d.ts +0 -1
  7. package/dist/types/interfaces/BaseScrollEvents.d.ts.map +1 -1
  8. package/dist/types/interfaces/LazyInterface.d.ts +0 -1
  9. package/dist/types/interfaces/LazyInterface.d.ts.map +1 -1
  10. package/dist/types/interfaces/index.d.ts +0 -2
  11. package/dist/types/interfaces/index.d.ts.map +1 -1
  12. package/package.json +1 -1
  13. package/src/hooks/index.ts +0 -3
  14. package/src/types/interfaces/BaseScrollEvents.ts +0 -1
  15. package/src/types/interfaces/LazyInterface.tsx +0 -1
  16. package/src/types/interfaces/index.ts +0 -2
  17. package/dist/hooks/useBounce.d.ts +0 -26
  18. package/dist/hooks/useBounce.d.ts.map +0 -1
  19. package/dist/hooks/useBounce.jsx +0 -383
  20. package/dist/hooks/useBounce.jsx.map +0 -1
  21. package/dist/hooks/useRefresh.d.ts +0 -24
  22. package/dist/hooks/useRefresh.d.ts.map +0 -1
  23. package/dist/hooks/useRefresh.jsx +0 -554
  24. package/dist/hooks/useRefresh.jsx.map +0 -1
  25. package/dist/types/interfaces/BounceableInterface.d.ts +0 -120
  26. package/dist/types/interfaces/BounceableInterface.d.ts.map +0 -1
  27. package/dist/types/interfaces/BounceableInterface.jsx +0 -0
  28. package/dist/types/interfaces/RefreshInterface.d.ts +0 -98
  29. package/dist/types/interfaces/RefreshInterface.d.ts.map +0 -1
  30. package/dist/types/interfaces/RefreshInterface.jsx +0 -10
  31. package/dist/types/interfaces/RefreshInterface.jsx.map +0 -1
  32. package/src/hooks/useBounce.tsx +0 -814
  33. package/src/hooks/useRefresh.ts +0 -1054
  34. package/src/types/interfaces/BounceableInterface.ts +0 -125
  35. package/src/types/interfaces/RefreshInterface.ts +0 -105
package/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # @lynx-js/lynx-ui-common
2
+
3
+ ## 3.131.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Migrate bounce and refresh hooks from common to ScrollView and FeedList. ([#119](https://github.com/lynx-family/lynx-ui/pull/119))
8
+
9
+ **BREAKING CHANGE**: `useBounce` and `useRefreshAndBounce` hooks are no longer exported from `@lynx-js/lynx-ui-common`.
10
+
11
+ ## 3.130.0
12
+
13
+ ### Patch Changes
14
+
15
+ - Fix an issue where using ReactiveValue causes an MTS error ([#79](https://github.com/lynx-family/lynx-ui/pull/79))
16
+
17
+ - Migrate away from `@/` imports. ([#79](https://github.com/lynx-family/lynx-ui/pull/79))
18
+
19
+ - optimize: fix type errors ([#79](https://github.com/lynx-family/lynx-ui/pull/79))
20
+
21
+ - Update files field in all packages to include LICENSE file. ([#79](https://github.com/lynx-family/lynx-ui/pull/79))
22
+
23
+ - fix: add a default fallback for dragEndVelocity for useRefresh. ([#79](https://github.com/lynx-family/lynx-ui/pull/79))
24
+
25
+ - fix: add a default fallback for dragEndVelocity; otherwise the condition is invalid when the user clicks LynxView to skip to another page. ([#79](https://github.com/lynx-family/lynx-ui/pull/79))
@@ -2,9 +2,6 @@ export { useUnmount } from './useUnmount';
2
2
  export { useGlobalEventListener } from './useGlobalEventListener';
3
3
  export { useLatest } from './useLatest';
4
4
  export { useRegisteredEvents } from './useRegisteredEvents';
5
- export { useRefreshAndBounce } from './useRefresh';
6
- export type { useRefreshAndBounceReturn } from './useRefresh';
7
- export { useBounce, type bounceHandlers } from './useBounce';
8
5
  export { useMemoizedFn } from './useMemoizedFn';
9
6
  export { usePrevious } from './usePrevious';
10
7
  export declare function useFirstRender(cb: () => void): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAE3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAClD,YAAY,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAQtD;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAUxD;AAED,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAU3D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,YAS9C,OAAO,EAAE,UAM7B;AAED,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAE7E,wBAAgB,WAAW,CACzB,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EAChC,KAAK,EAAE,MAAM,EACb,GAAG,UAAK,aAU+B,OAAO,EAAE,UASjD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAQtD;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAUxD;AAED,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAU3D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,YAS9C,OAAO,EAAE,UAM7B;AAED,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAE7E,wBAAgB,WAAW,CACzB,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EAChC,KAAK,EAAE,MAAM,EACb,GAAG,UAAK,aAU+B,OAAO,EAAE,UASjD"}
@@ -3,8 +3,6 @@ import { useUnmount } from "./useUnmount.jsx";
3
3
  import { useGlobalEventListener } from "./useGlobalEventListener.jsx";
4
4
  import { useLatest } from "./useLatest.jsx";
5
5
  import { useRegisteredEvents } from "./useRegisteredEvents.jsx";
6
- import { useRefreshAndBounce } from "./useRefresh.jsx";
7
- import { useBounce } from "./useBounce.jsx";
8
6
  import { useMemoizedFn } from "./useMemoizedFn.jsx";
9
7
  import { usePrevious } from "./usePrevious.jsx";
10
8
  import { useGCCollector } from "./useGCCollector.jsx";
@@ -68,6 +66,6 @@ function useThrottle(fn, delay, dep = []) {
68
66
  }
69
67
  }, dep);
70
68
  }
71
- export { useBounce, useFirstRender, useGCCollector, useGlobalEventListener, useJSFirstRender, useLatest, useLepusFirstRender, useMemoizedFn, usePersistCallback, usePrevious, useRefreshAndBounce, useRegisteredEvents, useThrottle, useUnmount };
69
+ export { useFirstRender, useGCCollector, useGlobalEventListener, useJSFirstRender, useLatest, useLepusFirstRender, useMemoizedFn, usePersistCallback, usePrevious, useRegisteredEvents, useThrottle, useUnmount };
72
70
 
73
71
  //# sourceMappingURL=index.jsx.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks/index.jsx","sources":["webpack://@lynx-js/lynx-ui-common/./src/hooks/index.ts"],"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 { useCallback, useEffect, useMemo, useRef } from '@lynx-js/react'\n\nexport { useUnmount } from './useUnmount'\nexport { useGlobalEventListener } from './useGlobalEventListener'\nexport { useLatest } from './useLatest'\nexport { useRegisteredEvents } from './useRegisteredEvents'\n\nexport { useRefreshAndBounce } from './useRefresh'\nexport type { useRefreshAndBounceReturn } from './useRefresh'\nexport { useBounce, type bounceHandlers } from './useBounce'\nexport { useMemoizedFn } from './useMemoizedFn'\nexport { usePrevious } from './usePrevious'\n\nexport function useFirstRender(cb: () => void): boolean {\n const isFirst = useRef(true)\n if (isFirst.current) {\n cb?.()\n isFirst.current = false\n return true\n }\n return isFirst.current\n}\n\nexport function useJSFirstRender(cb: () => void): boolean {\n const isJSFirst = useRef(true)\n if (isJSFirst.current) {\n if (!__LEPUS__) {\n cb?.()\n }\n isJSFirst.current = false\n return true\n }\n return isJSFirst.current\n}\n\nexport function useLepusFirstRender(cb: () => void): boolean {\n const isLepusFirst = useRef(true)\n if (isLepusFirst.current) {\n if (__LEPUS__) {\n cb?.()\n }\n isLepusFirst.current = false\n return true\n }\n return isLepusFirst.current\n}\n\n/**\n * @deprecated use useMemoizedFn instead\n */\nexport function usePersistCallback(fn: (...args: unknown[]) => void) {\n const ref = useRef<(...args: unknown[]) => void>(fn)\n ref.current = useMemo(\n function() {\n return fn\n },\n [fn],\n )\n return useCallback(\n function(...arg: unknown[]) {\n const fnn: (...arg2: unknown[]) => void = ref.current\n typeof ref.current === 'function' && fnn(...arg)\n },\n [ref],\n )\n}\n\nexport { useGCCollector, type UseGCCollectorOptions } from './useGCCollector'\n\nexport function useThrottle(\n fn: (...args: unknown[]) => void,\n delay: number,\n dep = [],\n) {\n const { current } = useRef({ fn, timer: 0 })\n useEffect(\n function() {\n current.fn = fn\n },\n [fn],\n )\n\n return useCallback(function f(...args: unknown[]) {\n if (!current.timer) {\n current.timer = setTimeout(() => {\n // @ts-expect-error Error\n delete current.timer\n }, delay) as unknown as number\n current.fn(...args)\n }\n }, dep)\n}\n"],"names":["useFirstRender","cb","isFirst","useRef","useJSFirstRender","isJSFirst","__LEPUS__","useLepusFirstRender","isLepusFirst","usePersistCallback","fn","ref","useMemo","useCallback","arg","fnn","useThrottle","delay","dep","current","useEffect","args","setTimeout"],"mappings":";;;;;;;;;;AAiBO,SAASA,eAAeC,EAAc;IAC3C,MAAMC,UAAUC,OAAO;IACvB,IAAID,QAAQ,OAAO,EAAE;QACnBD;QACAC,QAAQ,OAAO,GAAG;QAClB,OAAO;IACT;IACA,OAAOA,QAAQ,OAAO;AACxB;AAEO,SAASE,iBAAiBH,EAAc;IAC7C,MAAMI,YAAYF,OAAO;IACzB,IAAIE,UAAU,OAAO,EAAE;QACrB,IAAI,CAACC,WACHL;QAEFI,UAAU,OAAO,GAAG;QACpB,OAAO;IACT;IACA,OAAOA,UAAU,OAAO;AAC1B;AAEO,SAASE,oBAAoBN,EAAc;IAChD,MAAMO,eAAeL,OAAO;IAC5B,IAAIK,aAAa,OAAO,EAAE;QACxB,IAAIF,WACFL;QAEFO,aAAa,OAAO,GAAG;QACvB,OAAO;IACT;IACA,OAAOA,aAAa,OAAO;AAC7B;AAKO,SAASC,mBAAmBC,EAAgC;IACjE,MAAMC,MAAMR,OAAqCO;IACjDC,IAAI,OAAO,GAAGC,QACZ;QACE,OAAOF;IACT,GACA;QAACA;KAAG;IAEN,OAAOG,YACL,SAAS,GAAGC,GAAc;QACxB,MAAMC,MAAoCJ,IAAI,OAAO;QAC9B,cAAvB,OAAOA,IAAI,OAAO,IAAmBI,OAAOD;IAC9C,GACA;QAACH;KAAI;AAET;AAIO,SAASK,YACdN,EAAgC,EAChCO,KAAa,EACbC,MAAM,EAAE;IAER,MAAM,EAAEC,OAAO,EAAE,GAAGhB,OAAO;QAAEO;QAAI,OAAO;IAAE;IAC1CU,UACE;QACED,QAAQ,EAAE,GAAGT;IACf,GACA;QAACA;KAAG;IAGN,OAAOG,YAAY,SAAW,GAAGQ,IAAe;QAC9C,IAAI,CAACF,QAAQ,KAAK,EAAE;YAClBA,QAAQ,KAAK,GAAGG,WAAW;gBAEzB,OAAOH,QAAQ,KAAK;YACtB,GAAGF;YACHE,QAAQ,EAAE,IAAIE;QAChB;IACF,GAAGH;AACL"}
1
+ {"version":3,"file":"hooks/index.jsx","sources":["webpack://@lynx-js/lynx-ui-common/./src/hooks/index.ts"],"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 { useCallback, useEffect, useMemo, useRef } from '@lynx-js/react'\n\nexport { useUnmount } from './useUnmount'\nexport { useGlobalEventListener } from './useGlobalEventListener'\nexport { useLatest } from './useLatest'\nexport { useRegisteredEvents } from './useRegisteredEvents'\n\nexport { useMemoizedFn } from './useMemoizedFn'\nexport { usePrevious } from './usePrevious'\n\nexport function useFirstRender(cb: () => void): boolean {\n const isFirst = useRef(true)\n if (isFirst.current) {\n cb?.()\n isFirst.current = false\n return true\n }\n return isFirst.current\n}\n\nexport function useJSFirstRender(cb: () => void): boolean {\n const isJSFirst = useRef(true)\n if (isJSFirst.current) {\n if (!__LEPUS__) {\n cb?.()\n }\n isJSFirst.current = false\n return true\n }\n return isJSFirst.current\n}\n\nexport function useLepusFirstRender(cb: () => void): boolean {\n const isLepusFirst = useRef(true)\n if (isLepusFirst.current) {\n if (__LEPUS__) {\n cb?.()\n }\n isLepusFirst.current = false\n return true\n }\n return isLepusFirst.current\n}\n\n/**\n * @deprecated use useMemoizedFn instead\n */\nexport function usePersistCallback(fn: (...args: unknown[]) => void) {\n const ref = useRef<(...args: unknown[]) => void>(fn)\n ref.current = useMemo(\n function() {\n return fn\n },\n [fn],\n )\n return useCallback(\n function(...arg: unknown[]) {\n const fnn: (...arg2: unknown[]) => void = ref.current\n typeof ref.current === 'function' && fnn(...arg)\n },\n [ref],\n )\n}\n\nexport { useGCCollector, type UseGCCollectorOptions } from './useGCCollector'\n\nexport function useThrottle(\n fn: (...args: unknown[]) => void,\n delay: number,\n dep = [],\n) {\n const { current } = useRef({ fn, timer: 0 })\n useEffect(\n function() {\n current.fn = fn\n },\n [fn],\n )\n\n return useCallback(function f(...args: unknown[]) {\n if (!current.timer) {\n current.timer = setTimeout(() => {\n // @ts-expect-error Error\n delete current.timer\n }, delay) as unknown as number\n current.fn(...args)\n }\n }, dep)\n}\n"],"names":["useFirstRender","cb","isFirst","useRef","useJSFirstRender","isJSFirst","__LEPUS__","useLepusFirstRender","isLepusFirst","usePersistCallback","fn","ref","useMemo","useCallback","arg","fnn","useThrottle","delay","dep","current","useEffect","args","setTimeout"],"mappings":";;;;;;;;AAcO,SAASA,eAAeC,EAAc;IAC3C,MAAMC,UAAUC,OAAO;IACvB,IAAID,QAAQ,OAAO,EAAE;QACnBD;QACAC,QAAQ,OAAO,GAAG;QAClB,OAAO;IACT;IACA,OAAOA,QAAQ,OAAO;AACxB;AAEO,SAASE,iBAAiBH,EAAc;IAC7C,MAAMI,YAAYF,OAAO;IACzB,IAAIE,UAAU,OAAO,EAAE;QACrB,IAAI,CAACC,WACHL;QAEFI,UAAU,OAAO,GAAG;QACpB,OAAO;IACT;IACA,OAAOA,UAAU,OAAO;AAC1B;AAEO,SAASE,oBAAoBN,EAAc;IAChD,MAAMO,eAAeL,OAAO;IAC5B,IAAIK,aAAa,OAAO,EAAE;QACxB,IAAIF,WACFL;QAEFO,aAAa,OAAO,GAAG;QACvB,OAAO;IACT;IACA,OAAOA,aAAa,OAAO;AAC7B;AAKO,SAASC,mBAAmBC,EAAgC;IACjE,MAAMC,MAAMR,OAAqCO;IACjDC,IAAI,OAAO,GAAGC,QACZ;QACE,OAAOF;IACT,GACA;QAACA;KAAG;IAEN,OAAOG,YACL,SAAS,GAAGC,GAAc;QACxB,MAAMC,MAAoCJ,IAAI,OAAO;QAC9B,cAAvB,OAAOA,IAAI,OAAO,IAAmBI,OAAOD;IAC9C,GACA;QAACH;KAAI;AAET;AAIO,SAASK,YACdN,EAAgC,EAChCO,KAAa,EACbC,MAAM,EAAE;IAER,MAAM,EAAEC,OAAO,EAAE,GAAGhB,OAAO;QAAEO;QAAI,OAAO;IAAE;IAC1CU,UACE;QACED,QAAQ,EAAE,GAAGT;IACf,GACA;QAACA;KAAG;IAGN,OAAOG,YAAY,SAAW,GAAGQ,IAAe;QAC9C,IAAI,CAACF,QAAQ,KAAK,EAAE;YAClBA,QAAQ,KAAK,GAAGG,WAAW;gBAEzB,OAAOH,QAAQ,KAAK;YACtB,GAAGF;YACHE,QAAQ,EAAE,IAAIE;QAChB;IACF,GAAGH;AACL"}
@@ -3,7 +3,6 @@ export interface BaseScrollEvents {
3
3
  /**
4
4
  * Being triggered when scrolling occurs.
5
5
  * @zh 滚动时触发。
6
- * @defaultValue undefined
7
6
  * @eventProperty
8
7
  * @Android
9
8
  * @iOS
@@ -1 +1 @@
1
- {"version":3,"file":"BaseScrollEvents.d.ts","sourceRoot":"","sources":["../../../src/types/interfaces/BaseScrollEvents.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,eAAe,IAAI,uBAAuB,EAC1C,WAAW,EACZ,MAAM,gBAAgB,CAAA;AAEvB,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,KAAK,IAAI,CAAA;IACnC;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,uBAAuB,CAAC,eAAe,CAAC,KAAK,IAAI,CAAA;IACnE;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,CAAC,CAAC,EAAE,uBAAuB,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAA;IAC3E;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,CAAC,CAAC,EAAE,uBAAuB,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAA;CAC5E"}
1
+ {"version":3,"file":"BaseScrollEvents.d.ts","sourceRoot":"","sources":["../../../src/types/interfaces/BaseScrollEvents.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,eAAe,IAAI,uBAAuB,EAC1C,WAAW,EACZ,MAAM,gBAAgB,CAAA;AAEvB,MAAM,WAAW,gBAAgB;IAC/B;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,KAAK,IAAI,CAAA;IACnC;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,uBAAuB,CAAC,eAAe,CAAC,KAAK,IAAI,CAAA;IACnE;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,CAAC,CAAC,EAAE,uBAAuB,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAA;IAC3E;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,CAAC,CAAC,EAAE,uBAAuB,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAA;CAC5E"}
@@ -11,7 +11,6 @@ export interface EnableLazyMode {
11
11
  /**
12
12
  * Be used to mark the exposure timing of lazy loading. Please ensure that it is unique throughout the page.
13
13
  * @zh 用于标记懒加载的曝光时机。请确保在整个页面中是唯一的。
14
- * @defaultValue undefined
15
14
  * @Android
16
15
  * @iOS
17
16
  */
@@ -1 +1 @@
1
- {"version":3,"file":"LazyInterface.d.ts","sourceRoot":"","sources":["../../../src/types/interfaces/LazyInterface.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,UAAU,EAAE,OAAO,CAAA;IACnB;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;;;OAMG;IACH,kBAAkB,EAAE,aAAa,CAAA;IACjC;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,GAAG,MAAM,IAAI,GAAG,GAAG,MAAM,KAAK,CAAA;IAC5C;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,GAAG,MAAM,IAAI,GAAG,GAAG,MAAM,KAAK,CAAA;IAC/C;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,GAAG,MAAM,IAAI,GAAG,GAAG,MAAM,KAAK,CAAA;IAC7C;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,GAAG,MAAM,IAAI,GAAG,GAAG,MAAM,KAAK,CAAA;IAC9C;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,KAAK,CAAA;CAClB;AAED,MAAM,MAAM,WAAW,GAAG,cAAc,GAAG,eAAe,CAAA"}
1
+ {"version":3,"file":"LazyInterface.d.ts","sourceRoot":"","sources":["../../../src/types/interfaces/LazyInterface.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,UAAU,EAAE,OAAO,CAAA;IACnB;;;;;OAKG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;;;OAMG;IACH,kBAAkB,EAAE,aAAa,CAAA;IACjC;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,GAAG,MAAM,IAAI,GAAG,GAAG,MAAM,KAAK,CAAA;IAC5C;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,GAAG,MAAM,IAAI,GAAG,GAAG,MAAM,KAAK,CAAA;IAC/C;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,GAAG,MAAM,IAAI,GAAG,GAAG,MAAM,KAAK,CAAA;IAC7C;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,GAAG,MAAM,IAAI,GAAG,GAAG,MAAM,KAAK,CAAA;IAC9C;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,KAAK,CAAA;CAClB;AAED,MAAM,MAAM,WAAW,GAAG,cAAc,GAAG,eAAe,CAAA"}
@@ -2,9 +2,7 @@ import type { CSSProperties } from '@lynx-js/types';
2
2
  export type * from './BaseScrollEvents';
3
3
  export type * from './BaseUIEvents';
4
4
  export type * from './BaseUIProps';
5
- export type * from './BounceableInterface';
6
5
  export type * from './LazyInterface';
7
- export type * from './RefreshInterface';
8
6
  export interface Point {
9
7
  x: number;
10
8
  y: number;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/interfaces/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,mBAAmB,oBAAoB,CAAA;AACvC,mBAAmB,gBAAgB,CAAA;AACnC,mBAAmB,eAAe,CAAA;AAClC,mBAAmB,uBAAuB,CAAA;AAC1C,mBAAmB,iBAAiB,CAAA;AACpC,mBAAmB,oBAAoB,CAAA;AAEvC,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AAED,MAAM,WAAW,IAAI;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;CACZ;AAGD,MAAM,WAAW,mBAAmB;IAClC;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/interfaces/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,mBAAmB,oBAAoB,CAAA;AACvC,mBAAmB,gBAAgB,CAAA;AACnC,mBAAmB,eAAe,CAAA;AAClC,mBAAmB,iBAAiB,CAAA;AAEpC,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AAED,MAAM,WAAW,IAAI;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;CACZ;AAGD,MAAM,WAAW,mBAAmB;IAClC;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/lynx-ui-common",
3
- "version": "0.0.0",
3
+ "version": "3.131.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lynx-family/lynx-ui.git",
@@ -9,9 +9,6 @@ export { useGlobalEventListener } from './useGlobalEventListener'
9
9
  export { useLatest } from './useLatest'
10
10
  export { useRegisteredEvents } from './useRegisteredEvents'
11
11
 
12
- export { useRefreshAndBounce } from './useRefresh'
13
- export type { useRefreshAndBounceReturn } from './useRefresh'
14
- export { useBounce, type bounceHandlers } from './useBounce'
15
12
  export { useMemoizedFn } from './useMemoizedFn'
16
13
  export { usePrevious } from './usePrevious'
17
14
 
@@ -11,7 +11,6 @@ export interface BaseScrollEvents {
11
11
  /**
12
12
  * Being triggered when scrolling occurs.
13
13
  * @zh 滚动时触发。
14
- * @defaultValue undefined
15
14
  * @eventProperty
16
15
  * @Android
17
16
  * @iOS
@@ -16,7 +16,6 @@ export interface EnableLazyMode {
16
16
  /**
17
17
  * Be used to mark the exposure timing of lazy loading. Please ensure that it is unique throughout the page.
18
18
  * @zh 用于标记懒加载的曝光时机。请确保在整个页面中是唯一的。
19
- * @defaultValue undefined
20
19
  * @Android
21
20
  * @iOS
22
21
  */
@@ -7,9 +7,7 @@ import type { CSSProperties } from '@lynx-js/types'
7
7
  export type * from './BaseScrollEvents'
8
8
  export type * from './BaseUIEvents'
9
9
  export type * from './BaseUIProps'
10
- export type * from './BounceableInterface'
11
10
  export type * from './LazyInterface'
12
- export type * from './RefreshInterface'
13
11
 
14
12
  export interface Point {
15
13
  x: number
@@ -1,26 +0,0 @@
1
- import type { CommonEvent, MainThread, ScrollEvent } from '@lynx-js/types';
2
- import type { BounceableBasicProps } from '../types';
3
- export interface useBounceOptions {
4
- bounceableOptions: BounceableBasicProps;
5
- /**
6
- * idSelector of scroll container
7
- */
8
- id?: string;
9
- /**
10
- * scroll direction
11
- */
12
- scrollOrientation: 'vertical' | 'horizontal';
13
- }
14
- export interface bounceHandlers {
15
- 'main-thread:bindtouchstart': (event: MainThread.TouchEvent) => void;
16
- 'main-thread:bindtouchend': () => void;
17
- 'main-thread:bindtouchmove': (event: MainThread.TouchEvent) => void;
18
- 'main-thread:bindlayoutchange': (event: CommonEvent) => void;
19
- 'main-thread:bindscroll': (event: ScrollEvent) => void;
20
- onUpperExposure: (_event: CommonEvent) => void;
21
- onUpperDisexposure: (_event: CommonEvent) => void;
22
- onLowerExposure: (_event: CommonEvent) => void;
23
- onLowerDisexposure: (_event: CommonEvent) => void;
24
- }
25
- export declare function useBounce(options: useBounceOptions): bounceHandlers;
26
- //# sourceMappingURL=useBounce.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useBounce.d.ts","sourceRoot":"","sources":["../../src/hooks/useBounce.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE1E,OAAO,KAAK,EAAE,oBAAoB,EAAuB,MAAM,UAAU,CAAA;AAGzE,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB,EAAE,oBAAoB,CAAA;IACvC;;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,CA0wBnE"}
@@ -1,383 +0,0 @@
1
- import { runOnBackground, useMainThreadRef } from "@lynx-js/react";
2
- import { selectorMT } from "../utils/selector.jsx";
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