@lynx-js/lynx-ui-common 0.0.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 (215) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +28 -0
  3. package/dist/const/BaseScrollEventsMapping.d.ts +2 -0
  4. package/dist/const/BaseScrollEventsMapping.d.ts.map +1 -0
  5. package/dist/const/BaseScrollEventsMapping.jsx +13 -0
  6. package/dist/const/BaseScrollEventsMapping.jsx.map +1 -0
  7. package/dist/const/BaseUIEventsMapping.d.ts +4 -0
  8. package/dist/const/BaseUIEventsMapping.d.ts.map +1 -0
  9. package/dist/const/BaseUIEventsMapping.jsx +24 -0
  10. package/dist/const/BaseUIEventsMapping.jsx.map +1 -0
  11. package/dist/const/index.d.ts +3 -0
  12. package/dist/const/index.d.ts.map +1 -0
  13. package/dist/const/index.jsx +2 -0
  14. package/dist/hooks/docs/useBounce.jsx +0 -0
  15. package/dist/hooks/docs/useRefresh.jsx +0 -0
  16. package/dist/hooks/index.d.ts +19 -0
  17. package/dist/hooks/index.d.ts.map +1 -0
  18. package/dist/hooks/index.jsx +73 -0
  19. package/dist/hooks/index.jsx.map +1 -0
  20. package/dist/hooks/useBounce.d.ts +26 -0
  21. package/dist/hooks/useBounce.d.ts.map +1 -0
  22. package/dist/hooks/useBounce.jsx +383 -0
  23. package/dist/hooks/useBounce.jsx.map +1 -0
  24. package/dist/hooks/useGCCollector.d.ts +18 -0
  25. package/dist/hooks/useGCCollector.d.ts.map +1 -0
  26. package/dist/hooks/useGCCollector.jsx +48 -0
  27. package/dist/hooks/useGCCollector.jsx.map +1 -0
  28. package/dist/hooks/useGlobalEventListener.d.ts +9 -0
  29. package/dist/hooks/useGlobalEventListener.d.ts.map +1 -0
  30. package/dist/hooks/useGlobalEventListener.jsx +19 -0
  31. package/dist/hooks/useGlobalEventListener.jsx.map +1 -0
  32. package/dist/hooks/useLatest.d.ts +6 -0
  33. package/dist/hooks/useLatest.d.ts.map +1 -0
  34. package/dist/hooks/useLatest.jsx +9 -0
  35. package/dist/hooks/useLatest.jsx.map +1 -0
  36. package/dist/hooks/useMemoizedFn.d.ts +8 -0
  37. package/dist/hooks/useMemoizedFn.d.ts.map +1 -0
  38. package/dist/hooks/useMemoizedFn.jsx +15 -0
  39. package/dist/hooks/useMemoizedFn.jsx.map +1 -0
  40. package/dist/hooks/usePrevious.d.ts +16 -0
  41. package/dist/hooks/usePrevious.d.ts.map +1 -0
  42. package/dist/hooks/usePrevious.jsx +11 -0
  43. package/dist/hooks/usePrevious.jsx.map +1 -0
  44. package/dist/hooks/useRefresh.d.ts +24 -0
  45. package/dist/hooks/useRefresh.d.ts.map +1 -0
  46. package/dist/hooks/useRefresh.jsx +554 -0
  47. package/dist/hooks/useRefresh.jsx.map +1 -0
  48. package/dist/hooks/useRegisteredEvents.d.ts +19 -0
  49. package/dist/hooks/useRegisteredEvents.d.ts.map +1 -0
  50. package/dist/hooks/useRegisteredEvents.jsx +24 -0
  51. package/dist/hooks/useRegisteredEvents.jsx.map +1 -0
  52. package/dist/hooks/useUnmount.d.ts +2 -0
  53. package/dist/hooks/useUnmount.d.ts.map +1 -0
  54. package/dist/hooks/useUnmount.jsx +11 -0
  55. package/dist/hooks/useUnmount.jsx.map +1 -0
  56. package/dist/index.d.ts +8 -0
  57. package/dist/index.d.ts.map +1 -0
  58. package/dist/index.jsx +6 -0
  59. package/dist/reactive/hooks/useReactiveValue.d.ts +22 -0
  60. package/dist/reactive/hooks/useReactiveValue.d.ts.map +1 -0
  61. package/dist/reactive/hooks/useReactiveValue.jsx +75 -0
  62. package/dist/reactive/hooks/useReactiveValue.jsx.map +1 -0
  63. package/dist/reactive/hooks/useReactiveValueChange.d.ts +4 -0
  64. package/dist/reactive/hooks/useReactiveValueChange.d.ts.map +1 -0
  65. package/dist/reactive/hooks/useReactiveValueChange.jsx +7 -0
  66. package/dist/reactive/hooks/useReactiveValueChange.jsx.map +1 -0
  67. package/dist/reactive/hooks/useReactiveValueEvent.d.ts +5 -0
  68. package/dist/reactive/hooks/useReactiveValueEvent.d.ts.map +1 -0
  69. package/dist/reactive/hooks/useReactiveValueEvent.jsx +15 -0
  70. package/dist/reactive/hooks/useReactiveValueEvent.jsx.map +1 -0
  71. package/dist/reactive/index.d.ts +6 -0
  72. package/dist/reactive/index.d.ts.map +1 -0
  73. package/dist/reactive/index.jsx +5 -0
  74. package/dist/reactive/types.d.ts +17 -0
  75. package/dist/reactive/types.d.ts.map +1 -0
  76. package/dist/reactive/types.jsx +0 -0
  77. package/dist/reactive/updateReactive.d.ts +4 -0
  78. package/dist/reactive/updateReactive.d.ts.map +1 -0
  79. package/dist/reactive/updateReactive.jsx +8 -0
  80. package/dist/reactive/updateReactive.jsx.map +1 -0
  81. package/dist/types/index.d.ts +2 -0
  82. package/dist/types/index.d.ts.map +1 -0
  83. package/dist/types/index.jsx +0 -0
  84. package/dist/types/interfaces/BaseScrollEvents.d.ts +40 -0
  85. package/dist/types/interfaces/BaseScrollEvents.d.ts.map +1 -0
  86. package/dist/types/interfaces/BaseScrollEvents.jsx +0 -0
  87. package/dist/types/interfaces/BaseUIEvents.d.ts +132 -0
  88. package/dist/types/interfaces/BaseUIEvents.d.ts.map +1 -0
  89. package/dist/types/interfaces/BaseUIEvents.jsx +0 -0
  90. package/dist/types/interfaces/BaseUIProps.d.ts +19 -0
  91. package/dist/types/interfaces/BaseUIProps.d.ts.map +1 -0
  92. package/dist/types/interfaces/BaseUIProps.jsx +0 -0
  93. package/dist/types/interfaces/BounceableInterface.d.ts +120 -0
  94. package/dist/types/interfaces/BounceableInterface.d.ts.map +1 -0
  95. package/dist/types/interfaces/BounceableInterface.jsx +0 -0
  96. package/dist/types/interfaces/EventMTSInterface.d.ts +1 -0
  97. package/dist/types/interfaces/EventMTSInterface.d.ts.map +1 -0
  98. package/dist/types/interfaces/EventMTSInterface.jsx +0 -0
  99. package/dist/types/interfaces/LazyInterface.d.ts +72 -0
  100. package/dist/types/interfaces/LazyInterface.d.ts.map +1 -0
  101. package/dist/types/interfaces/LazyInterface.jsx +0 -0
  102. package/dist/types/interfaces/RefreshInterface.d.ts +98 -0
  103. package/dist/types/interfaces/RefreshInterface.d.ts.map +1 -0
  104. package/dist/types/interfaces/RefreshInterface.jsx +10 -0
  105. package/dist/types/interfaces/RefreshInterface.jsx.map +1 -0
  106. package/dist/types/interfaces/index.d.ts +36 -0
  107. package/dist/types/interfaces/index.d.ts.map +1 -0
  108. package/dist/types/interfaces/index.jsx +0 -0
  109. package/dist/utils/common.d.ts +15 -0
  110. package/dist/utils/common.d.ts.map +1 -0
  111. package/dist/utils/common.jsx +12 -0
  112. package/dist/utils/common.jsx.map +1 -0
  113. package/dist/utils/common.test.jsx +55 -0
  114. package/dist/utils/common.test.jsx.map +1 -0
  115. package/dist/utils/convertToPx.d.ts +4 -0
  116. package/dist/utils/convertToPx.d.ts.map +1 -0
  117. package/dist/utils/convertToPx.jsx +20 -0
  118. package/dist/utils/convertToPx.jsx.map +1 -0
  119. package/dist/utils/delayFrames.d.ts +2 -0
  120. package/dist/utils/delayFrames.d.ts.map +1 -0
  121. package/dist/utils/delayFrames.jsx +12 -0
  122. package/dist/utils/delayFrames.jsx.map +1 -0
  123. package/dist/utils/getEventDetail.d.ts +23 -0
  124. package/dist/utils/getEventDetail.d.ts.map +1 -0
  125. package/dist/utils/getEventDetail.jsx +7 -0
  126. package/dist/utils/getEventDetail.jsx.map +1 -0
  127. package/dist/utils/index.d.ts +13 -0
  128. package/dist/utils/index.d.ts.map +1 -0
  129. package/dist/utils/index.jsx +12 -0
  130. package/dist/utils/interpolation.d.ts +40 -0
  131. package/dist/utils/interpolation.d.ts.map +1 -0
  132. package/dist/utils/interpolation.jsx +86 -0
  133. package/dist/utils/interpolation.jsx.map +1 -0
  134. package/dist/utils/interpolationJS.d.ts +39 -0
  135. package/dist/utils/interpolationJS.d.ts.map +1 -0
  136. package/dist/utils/interpolationJS.jsx +80 -0
  137. package/dist/utils/interpolationJS.jsx.map +1 -0
  138. package/dist/utils/log.d.ts +3 -0
  139. package/dist/utils/log.d.ts.map +1 -0
  140. package/dist/utils/log.jsx +10 -0
  141. package/dist/utils/log.jsx.map +1 -0
  142. package/dist/utils/mainThreadify.d.ts +2 -0
  143. package/dist/utils/mainThreadify.d.ts.map +1 -0
  144. package/dist/utils/mainThreadify.jsx +11 -0
  145. package/dist/utils/mainThreadify.jsx.map +1 -0
  146. package/dist/utils/popoverUtils.d.ts +3 -0
  147. package/dist/utils/popoverUtils.d.ts.map +1 -0
  148. package/dist/utils/popoverUtils.jsx +12 -0
  149. package/dist/utils/popoverUtils.jsx.map +1 -0
  150. package/dist/utils/renderContentWithExtraProps.d.ts +5 -0
  151. package/dist/utils/renderContentWithExtraProps.d.ts.map +1 -0
  152. package/dist/utils/renderContentWithExtraProps.jsx +10 -0
  153. package/dist/utils/renderContentWithExtraProps.jsx.map +1 -0
  154. package/dist/utils/selector.d.ts +36 -0
  155. package/dist/utils/selector.d.ts.map +1 -0
  156. package/dist/utils/selector.jsx +85 -0
  157. package/dist/utils/selector.jsx.map +1 -0
  158. package/dist/utils/selector.test.jsx +215 -0
  159. package/dist/utils/selector.test.jsx.map +1 -0
  160. package/dist/utils/version.d.ts +6 -0
  161. package/dist/utils/version.d.ts.map +1 -0
  162. package/dist/utils/version.jsx +28 -0
  163. package/dist/utils/version.jsx.map +1 -0
  164. package/dist/utils/version.test.jsx +77 -0
  165. package/dist/utils/version.test.jsx.map +1 -0
  166. package/package.json +52 -0
  167. package/src/const/BaseScrollEventsMapping.ts +14 -0
  168. package/src/const/BaseUIEventsMapping.ts +25 -0
  169. package/src/const/index.ts +6 -0
  170. package/src/hooks/docs/useBounce.mdx +2 -0
  171. package/src/hooks/docs/useRefresh.mdx +2 -0
  172. package/src/hooks/index.ts +96 -0
  173. package/src/hooks/useBounce.tsx +814 -0
  174. package/src/hooks/useGCCollector.tsx +76 -0
  175. package/src/hooks/useGlobalEventListener.ts +50 -0
  176. package/src/hooks/useLatest.ts +16 -0
  177. package/src/hooks/useMemoizedFn.ts +35 -0
  178. package/src/hooks/usePrevious.ts +28 -0
  179. package/src/hooks/useRefresh.ts +1054 -0
  180. package/src/hooks/useRegisteredEvents.ts +69 -0
  181. package/src/hooks/useUnmount.ts +18 -0
  182. package/src/index.tsx +25 -0
  183. package/src/reactive/hooks/useReactiveValue.ts +132 -0
  184. package/src/reactive/hooks/useReactiveValueChange.ts +15 -0
  185. package/src/reactive/hooks/useReactiveValueEvent.ts +26 -0
  186. package/src/reactive/index.ts +20 -0
  187. package/src/reactive/types.ts +29 -0
  188. package/src/reactive/updateReactive.ts +16 -0
  189. package/src/types/index.ts +5 -0
  190. package/src/types/interfaces/BaseScrollEvents.ts +47 -0
  191. package/src/types/interfaces/BaseUIEvents.ts +142 -0
  192. package/src/types/interfaces/BaseUIProps.ts +22 -0
  193. package/src/types/interfaces/BounceableInterface.ts +125 -0
  194. package/src/types/interfaces/EventMTSInterface.ts +35 -0
  195. package/src/types/interfaces/LazyInterface.tsx +78 -0
  196. package/src/types/interfaces/RefreshInterface.ts +105 -0
  197. package/src/types/interfaces/index.ts +44 -0
  198. package/src/utils/common.test.ts +64 -0
  199. package/src/utils/common.ts +35 -0
  200. package/src/utils/convertToPx.ts +32 -0
  201. package/src/utils/delayFrames.ts +24 -0
  202. package/src/utils/getEventDetail.ts +36 -0
  203. package/src/utils/index.ts +16 -0
  204. package/src/utils/interpolation.ts +222 -0
  205. package/src/utils/interpolationJS.ts +212 -0
  206. package/src/utils/log.ts +16 -0
  207. package/src/utils/mainThreadify.ts +17 -0
  208. package/src/utils/popoverUtils.ts +25 -0
  209. package/src/utils/renderContentWithExtraProps.ts +20 -0
  210. package/src/utils/selector.test.ts +237 -0
  211. package/src/utils/selector.ts +222 -0
  212. package/src/utils/version.test.ts +98 -0
  213. package/src/utils/version.ts +50 -0
  214. package/tsconfig.docs.json +7 -0
  215. package/tsconfig.json +12 -0
@@ -0,0 +1,125 @@
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 { ReactElement } from '@lynx-js/react'
6
+
7
+ export interface scrollToBouncesInfo {
8
+ direction: 'upper' | 'lower'
9
+ }
10
+
11
+ export interface BounceableBasicProps {
12
+ /**
13
+ * Whether to enable bounce effect
14
+ * @zh 是否开启回弹效果
15
+ * @iOS
16
+ * @Android
17
+ * @Harmony
18
+ */
19
+ enableBounces: boolean
20
+ /**
21
+ * Trigger bounces effect during fling
22
+ * @zh 在快速滑动(fling)时触发回弹效果
23
+ * @defaultValue false
24
+ * @iOS
25
+ * @Android
26
+ * @Harmony
27
+ */
28
+ enableBounceEventInFling?: boolean
29
+ /**
30
+ * The threshold distance of upper bounces, in pixels, when triggering the scrollToBounces event
31
+ * @zh 触发 `scrollToBounces` 事件时,上部回弹的阈值距离(单位:px)
32
+ * @defaultValue 0
33
+ * @iOS
34
+ * @Android
35
+ * @Harmony
36
+ */
37
+ startBounceTriggerDistance?: number
38
+ /**
39
+ * The threshold distance of lower bounces, in pixels, when triggering the scrollToBounces event
40
+ * @zh 触发 `scrollToBounces` 事件时,下部回弹的阈值距离(单位:px)
41
+ * @defaultValue 0
42
+ * @iOS
43
+ * @Android
44
+ * @Harmony
45
+ */
46
+ endBounceTriggerDistance?: number
47
+ /**
48
+ * Content of upper bounces view, which will be displayed during the upper bouncing effect.
49
+ * @zh 上部回弹视图的内容,将在上部回弹效果期间显示。
50
+ * @iOS
51
+ * @Android
52
+ * @Harmony
53
+ */
54
+ upperBounceItem?: ReactElement
55
+ /**
56
+ * Content of lower bounces view, which will be displayed during the lower bouncing effect.
57
+ * @zh 下部回弹视图的内容,将在下部回弹效果期间显示。
58
+ * @iOS
59
+ * @Android
60
+ * @Harmony
61
+ */
62
+ lowerBounceItem?: ReactElement
63
+ /**
64
+ * Whether the scrollable container can bounce when the content area of the scrollable container is smaller than the viewport area.
65
+ * @zh 当可滚动容器的内容区域小于视口区域时,是否允许容器回弹。
66
+ * @defaultValue true
67
+ * @iOS
68
+ * @Android
69
+ * @Harmony
70
+ */
71
+ alwaysBouncing?: boolean
72
+ /**
73
+ * The direction of the bounce effect. 'both' for bouncing on both ends, 'none' to disable bounce, and 'upper'/'lower' for bouncing on either end
74
+ * @zh 回弹效果的方向。'both' 表示两端都回弹,'none' 表示禁用回弹,'upper'/'lower' 表示只在上端或下端回弹。
75
+ * @defaultValue 'both'
76
+ * @iOS
77
+ * @Android
78
+ * @Harmony
79
+ */
80
+ singleSidedBounce?: 'upper' | 'lower' | 'both' | 'iOSBounces' | 'none'
81
+ /**
82
+ * Unit: px. Optional size hint for bounce effect. Recommended when used in List or <list/>.
83
+ * @zh 单位:px。可选的回弹效果尺寸提示。在列表或 `<list/>` 中使用时推荐设置。
84
+ * @Android
85
+ * @iOS
86
+ * @Harmony
87
+ */
88
+ estimatedHeight?: number
89
+ /**
90
+ * Unit: px. Optional size hint for bounce effect. Recommended when used in List or <list/>.
91
+ * @zh 单位:px。可选的回弹效果尺寸提示。在列表或 `<list/>` 中使用时推荐设置。
92
+ * @Android
93
+ * @iOS
94
+ * @Harmony
95
+ */
96
+ estimatedWidth?: number
97
+ /**
98
+ * Display debug logs. Open it when you find a bug.
99
+ * @zh 显示调试日志。当您发现错误时,请打开此选项。
100
+ * @defaultValue false
101
+ * @iOS
102
+ * @Android
103
+ * @Harmony
104
+ */
105
+ debugLog?: boolean
106
+ /**
107
+ * requestAnimationFrame don't work under lynx version 2.15.2. This switch should be opened when the version is higher than 2.15.2.
108
+ * @zh `requestAnimationFrame` 在 lynx 2.15.2 以下版本中不起作用。当版本高于 2.15.2 时,应打开此开关。
109
+ * @defaultValue false
110
+ * @iOS
111
+ * @Android
112
+ * @Harmony
113
+ */
114
+ validAnimationVersion?: boolean
115
+ /**
116
+ * When bounces effect is triggered and the bounce distance is larger than startBounceDistance or endBounceDistance on the upper or lower side, the scrollToBounces event will be triggered.
117
+ * @zh 当触发回弹效果并且回弹距离在上侧或下侧大于 `startBounceDistance` 或 `endBounceDistance` 时,将触发 `scrollToBounces` 事件。
118
+ * @defaultValue 0
119
+ * @eventProperty
120
+ * @iOS
121
+ * @Android
122
+ * @Harmony
123
+ */
124
+ onScrollToBounces?: (e: scrollToBouncesInfo) => void
125
+ }
@@ -0,0 +1,35 @@
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
+ // TODO(@wangyang.ryan) This MainThreadify currently can not work as ITouchEvent is not equal to MainThread:ITouchEvent
6
+ // import { MainThreadify } from '../types/MainThreadify';
7
+ // interface BaseEventInterface {
8
+ // onLayoutChange?: (e: ReactLynx.CommonEvent) => void;
9
+ // /**
10
+ // * @description MTS version of onTouchMove.
11
+ // * @iOS
12
+ // * @Android
13
+ // */
14
+ // onTouchMove?: (e: ReactLynx.TouchEvent) => void;
15
+ // /**
16
+ // * @description MTS version of onTouchStart.
17
+ // * @iOS
18
+ // * @Android
19
+ // */
20
+ // onTouchStart?: (e: ReactLynx.TouchEvent) => void;
21
+ // /**
22
+ // * @description MTS version of onTouchEnd.
23
+ // * @iOS
24
+ // * @Android
25
+ // */
26
+ // onTouchEnd?: (e: ReactLynx.TouchEvent) => void;
27
+ // }
28
+
29
+ // export type EventMTSInterface = MainThreadify<
30
+ // BaseEventInterface,
31
+ // | 'onLayoutChange'
32
+ // | 'onTouchMove'
33
+ // | 'onTouchStart'
34
+ // | 'onTouchEnd'
35
+ // >;
@@ -0,0 +1,78 @@
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 { CSSProperties } from '@lynx-js/types'
6
+
7
+ export interface EnableLazyMode {
8
+ /**
9
+ * When enabled, only the items that are about to enter the viewport are rendered, reducing initial load time and memory usage; remaining items are rendered as they approach visibility during scroll.
10
+ * @zh 启用懒渲染。只有当用户滚动到可见区域时,才会渲染 items,从而减少初始加载时间和内存使用。
11
+ * @defaultValue true
12
+ * @Android
13
+ * @iOS
14
+ */
15
+ enableLazy: boolean
16
+ /**
17
+ * Be used to mark the exposure timing of lazy loading. Please ensure that it is unique throughout the page.
18
+ * @zh 用于标记懒加载的曝光时机。请确保在整个页面中是唯一的。
19
+ * @defaultValue undefined
20
+ * @Android
21
+ * @iOS
22
+ */
23
+ scene: string
24
+ /**
25
+ * Estimated height and width of the items need to be set.
26
+ * @zh 需要设置项目的预估高度和宽度。
27
+ * @defaultValue undefined
28
+ * @Android
29
+ * @iOS
30
+ */
31
+ estimatedItemStyle: CSSProperties
32
+ /**
33
+ * exposure-screen-margin-top
34
+ * @zh 曝光屏幕上边距
35
+ * @defaultValue '10px'
36
+ * @Android
37
+ * @iOS
38
+ */
39
+ exposureTop?: `${number}px` | `${number}rpx`
40
+ /**
41
+ * exposure-screen-margin-bottom
42
+ * @zh 曝光屏幕下边距
43
+ * @defaultValue '10px'
44
+ * @Android
45
+ * @iOS
46
+ */
47
+ exposureBottom?: `${number}px` | `${number}rpx`
48
+ /**
49
+ * exposure-screen-margin-left
50
+ * @zh 曝光屏幕左边距
51
+ * @defaultValue '10px'
52
+ * @Android
53
+ * @iOS
54
+ */
55
+ exposureLeft?: `${number}px` | `${number}rpx`
56
+ /**
57
+ * exposure-screen-margin-right
58
+ * @zh 曝光屏幕右边距
59
+ * @defaultValue '10px'
60
+ * @Android
61
+ * @iOS
62
+ */
63
+ exposureRight?: `${number}px` | `${number}rpx`
64
+ /**
65
+ * Estimated first screen item count for lazy rendering. Remaining children will complete rendering based on exposure. When this estimate is small, it may cause a blank screen phenomenon where some nodes exist on the first screen.
66
+ * @zh 懒加载的首屏预估 item 数量。剩余子节点将根据曝光情况完成渲染。当此预估值较小时,可能会导致首屏存在部分节点白屏的现象。
67
+ * @defaultValue 1
68
+ * @Android
69
+ * @iOS
70
+ */
71
+ firstScreenItemCount?: number
72
+ }
73
+
74
+ export interface DisableLazyMode {
75
+ enableLazy: false
76
+ }
77
+
78
+ export type LazyOptions = EnableLazyMode | DisableLazyMode
@@ -0,0 +1,105 @@
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 { ReactElement } from '@lynx-js/react'
6
+
7
+ export interface RefreshEvent {
8
+ triggeredBy: 'startRefresh' | 'drag'
9
+ }
10
+ export interface refreshOffsetEvent {
11
+ offset: number
12
+ headerSize: number
13
+ isDragging: boolean
14
+ }
15
+ export interface headerReleased {
16
+ offset: number
17
+ headerSize: number
18
+ }
19
+
20
+ export enum RefreshState {
21
+ IDLE = 0, // Hide
22
+ OVER_DRAG_RELEASE = 1, // Drag over refresh header size and release
23
+ REFRESHING = 2, // During refresh
24
+ DRAGGING = 3, // Dragging
25
+ }
26
+
27
+ export interface RefreshStateChange {
28
+ /**
29
+ * Status of refreshHeader
30
+ * @zh 刷新头的状态
31
+ * @Android
32
+ * @iOS
33
+ * @Harmony
34
+ */
35
+ state: RefreshState
36
+ }
37
+
38
+ export interface RefreshProps {
39
+ /**
40
+ * Enable refresh
41
+ * @zh 启用刷新
42
+ * @Android
43
+ * @iOS
44
+ * @Harmony
45
+ */
46
+ enableRefresh: boolean
47
+ /**
48
+ * header children
49
+ * @zh 头部内容
50
+ * @Android
51
+ * @iOS
52
+ * @Harmony
53
+ */
54
+ headerContent: ReactElement
55
+ /**
56
+ * Display debug logs. Open it when you find a bug.
57
+ * @zh 显示调试日志。当您发现错误时请打开它。
58
+ * @defaultValue false
59
+ * @Android
60
+ * @iOS
61
+ * @Harmony
62
+ */
63
+ debugLog?: boolean
64
+ /**
65
+ * requestAnimationFrame don't work under lynx version 2.15.2. This switch should be opened when the version is higher than 2.15.2.
66
+ * @zh requestAnimationFrame 在 lynx 2.15.2 以下版本中不起作用。当版本高于 2.15.2 时,应打开此开关。
67
+ * @defaultValue false
68
+ * @Android
69
+ * @iOS
70
+ * @Harmony
71
+ */
72
+ validAnimationVersion?: boolean
73
+ /**
74
+ * Send when refresh started.
75
+ * @zh 刷新开始时发送。
76
+ * @Android
77
+ * @iOS
78
+ * @Harmony
79
+ */
80
+ onStartRefresh?: (e: RefreshEvent) => void
81
+ /**
82
+ * Send when header shows and moves.
83
+ * @zh 当头部显示和移动时发送。
84
+ * @Android
85
+ * @iOS
86
+ * @Harmony
87
+ */
88
+ onRefreshOffsetChange?: (e: refreshOffsetEvent) => void
89
+ /**
90
+ * Send during refresh dragging and header is visible.
91
+ * @zh 在刷新拖动期间并且头部可见时发送。
92
+ * @Android
93
+ * @iOS
94
+ * @Harmony
95
+ */
96
+ onRefreshStateChange?: (e: RefreshStateChange) => void
97
+ /**
98
+ * Send when drag is end.
99
+ * @zh 拖动结束时发送。
100
+ * @Android
101
+ * @iOS
102
+ * @Harmony
103
+ */
104
+ onHeaderReleased?: (e: headerReleased) => void
105
+ }
@@ -0,0 +1,44 @@
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 { CSSProperties } from '@lynx-js/types'
6
+
7
+ export type * from './BaseScrollEvents'
8
+ export type * from './BaseUIEvents'
9
+ export type * from './BaseUIProps'
10
+ export type * from './BounceableInterface'
11
+ export type * from './LazyInterface'
12
+ export type * from './RefreshInterface'
13
+
14
+ export interface Point {
15
+ x: number
16
+ y: number
17
+ }
18
+
19
+ export interface Rect {
20
+ width: number
21
+ height: number
22
+ left: number
23
+ top: number
24
+ }
25
+
26
+ // TODO(fangzhou.fz): add id if it becomes necessary in the future
27
+ export interface ComponentBasicProps {
28
+ /**
29
+ * className
30
+ * @zh 类名
31
+ * @Android
32
+ * @iOS
33
+ * @Harmony
34
+ */
35
+ className?: string
36
+ /**
37
+ * style
38
+ * @zh 样式
39
+ * @Android
40
+ * @iOS
41
+ * @Harmony
42
+ */
43
+ style?: CSSProperties
44
+ }
@@ -0,0 +1,64 @@
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 { describe, it, expect } from 'vitest'
6
+ import { get, noop } from './common'
7
+
8
+ describe('common utils', () => {
9
+ describe('get', () => {
10
+ const testObj = {
11
+ a: {
12
+ b: {
13
+ c: 'value',
14
+ },
15
+ arr: [{ nested: 'array-value' }],
16
+ },
17
+ nullValue: null,
18
+ undefinedValue: undefined,
19
+ }
20
+
21
+ it('should return value for dot notation path', () => {
22
+ expect(get(testObj, 'a.b.c')).toBe('value')
23
+ })
24
+
25
+ it('should return value for bracket notation path', () => {
26
+ expect(get(testObj, 'a[b][c]')).toBe('value')
27
+ })
28
+
29
+ it('should return value for array index path', () => {
30
+ expect(get(testObj, 'a.arr[0].nested')).toBe('array-value')
31
+ expect(get(testObj, 'a.arr.0.nested')).toBe('array-value')
32
+ })
33
+
34
+ it('should return default value when path does not exist', () => {
35
+ expect(get(testObj, 'a.b.d', 'default')).toBe('default')
36
+ expect(get(testObj, 'x.y.z', 'default')).toBe('default')
37
+ })
38
+
39
+ it('should return undefined when no default value is provided and path does not exist', () => {
40
+ expect(get(testObj, 'a.b.d')).toBeUndefined()
41
+ })
42
+
43
+ it('should handle null and undefined values', () => {
44
+ expect(get(testObj, 'nullValue.something', 'default')).toBe('default')
45
+ expect(get(testObj, 'undefinedValue.something', 'default')).toBe(
46
+ 'default',
47
+ )
48
+ })
49
+
50
+ it('should return default value when input is not an object', () => {
51
+ expect(get(null, 'any.path', 'default')).toBe('default')
52
+ expect(get(undefined, 'any.path', 'default')).toBe('default')
53
+ expect(get('string', 'any.path', 'default')).toBe('default')
54
+ expect(get(123, 'any.path', 'default')).toBe('default')
55
+ })
56
+ })
57
+
58
+ describe('noop', () => {
59
+ it('should be a function that returns undefined', () => {
60
+ expect(typeof noop).toBe('function')
61
+ expect(noop()).toBeUndefined()
62
+ })
63
+ })
64
+ })
@@ -0,0 +1,35 @@
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
+ function _basePath(path: unknown[] | string) {
6
+ if (Array.isArray(path)) {
7
+ return path
8
+ }
9
+ return path.replace(/\[/g, '.').replace(/\]/g, '').split('.')
10
+ }
11
+
12
+ /**
13
+ * Lodash like get, accessing object by path. Otherwise return defaultValue
14
+ * Where path can be 'a[0].b.c', 'a.0.b.c' or ['a','0','b','c']
15
+ * @param obj Object to get property from
16
+ * @param path Path of property
17
+ * @param defaultValue Optional. Default value
18
+ * @returns
19
+ */
20
+ export function get(obj: unknown, path: string, defaultValue?: unknown) {
21
+ if (typeof obj !== 'object') {
22
+ return defaultValue
23
+ }
24
+ // @ts-expect-error: o is unknown
25
+ return _basePath(path).reduce((o: unknown, k: string) => o?.[k], obj)
26
+ ?? defaultValue
27
+ }
28
+
29
+ /**
30
+ * Empty function that does nothing.
31
+ * Useful as a default callback or placeholder function.
32
+ */
33
+ export const noop = (): void => {
34
+ // Intentionally empty
35
+ }
@@ -0,0 +1,32 @@
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
+ export const screenWidth = SystemInfo.pixelWidth / SystemInfo.pixelRatio
6
+ export const screenHeight = SystemInfo.pixelHeight / SystemInfo.pixelRatio
7
+
8
+ export function convertToPx(
9
+ value:
10
+ | `${number}px`
11
+ | `${number}rpx`
12
+ | `${number}vw`
13
+ | `${number}vh`
14
+ | undefined,
15
+ ): number | undefined {
16
+ if (!value) {
17
+ return undefined
18
+ }
19
+ const num = Number.parseFloat(value)
20
+
21
+ const unit = value.slice(String(num).length).trim()
22
+ switch (unit) {
23
+ case 'px':
24
+ return num
25
+ case 'rpx':
26
+ return num * (screenWidth / 750)
27
+ case 'vw':
28
+ return num * (screenWidth / 100)
29
+ case 'vh':
30
+ return num * (screenHeight / 100)
31
+ }
32
+ }
@@ -0,0 +1,24 @@
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
+ export function delayFrames(frames: number, callback: () => void): void {
6
+ let count = 0
7
+
8
+ const frameHandler = () => {
9
+ count++
10
+ if (count >= frames) {
11
+ callback()
12
+ } else {
13
+ // (TODO) Currently the requestAnimation has bug on reactLynx 0.109.3. After it fixed, replace lynx.requestAnimationFrame with it.
14
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
15
+ // @ts-ignore
16
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
17
+ lynx.requestAnimationFrame(frameHandler)
18
+ }
19
+ }
20
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
21
+ // @ts-ignore
22
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
23
+ lynx.requestAnimationFrame(frameHandler)
24
+ }
@@ -0,0 +1,36 @@
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
+ /**
6
+ * A type representing event details that may contain layout and positioning information.
7
+ * It includes optional properties for dimensions and coordinates, and allows for other properties.
8
+ */
9
+ export type EventDetailWithLayout = {
10
+ left?: number
11
+ top?: number
12
+ right?: number
13
+ bottom?: number
14
+ width?: number
15
+ height?: number
16
+ } & Record<string, unknown>
17
+
18
+ /**
19
+ * Safely retrieves detailed information from an event object.
20
+ * It attempts to access `event.detail` first. If `detail` is not available,
21
+ * it falls back to `event.params`. This is useful for maintaining
22
+ * compatibility across different event structures on different platforms and versions.
23
+ *
24
+ * @param event The event object, which can be of any type.
25
+ * @returns The `detail` or `params` object from the event, or an empty object if neither is found.
26
+ */
27
+ export function getEventDetail<
28
+ T extends EventDetailWithLayout = EventDetailWithLayout,
29
+ > // biome-ignore lint/suspicious/noExplicitAny: accept any type of events
30
+ (event: any): T {
31
+ if (!event) {
32
+ return {} as T
33
+ }
34
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
35
+ return (event.detail ?? event.params ?? {}) as T
36
+ }
@@ -0,0 +1,16 @@
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
+ export * from './common'
6
+ export * from './version'
7
+ export * from './selector'
8
+ export * from './log'
9
+ export * from './mainThreadify'
10
+ export { convertOverlayMode, registerOverlayMode } from './popoverUtils'
11
+ export { convertToPx, screenWidth, screenHeight } from './convertToPx'
12
+ export { interpolate, interpolateJS } from './interpolation'
13
+ export { renderContentWithExtraProps } from './renderContentWithExtraProps'
14
+ export { delayFrames } from './delayFrames'
15
+ export { getEventDetail } from './getEventDetail'
16
+ export type { EventDetailWithLayout } from './getEventDetail'