@lynx-js/lynx-ui-common 3.130.0 → 3.133.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/hooks/index.d.ts +1 -3
  3. package/dist/hooks/index.d.ts.map +1 -1
  4. package/dist/hooks/index.jsx +2 -3
  5. package/dist/hooks/index.jsx.map +1 -1
  6. package/dist/hooks/usePreCommit.d.ts +15 -0
  7. package/dist/hooks/usePreCommit.d.ts.map +1 -0
  8. package/dist/hooks/usePreCommit.jsx +49 -0
  9. package/dist/hooks/usePreCommit.jsx.map +1 -0
  10. package/dist/types/interfaces/BaseScrollEvents.d.ts +0 -1
  11. package/dist/types/interfaces/BaseScrollEvents.d.ts.map +1 -1
  12. package/dist/types/interfaces/LazyInterface.d.ts +0 -1
  13. package/dist/types/interfaces/LazyInterface.d.ts.map +1 -1
  14. package/dist/types/interfaces/index.d.ts +0 -2
  15. package/dist/types/interfaces/index.d.ts.map +1 -1
  16. package/dist/utils/areDepsEqual.d.ts +6 -0
  17. package/dist/utils/areDepsEqual.d.ts.map +1 -0
  18. package/dist/utils/areDepsEqual.jsx +9 -0
  19. package/dist/utils/areDepsEqual.jsx.map +1 -0
  20. package/package.json +3 -3
  21. package/src/hooks/docs/useBounce.mdx +0 -1
  22. package/src/hooks/docs/useRefresh.mdx +0 -1
  23. package/src/hooks/index.ts +1 -3
  24. package/src/hooks/usePreCommit.tsx +111 -0
  25. package/src/types/interfaces/BaseScrollEvents.ts +0 -1
  26. package/src/types/interfaces/LazyInterface.tsx +0 -1
  27. package/src/types/interfaces/index.ts +0 -2
  28. package/src/utils/areDepsEqual.ts +26 -0
  29. package/dist/hooks/useBounce.d.ts +0 -26
  30. package/dist/hooks/useBounce.d.ts.map +0 -1
  31. package/dist/hooks/useBounce.jsx +0 -383
  32. package/dist/hooks/useBounce.jsx.map +0 -1
  33. package/dist/hooks/useRefresh.d.ts +0 -24
  34. package/dist/hooks/useRefresh.d.ts.map +0 -1
  35. package/dist/hooks/useRefresh.jsx +0 -554
  36. package/dist/hooks/useRefresh.jsx.map +0 -1
  37. package/dist/types/interfaces/BounceableInterface.d.ts +0 -120
  38. package/dist/types/interfaces/BounceableInterface.d.ts.map +0 -1
  39. package/dist/types/interfaces/BounceableInterface.jsx +0 -0
  40. package/dist/types/interfaces/RefreshInterface.d.ts +0 -98
  41. package/dist/types/interfaces/RefreshInterface.d.ts.map +0 -1
  42. package/dist/types/interfaces/RefreshInterface.jsx +0 -10
  43. package/dist/types/interfaces/RefreshInterface.jsx.map +0 -1
  44. package/src/hooks/useBounce.tsx +0 -814
  45. package/src/hooks/useRefresh.ts +0 -1054
  46. package/src/types/interfaces/BounceableInterface.ts +0 -125
  47. package/src/types/interfaces/RefreshInterface.ts +0 -105
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @lynx-js/lynx-ui-common
2
2
 
3
+ ## 3.133.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add an experimental `usePreCommit` hook for running main-thread work before native commit. ([#188](https://github.com/lynx-family/lynx-ui/pull/188))
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
+
3
17
  ## 3.130.0
4
18
 
5
19
  ### Patch Changes
@@ -2,11 +2,9 @@ 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';
7
+ export { supportUsePreCommit, usePreCommit } from './usePreCommit';
10
8
  export declare function useFirstRender(cb: () => void): boolean;
11
9
  export declare function useJSFirstRender(cb: () => void): boolean;
12
10
  export declare function useLepusFirstRender(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;AAC3C,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElE,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,10 +3,9 @@ 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";
8
+ import { supportUsePreCommit, usePreCommit } from "./usePreCommit.jsx";
10
9
  import { useGCCollector } from "./useGCCollector.jsx";
11
10
  function useFirstRender(cb) {
12
11
  const isFirst = useRef(true);
@@ -68,6 +67,6 @@ function useThrottle(fn, delay, dep = []) {
68
67
  }
69
68
  }, dep);
70
69
  }
71
- export { useBounce, useFirstRender, useGCCollector, useGlobalEventListener, useJSFirstRender, useLatest, useLepusFirstRender, useMemoizedFn, usePersistCallback, usePrevious, useRefreshAndBounce, useRegisteredEvents, useThrottle, useUnmount };
70
+ export { supportUsePreCommit, useFirstRender, useGCCollector, useGlobalEventListener, useJSFirstRender, useLatest, useLepusFirstRender, useMemoizedFn, usePersistCallback, usePreCommit, usePrevious, useRegisteredEvents, useThrottle, useUnmount };
72
71
 
73
72
  //# 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'\nexport { supportUsePreCommit, usePreCommit } from './usePreCommit'\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":";;;;;;;;;AAeO,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"}
@@ -0,0 +1,15 @@
1
+ import type { DependencyList } from '@lynx-js/react';
2
+ declare global {
3
+ var __setEomShouldFlushElementTree: ((value: boolean) => void) | undefined;
4
+ var __eomFlushHoldCount: number | undefined;
5
+ }
6
+ export declare function supportUsePreCommit(): boolean;
7
+ /**
8
+ * An experimental hook dedicated to make MTS run on firstScreenPaint
9
+ * Can be used starting from ReactLynx 0.113.0
10
+ * @experimental
11
+ * @param cb A main-thread callback to run on firstScreen
12
+ * @param deps Dependency array - callback only executes when dependencies change
13
+ */
14
+ export declare function usePreCommit(cb: () => void, deps?: DependencyList): void;
15
+ //# sourceMappingURL=usePreCommit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePreCommit.d.ts","sourceRoot":"","sources":["../../src/hooks/usePreCommit.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAUpD,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,8BAA8B,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,SAAS,CAAA;IAC1E,IAAI,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAA;CAC5C;AAiCD,wBAAgB,mBAAmB,YAElC;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,IAAI,CAAC,EAAE,cAAc,QAgDjE"}
@@ -0,0 +1,49 @@
1
+ import { runOnMainThread, useRef } from "@lynx-js/react";
2
+ import { runWorkletCtx, setEomShouldFlushElementTree } from "@lynx-js/react/worklet-runtime/bindings";
3
+ import { areDepsEqual } from "../utils/areDepsEqual.jsx";
4
+ const setEomShouldFlush = setEomShouldFlushElementTree;
5
+ let eomFlushHoldCount = 0;
6
+ function holdEomFlush() {
7
+ eomFlushHoldCount += 1;
8
+ if (1 === eomFlushHoldCount) setEomShouldFlush(false);
9
+ }
10
+ function releaseEomFlush() {
11
+ if (0 === eomFlushHoldCount) return;
12
+ eomFlushHoldCount -= 1;
13
+ if (0 === eomFlushHoldCount) setEomShouldFlush(true);
14
+ }
15
+ if (__MAIN_THREAD__) globalThis.__setEomShouldFlushElementTree = setEomShouldFlush;
16
+ function supportUsePreCommit() {
17
+ return 'function' == typeof setEomShouldFlushElementTree;
18
+ }
19
+ function usePreCommit(cb, deps) {
20
+ const prevDepsRef = useRef(void 0);
21
+ const depsChanged = !areDepsEqual(prevDepsRef.current, deps);
22
+ prevDepsRef.current = deps;
23
+ if (!depsChanged) return;
24
+ if (__MAIN_THREAD__) {
25
+ holdEomFlush();
26
+ Promise.resolve().then(()=>{
27
+ try {
28
+ runWorkletCtx(cb, []);
29
+ } catch (e) {
30
+ console.error('Error occurred in preCommit hook', e);
31
+ } finally{
32
+ releaseEomFlush();
33
+ }
34
+ });
35
+ } else runOnMainThread(()=>{
36
+ 'main thread';
37
+ globalThis.__eomFlushHoldCount = (globalThis.__eomFlushHoldCount ?? 0) + 1;
38
+ if (1 === globalThis.__eomFlushHoldCount) globalThis.__setEomShouldFlushElementTree?.(false);
39
+ try {
40
+ cb();
41
+ } finally{
42
+ globalThis.__eomFlushHoldCount = Math.max((globalThis.__eomFlushHoldCount ?? 1) - 1, 0);
43
+ if (0 === globalThis.__eomFlushHoldCount) globalThis.__setEomShouldFlushElementTree?.(true);
44
+ }
45
+ })();
46
+ }
47
+ export { supportUsePreCommit, usePreCommit };
48
+
49
+ //# sourceMappingURL=usePreCommit.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks/usePreCommit.jsx","sources":["webpack://@lynx-js/lynx-ui-common/./src/hooks/usePreCommit.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 { runOnMainThread, useRef } from '@lynx-js/react'\nimport type { DependencyList } from '@lynx-js/react'\n\nimport {\n runWorkletCtx,\n setEomShouldFlushElementTree,\n} from '@lynx-js/react/worklet-runtime/bindings'\nimport type { Worklet } from '@lynx-js/react/worklet-runtime/bindings'\n\nimport { areDepsEqual } from '../utils/areDepsEqual'\n\ndeclare global {\n var __setEomShouldFlushElementTree: ((value: boolean) => void) | undefined\n var __eomFlushHoldCount: number | undefined\n}\n\nconst setEomShouldFlush = setEomShouldFlushElementTree as unknown as (\n value: boolean,\n) => void\n\nlet eomFlushHoldCount = 0\n\nfunction holdEomFlush() {\n eomFlushHoldCount += 1\n if (eomFlushHoldCount === 1) {\n setEomShouldFlush(false)\n }\n}\n\nfunction releaseEomFlush() {\n if (eomFlushHoldCount === 0) {\n return\n }\n\n eomFlushHoldCount -= 1\n if (eomFlushHoldCount === 0) {\n setEomShouldFlush(true)\n }\n}\n\n/**\n * Use this hack to prevent setEomShouldFlushElementTree being in the MTS closure\n */\nif (__MAIN_THREAD__) {\n globalThis.__setEomShouldFlushElementTree = setEomShouldFlush\n}\n\nexport function supportUsePreCommit() {\n return typeof setEomShouldFlushElementTree === 'function'\n}\n\n/**\n * An experimental hook dedicated to make MTS run on firstScreenPaint\n * Can be used starting from ReactLynx 0.113.0\n * @experimental\n * @param cb A main-thread callback to run on firstScreen\n * @param deps Dependency array - callback only executes when dependencies change\n */\nexport function usePreCommit(cb: () => void, deps?: DependencyList) {\n const prevDepsRef = useRef<DependencyList | undefined>(undefined)\n\n // Check if dependencies have changed\n const depsChanged = !areDepsEqual(prevDepsRef.current, deps)\n\n // Update the previous deps for next render\n prevDepsRef.current = deps\n\n // Only run if dependencies changed\n if (!depsChanged) {\n return\n }\n\n // For the Initial Frame Render\n if (__MAIN_THREAD__) {\n holdEomFlush()\n Promise.resolve().then(() => {\n try {\n runWorkletCtx(cb as unknown as Worklet, [])\n } catch (e) {\n console.error('Error occurred in preCommit hook', e)\n } finally {\n releaseEomFlush()\n }\n })\n } else {\n runOnMainThread(() => {\n 'main thread'\n\n globalThis.__eomFlushHoldCount = (globalThis.__eomFlushHoldCount ?? 0) + 1\n if (globalThis.__eomFlushHoldCount === 1) {\n globalThis.__setEomShouldFlushElementTree?.(false)\n }\n\n try {\n cb()\n } finally {\n globalThis.__eomFlushHoldCount = Math.max(\n (globalThis.__eomFlushHoldCount ?? 1) - 1,\n 0,\n )\n if (globalThis.__eomFlushHoldCount === 0) {\n globalThis.__setEomShouldFlushElementTree?.(true)\n }\n }\n })()\n }\n}\n"],"names":["setEomShouldFlush","setEomShouldFlushElementTree","eomFlushHoldCount","holdEomFlush","releaseEomFlush","__MAIN_THREAD__","globalThis","supportUsePreCommit","usePreCommit","cb","deps","prevDepsRef","useRef","undefined","depsChanged","areDepsEqual","Promise","runWorkletCtx","e","console","runOnMainThread","Math"],"mappings":";;;AAoBA,MAAMA,oBAAoBC;AAI1B,IAAIC,oBAAoB;AAExB,SAASC;IACPD,qBAAqB;IACrB,IAAIA,AAAsB,MAAtBA,mBACFF,kBAAkB;AAEtB;AAEA,SAASI;IACP,IAAIF,AAAsB,MAAtBA,mBACF;IAGFA,qBAAqB;IACrB,IAAIA,AAAsB,MAAtBA,mBACFF,kBAAkB;AAEtB;AAKA,IAAIK,iBACFC,WAAW,8BAA8B,GAAGN;AAGvC,SAASO;IACd,OAAO,AAAwC,cAAxC,OAAON;AAChB;AASO,SAASO,aAAaC,EAAc,EAAEC,IAAqB;IAChE,MAAMC,cAAcC,OAAmCC;IAGvD,MAAMC,cAAc,CAACC,aAAaJ,YAAY,OAAO,EAAED;IAGvDC,YAAY,OAAO,GAAGD;IAGtB,IAAI,CAACI,aACH;IAIF,IAAIT,iBAAiB;QACnBF;QACAa,QAAQ,OAAO,GAAG,IAAI,CAAC;YACrB,IAAI;gBACFC,cAAcR,IAA0B,EAAE;YAC5C,EAAE,OAAOS,GAAG;gBACVC,QAAQ,KAAK,CAAC,oCAAoCD;YACpD,SAAU;gBACRd;YACF;QACF;IACF,OACEgB,gBAAgB;QACd;QAEAd,WAAW,mBAAmB,GAAIA,AAAAA,CAAAA,WAAW,mBAAmB,IAAI,KAAK;QACzE,IAAIA,AAAmC,MAAnCA,WAAW,mBAAmB,EAChCA,WAAW,8BAA8B,GAAG;QAG9C,IAAI;YACFG;QACF,SAAU;YACRH,WAAW,mBAAmB,GAAGe,KAAK,GAAG,CACtCf,AAAAA,CAAAA,WAAW,mBAAmB,IAAI,KAAK,GACxC;YAEF,IAAIA,AAAmC,MAAnCA,WAAW,mBAAmB,EAChCA,WAAW,8BAA8B,GAAG;QAEhD;IACF;AAEJ"}
@@ -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"}
@@ -0,0 +1,6 @@
1
+ import type { DependencyList } from '@lynx-js/react';
2
+ /**
3
+ * Compares two dependency arrays
4
+ */
5
+ export declare function areDepsEqual(prevDeps: DependencyList | undefined, nextDeps: DependencyList | undefined): boolean;
6
+ //# sourceMappingURL=areDepsEqual.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"areDepsEqual.d.ts","sourceRoot":"","sources":["../../src/utils/areDepsEqual.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;GAEG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,cAAc,GAAG,SAAS,EACpC,QAAQ,EAAE,cAAc,GAAG,SAAS,GACnC,OAAO,CAaT"}
@@ -0,0 +1,9 @@
1
+ function areDepsEqual(prevDeps, nextDeps) {
2
+ if (void 0 === prevDeps || void 0 === nextDeps) return false;
3
+ if (prevDeps.length !== nextDeps.length) return false;
4
+ for(let i = 0; i < prevDeps.length; i++)if (!Object.is(prevDeps[i], nextDeps[i])) return false;
5
+ return true;
6
+ }
7
+ export { areDepsEqual };
8
+
9
+ //# sourceMappingURL=areDepsEqual.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils/areDepsEqual.jsx","sources":["webpack://@lynx-js/lynx-ui-common/./src/utils/areDepsEqual.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 type { DependencyList } from '@lynx-js/react'\n\n/**\n * Compares two dependency arrays\n */\nexport function areDepsEqual(\n prevDeps: DependencyList | undefined,\n nextDeps: DependencyList | undefined,\n): boolean {\n if (prevDeps === undefined || nextDeps === undefined) {\n return false\n }\n if (prevDeps.length !== nextDeps.length) {\n return false\n }\n for (let i = 0; i < prevDeps.length; i++) {\n if (!Object.is(prevDeps[i], nextDeps[i])) {\n return false\n }\n }\n return true\n}\n"],"names":["areDepsEqual","prevDeps","nextDeps","undefined","i","Object"],"mappings":"AASO,SAASA,aACdC,QAAoC,EACpCC,QAAoC;IAEpC,IAAID,AAAaE,WAAbF,YAA0BC,AAAaC,WAAbD,UAC5B,OAAO;IAET,IAAID,SAAS,MAAM,KAAKC,SAAS,MAAM,EACrC,OAAO;IAET,IAAK,IAAIE,IAAI,GAAGA,IAAIH,SAAS,MAAM,EAAEG,IACnC,IAAI,CAACC,OAAO,EAAE,CAACJ,QAAQ,CAACG,EAAE,EAAEF,QAAQ,CAACE,EAAE,GACrC,OAAO;IAGX,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/lynx-ui-common",
3
- "version": "3.130.0",
3
+ "version": "3.133.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lynx-family/lynx-ui.git",
@@ -26,10 +26,10 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@lynx-js/gesture-runtime": "2.1.1",
29
- "@lynx-js/react-use": "0.0.7"
29
+ "@lynx-js/react-use": "0.1.3"
30
30
  },
31
31
  "devDependencies": {
32
- "@lynx-js/react": "0.113.0",
32
+ "@lynx-js/react": "0.114.0",
33
33
  "@lynx-js/types": "3.6.0",
34
34
  "@rslib/core": "^0.16.0",
35
35
  "@types/react": "^18.3.8",
@@ -1,2 +1 @@
1
1
  # useBounce
2
-
@@ -1,2 +1 @@
1
1
  # useRefresh
2
-
@@ -9,11 +9,9 @@ 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'
14
+ export { supportUsePreCommit, usePreCommit } from './usePreCommit'
17
15
 
18
16
  export function useFirstRender(cb: () => void): boolean {
19
17
  const isFirst = useRef(true)
@@ -0,0 +1,111 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ import { runOnMainThread, useRef } from '@lynx-js/react'
6
+ import type { DependencyList } from '@lynx-js/react'
7
+
8
+ import {
9
+ runWorkletCtx,
10
+ setEomShouldFlushElementTree,
11
+ } from '@lynx-js/react/worklet-runtime/bindings'
12
+ import type { Worklet } from '@lynx-js/react/worklet-runtime/bindings'
13
+
14
+ import { areDepsEqual } from '../utils/areDepsEqual'
15
+
16
+ declare global {
17
+ var __setEomShouldFlushElementTree: ((value: boolean) => void) | undefined
18
+ var __eomFlushHoldCount: number | undefined
19
+ }
20
+
21
+ const setEomShouldFlush = setEomShouldFlushElementTree as unknown as (
22
+ value: boolean,
23
+ ) => void
24
+
25
+ let eomFlushHoldCount = 0
26
+
27
+ function holdEomFlush() {
28
+ eomFlushHoldCount += 1
29
+ if (eomFlushHoldCount === 1) {
30
+ setEomShouldFlush(false)
31
+ }
32
+ }
33
+
34
+ function releaseEomFlush() {
35
+ if (eomFlushHoldCount === 0) {
36
+ return
37
+ }
38
+
39
+ eomFlushHoldCount -= 1
40
+ if (eomFlushHoldCount === 0) {
41
+ setEomShouldFlush(true)
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Use this hack to prevent setEomShouldFlushElementTree being in the MTS closure
47
+ */
48
+ if (__MAIN_THREAD__) {
49
+ globalThis.__setEomShouldFlushElementTree = setEomShouldFlush
50
+ }
51
+
52
+ export function supportUsePreCommit() {
53
+ return typeof setEomShouldFlushElementTree === 'function'
54
+ }
55
+
56
+ /**
57
+ * An experimental hook dedicated to make MTS run on firstScreenPaint
58
+ * Can be used starting from ReactLynx 0.113.0
59
+ * @experimental
60
+ * @param cb A main-thread callback to run on firstScreen
61
+ * @param deps Dependency array - callback only executes when dependencies change
62
+ */
63
+ export function usePreCommit(cb: () => void, deps?: DependencyList) {
64
+ const prevDepsRef = useRef<DependencyList | undefined>(undefined)
65
+
66
+ // Check if dependencies have changed
67
+ const depsChanged = !areDepsEqual(prevDepsRef.current, deps)
68
+
69
+ // Update the previous deps for next render
70
+ prevDepsRef.current = deps
71
+
72
+ // Only run if dependencies changed
73
+ if (!depsChanged) {
74
+ return
75
+ }
76
+
77
+ // For the Initial Frame Render
78
+ if (__MAIN_THREAD__) {
79
+ holdEomFlush()
80
+ Promise.resolve().then(() => {
81
+ try {
82
+ runWorkletCtx(cb as unknown as Worklet, [])
83
+ } catch (e) {
84
+ console.error('Error occurred in preCommit hook', e)
85
+ } finally {
86
+ releaseEomFlush()
87
+ }
88
+ })
89
+ } else {
90
+ runOnMainThread(() => {
91
+ 'main thread'
92
+
93
+ globalThis.__eomFlushHoldCount = (globalThis.__eomFlushHoldCount ?? 0) + 1
94
+ if (globalThis.__eomFlushHoldCount === 1) {
95
+ globalThis.__setEomShouldFlushElementTree?.(false)
96
+ }
97
+
98
+ try {
99
+ cb()
100
+ } finally {
101
+ globalThis.__eomFlushHoldCount = Math.max(
102
+ (globalThis.__eomFlushHoldCount ?? 1) - 1,
103
+ 0,
104
+ )
105
+ if (globalThis.__eomFlushHoldCount === 0) {
106
+ globalThis.__setEomShouldFlushElementTree?.(true)
107
+ }
108
+ }
109
+ })()
110
+ }
111
+ }
@@ -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
@@ -0,0 +1,26 @@
1
+ // Copyright 2026 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+
5
+ import type { DependencyList } from '@lynx-js/react'
6
+
7
+ /**
8
+ * Compares two dependency arrays
9
+ */
10
+ export function areDepsEqual(
11
+ prevDeps: DependencyList | undefined,
12
+ nextDeps: DependencyList | undefined,
13
+ ): boolean {
14
+ if (prevDeps === undefined || nextDeps === undefined) {
15
+ return false
16
+ }
17
+ if (prevDeps.length !== nextDeps.length) {
18
+ return false
19
+ }
20
+ for (let i = 0; i < prevDeps.length; i++) {
21
+ if (!Object.is(prevDeps[i], nextDeps[i])) {
22
+ return false
23
+ }
24
+ }
25
+ return true
26
+ }
@@ -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"}