@mpxjs/webpack-plugin 2.10.17 → 2.10.18-beta.2

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 (262) hide show
  1. package/lib/config.js +60 -0
  2. package/lib/file-loader.js +4 -1
  3. package/lib/global.d.ts +231 -0
  4. package/lib/index.js +70 -73
  5. package/lib/init.js +3 -0
  6. package/lib/json-compiler/index.js +13 -4
  7. package/lib/loader.js +4 -0
  8. package/lib/platform/json/wx/index.js +6 -0
  9. package/lib/platform/style/wx/index.js +102 -72
  10. package/lib/platform/template/wx/component-config/ad.js +5 -0
  11. package/lib/platform/template/wx/component-config/button.js +10 -3
  12. package/lib/platform/template/wx/component-config/camera.js +25 -3
  13. package/lib/platform/template/wx/component-config/canvas.js +8 -1
  14. package/lib/platform/template/wx/component-config/cover-image.js +7 -2
  15. package/lib/platform/template/wx/component-config/cover-view.js +3 -1
  16. package/lib/platform/template/wx/component-config/form.js +27 -2
  17. package/lib/platform/template/wx/component-config/image.js +5 -0
  18. package/lib/platform/template/wx/component-config/input.js +10 -0
  19. package/lib/platform/template/wx/component-config/label.js +10 -2
  20. package/lib/platform/template/wx/component-config/map.js +11 -0
  21. package/lib/platform/template/wx/component-config/movable-area.js +4 -1
  22. package/lib/platform/template/wx/component-config/movable-view.js +17 -2
  23. package/lib/platform/template/wx/component-config/navigator.js +26 -0
  24. package/lib/platform/template/wx/component-config/picker-view.js +12 -0
  25. package/lib/platform/template/wx/component-config/picker.js +3 -1
  26. package/lib/platform/template/wx/component-config/progress.js +11 -1
  27. package/lib/platform/template/wx/component-config/rich-text.js +5 -0
  28. package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
  29. package/lib/platform/template/wx/component-config/slider.js +8 -0
  30. package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
  31. package/lib/platform/template/wx/component-config/swiper.js +10 -0
  32. package/lib/platform/template/wx/component-config/text.js +5 -0
  33. package/lib/platform/template/wx/component-config/textarea.js +19 -2
  34. package/lib/platform/template/wx/component-config/unsupported.js +10 -1
  35. package/lib/platform/template/wx/component-config/video.js +10 -0
  36. package/lib/platform/template/wx/index.js +21 -1
  37. package/lib/react/LoadAsyncChunkModule.js +1 -1
  38. package/lib/react/processStyles.js +21 -9
  39. package/lib/react/script-helper.js +2 -2
  40. package/lib/react/style-helper.js +76 -13
  41. package/lib/resolver/AddModePlugin.js +17 -7
  42. package/lib/resolver/ExtendComponentsPlugin.js +60 -0
  43. package/lib/runtime/components/ali/mpx-section-list.mpx +566 -0
  44. package/lib/runtime/components/ali/mpx-sticky-header.mpx +212 -0
  45. package/lib/runtime/components/ali/mpx-sticky-section.mpx +17 -0
  46. package/lib/runtime/components/react/animationHooks/index.ts +75 -0
  47. package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +197 -0
  48. package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +301 -0
  49. package/lib/runtime/components/react/animationHooks/utils.ts +197 -0
  50. package/lib/runtime/components/react/context.ts +12 -3
  51. package/lib/runtime/components/react/dist/animationHooks/index.d.ts +15 -0
  52. package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
  53. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +3 -0
  54. package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +181 -0
  55. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +3 -0
  56. package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +279 -0
  57. package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +109 -0
  58. package/lib/runtime/components/react/dist/animationHooks/utils.js +151 -0
  59. package/lib/runtime/components/react/dist/context.d.ts +10 -3
  60. package/lib/runtime/components/react/dist/context.js +1 -2
  61. package/lib/runtime/components/react/dist/event.config.d.ts +0 -1
  62. package/lib/runtime/components/react/dist/getInnerListeners.d.ts +0 -1
  63. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +0 -1
  64. package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +3 -1
  65. package/lib/runtime/components/react/dist/mpx-button.d.ts +0 -1
  66. package/lib/runtime/components/react/dist/mpx-camera.d.ts +31 -0
  67. package/lib/runtime/components/react/dist/mpx-camera.jsx +236 -0
  68. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +0 -1
  69. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +0 -1
  70. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +0 -1
  71. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +0 -1
  72. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +0 -1
  73. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +0 -1
  74. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +0 -1
  75. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +0 -1
  76. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +0 -1
  77. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +0 -1
  78. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +0 -1
  79. package/lib/runtime/components/react/dist/mpx-form.d.ts +0 -1
  80. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +0 -1
  81. package/lib/runtime/components/react/dist/mpx-image.d.ts +0 -1
  82. package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
  83. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +0 -1
  84. package/lib/runtime/components/react/dist/mpx-input.d.ts +2 -1
  85. package/lib/runtime/components/react/dist/mpx-input.jsx +66 -50
  86. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +0 -1
  87. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +35 -6
  88. package/lib/runtime/components/react/dist/mpx-label.d.ts +0 -1
  89. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +0 -1
  90. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +0 -1
  91. package/lib/runtime/components/react/dist/mpx-nav.d.ts +0 -1
  92. package/lib/runtime/components/react/dist/mpx-navigator.d.ts +0 -1
  93. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +0 -1
  94. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +0 -1
  95. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +0 -1
  96. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +0 -1
  97. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +0 -1
  98. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +0 -1
  99. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +0 -1
  100. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +0 -1
  101. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +0 -1
  102. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +0 -1
  103. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +0 -1
  104. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +0 -1
  105. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +0 -1
  106. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +0 -1
  107. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +0 -1
  108. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +0 -1
  109. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +0 -1
  110. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +0 -1
  111. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +0 -1
  112. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +0 -1
  113. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +0 -1
  114. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +0 -1
  115. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
  116. package/lib/runtime/components/react/dist/mpx-progress.d.ts +0 -1
  117. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +0 -1
  118. package/lib/runtime/components/react/dist/mpx-radio.d.ts +0 -1
  119. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +0 -1
  120. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +0 -1
  121. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +0 -1
  122. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +0 -1
  123. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +84 -78
  124. package/lib/runtime/components/react/dist/mpx-section-list.d.ts +48 -0
  125. package/lib/runtime/components/react/dist/mpx-section-list.jsx +292 -0
  126. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +0 -1
  127. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +0 -1
  128. package/lib/runtime/components/react/dist/mpx-slider.d.ts +0 -1
  129. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +0 -1
  130. package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +20 -20
  131. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +0 -1
  132. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +0 -1
  133. package/lib/runtime/components/react/dist/mpx-swiper.d.ts +11 -1
  134. package/lib/runtime/components/react/dist/mpx-swiper.jsx +136 -83
  135. package/lib/runtime/components/react/dist/mpx-switch.d.ts +0 -1
  136. package/lib/runtime/components/react/dist/mpx-text.d.ts +0 -1
  137. package/lib/runtime/components/react/dist/mpx-textarea.d.ts +0 -1
  138. package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -0
  139. package/lib/runtime/components/react/dist/mpx-video.d.ts +0 -1
  140. package/lib/runtime/components/react/dist/mpx-view.d.ts +3 -3
  141. package/lib/runtime/components/react/dist/mpx-view.jsx +22 -8
  142. package/lib/runtime/components/react/dist/mpx-web-view.d.ts +0 -1
  143. package/lib/runtime/components/react/dist/mpx-web-view.jsx +1 -1
  144. package/lib/runtime/components/react/dist/parser.d.ts +0 -1
  145. package/lib/runtime/components/react/dist/useNodesRef.d.ts +0 -1
  146. package/lib/runtime/components/react/dist/utils.d.ts +10 -9
  147. package/lib/runtime/components/react/dist/utils.jsx +47 -24
  148. package/lib/runtime/components/react/mpx-async-suspense.tsx +3 -1
  149. package/lib/runtime/components/react/mpx-camera.tsx +327 -0
  150. package/lib/runtime/components/react/mpx-image.tsx +2 -2
  151. package/lib/runtime/components/react/mpx-input.tsx +77 -54
  152. package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +35 -6
  153. package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
  154. package/lib/runtime/components/react/mpx-scroll-view.tsx +110 -114
  155. package/lib/runtime/components/react/mpx-section-list.tsx +439 -0
  156. package/lib/runtime/components/react/mpx-sticky-header.tsx +24 -24
  157. package/lib/runtime/components/react/mpx-swiper.tsx +156 -81
  158. package/lib/runtime/components/react/mpx-textarea.tsx +1 -0
  159. package/lib/runtime/components/react/mpx-view.tsx +27 -12
  160. package/lib/runtime/components/react/mpx-web-view.tsx +1 -1
  161. package/lib/runtime/components/react/tsconfig.json +26 -0
  162. package/lib/runtime/components/react/types/global.d.ts +1 -0
  163. package/lib/runtime/components/react/utils.tsx +51 -27
  164. package/lib/runtime/components/web/mpx-scroll-view.vue +5 -2
  165. package/lib/runtime/components/web/mpx-section-list.vue +551 -0
  166. package/lib/runtime/components/wx/mpx-section-list-default/list-footer.mpx +26 -0
  167. package/lib/runtime/components/wx/mpx-section-list-default/list-header.mpx +26 -0
  168. package/lib/runtime/components/wx/mpx-section-list-default/list-item.mpx +26 -0
  169. package/lib/runtime/components/wx/mpx-section-list-default/section-header.mpx +26 -0
  170. package/lib/runtime/components/wx/mpx-section-list.mpx +209 -0
  171. package/lib/runtime/components/wx/mpx-sticky-header.mpx +40 -0
  172. package/lib/runtime/components/wx/mpx-sticky-section.mpx +31 -0
  173. package/lib/runtime/optionProcessor.js +5 -0
  174. package/lib/runtime/optionProcessorReact.js +7 -0
  175. package/lib/runtime/stringify.wxs +2 -2
  176. package/lib/script-setup-compiler/index.js +1 -2
  177. package/lib/style-compiler/strip-conditional.js +244 -0
  178. package/lib/template-compiler/compiler.js +9 -8
  179. package/lib/utils/const.js +29 -0
  180. package/lib/utils/dom-tag-config.js +1 -1
  181. package/lib/utils/string.js +25 -1
  182. package/lib/wxss/loader.js +4 -1
  183. package/lib/wxss/utils.js +7 -2
  184. package/package.json +7 -14
  185. package/LICENSE +0 -433
  186. package/lib/runtime/components/react/dist/context.d.ts.map +0 -1
  187. package/lib/runtime/components/react/dist/event.config.d.ts.map +0 -1
  188. package/lib/runtime/components/react/dist/getInnerListeners.d.ts.map +0 -1
  189. package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts.map +0 -1
  190. package/lib/runtime/components/react/dist/mpx-button.d.ts.map +0 -1
  191. package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts.map +0 -1
  192. package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts.map +0 -1
  193. package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts.map +0 -1
  194. package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts.map +0 -1
  195. package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts.map +0 -1
  196. package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts.map +0 -1
  197. package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts.map +0 -1
  198. package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts.map +0 -1
  199. package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts.map +0 -1
  200. package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts.map +0 -1
  201. package/lib/runtime/components/react/dist/mpx-checkbox.d.ts.map +0 -1
  202. package/lib/runtime/components/react/dist/mpx-form.d.ts.map +0 -1
  203. package/lib/runtime/components/react/dist/mpx-icon/index.d.ts.map +0 -1
  204. package/lib/runtime/components/react/dist/mpx-image.d.ts.map +0 -1
  205. package/lib/runtime/components/react/dist/mpx-inline-text.d.ts.map +0 -1
  206. package/lib/runtime/components/react/dist/mpx-input.d.ts.map +0 -1
  207. package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts.map +0 -1
  208. package/lib/runtime/components/react/dist/mpx-label.d.ts.map +0 -1
  209. package/lib/runtime/components/react/dist/mpx-movable-area.d.ts.map +0 -1
  210. package/lib/runtime/components/react/dist/mpx-movable-view.d.ts.map +0 -1
  211. package/lib/runtime/components/react/dist/mpx-nav.d.ts.map +0 -1
  212. package/lib/runtime/components/react/dist/mpx-navigator.d.ts.map +0 -1
  213. package/lib/runtime/components/react/dist/mpx-picker/date.d.ts.map +0 -1
  214. package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts.map +0 -1
  215. package/lib/runtime/components/react/dist/mpx-picker/index.d.ts.map +0 -1
  216. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts.map +0 -1
  217. package/lib/runtime/components/react/dist/mpx-picker/region.d.ts.map +0 -1
  218. package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts.map +0 -1
  219. package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts.map +0 -1
  220. package/lib/runtime/components/react/dist/mpx-picker/time.d.ts.map +0 -1
  221. package/lib/runtime/components/react/dist/mpx-picker/type.d.ts.map +0 -1
  222. package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts.map +0 -1
  223. package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts.map +0 -1
  224. package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts.map +0 -1
  225. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts.map +0 -1
  226. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts.map +0 -1
  227. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts.map +0 -1
  228. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts.map +0 -1
  229. package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts.map +0 -1
  230. package/lib/runtime/components/react/dist/mpx-popup/index.d.ts.map +0 -1
  231. package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts.map +0 -1
  232. package/lib/runtime/components/react/dist/mpx-portal/index.d.ts.map +0 -1
  233. package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts.map +0 -1
  234. package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts.map +0 -1
  235. package/lib/runtime/components/react/dist/mpx-progress.d.ts.map +0 -1
  236. package/lib/runtime/components/react/dist/mpx-radio-group.d.ts.map +0 -1
  237. package/lib/runtime/components/react/dist/mpx-radio.d.ts.map +0 -1
  238. package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts.map +0 -1
  239. package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts.map +0 -1
  240. package/lib/runtime/components/react/dist/mpx-root-portal.d.ts.map +0 -1
  241. package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts.map +0 -1
  242. package/lib/runtime/components/react/dist/mpx-simple-text.d.ts.map +0 -1
  243. package/lib/runtime/components/react/dist/mpx-simple-view.d.ts.map +0 -1
  244. package/lib/runtime/components/react/dist/mpx-slider.d.ts.map +0 -1
  245. package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts.map +0 -1
  246. package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts.map +0 -1
  247. package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts.map +0 -1
  248. package/lib/runtime/components/react/dist/mpx-swiper.d.ts.map +0 -1
  249. package/lib/runtime/components/react/dist/mpx-switch.d.ts.map +0 -1
  250. package/lib/runtime/components/react/dist/mpx-text.d.ts.map +0 -1
  251. package/lib/runtime/components/react/dist/mpx-textarea.d.ts.map +0 -1
  252. package/lib/runtime/components/react/dist/mpx-video.d.ts.map +0 -1
  253. package/lib/runtime/components/react/dist/mpx-view.d.ts.map +0 -1
  254. package/lib/runtime/components/react/dist/mpx-web-view.d.ts.map +0 -1
  255. package/lib/runtime/components/react/dist/parser.d.ts.map +0 -1
  256. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts +0 -33
  257. package/lib/runtime/components/react/dist/useAnimationHooks.d.ts.map +0 -1
  258. package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
  259. package/lib/runtime/components/react/dist/useNodesRef.d.ts.map +0 -1
  260. package/lib/runtime/components/react/dist/utils.d.ts.map +0 -1
  261. package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
  262. package/lib/style-compiler/strip-conditional-loader.js +0 -289
@@ -0,0 +1,439 @@
1
+ import React, { forwardRef, useRef, useState, useEffect, useMemo, createElement, useImperativeHandle, useCallback, memo } from 'react'
2
+ import { SectionList, RefreshControl, NativeSyntheticEvent, NativeScrollEvent } from 'react-native'
3
+ import useInnerProps, { getCustomEvent } from './getInnerListeners'
4
+ import { extendObject, useLayout, useTransformStyle } from './utils'
5
+ interface ListItem {
6
+ isSectionHeader?: boolean;
7
+ _originalItemIndex?: number;
8
+ [key: string]: any;
9
+ }
10
+
11
+ interface Section {
12
+ headerData: ListItem | null;
13
+ data: ListItem[];
14
+ hasSectionHeader?: boolean;
15
+ _originalItemIndex?: number;
16
+ }
17
+
18
+ interface ItemHeightType {
19
+ value?: number;
20
+ getter?: (item: any, index: number) => number;
21
+ }
22
+
23
+ interface SectionListProps {
24
+ enhanced?: boolean;
25
+ bounces?: boolean;
26
+ scrollEventThrottle?: number;
27
+ height?: number | string;
28
+ width?: number | string;
29
+ listData?: ListItem[];
30
+ generichash?: string;
31
+ style?: Record<string, any>;
32
+ itemHeight?: ItemHeightType;
33
+ sectionHeaderHeight?: ItemHeightType;
34
+ listHeaderData?: any;
35
+ listHeaderHeight?: ItemHeightType;
36
+ useListHeader?: boolean;
37
+ listFooterData?: any;
38
+ useListFooter?: boolean;
39
+ 'genericrecycle-item'?: string;
40
+ 'genericsection-header'?: string;
41
+ 'genericlist-header'?: string;
42
+ 'genericlist-footer'?: string;
43
+ 'enable-var'?: boolean;
44
+ 'external-var-context'?: any;
45
+ 'parent-font-size'?: number;
46
+ 'parent-width'?: number;
47
+ 'parent-height'?: number;
48
+ 'enable-sticky'?: boolean;
49
+ 'enable-back-to-top'?: boolean;
50
+ 'end-reached-threshold'?: number;
51
+ 'refresher-enabled'?: boolean;
52
+ 'show-scrollbar'?: boolean;
53
+ 'refresher-triggered'?: boolean;
54
+ bindrefresherrefresh?: (event: any) => void;
55
+ bindscrolltolower?: (event: any) => void;
56
+ bindscroll?: (event: any) => void;
57
+ [key: string]: any;
58
+ }
59
+
60
+ interface ScrollPositionParams {
61
+ index: number;
62
+ animated?: boolean;
63
+ viewOffset?: number;
64
+ viewPosition?: number;
65
+ }
66
+
67
+ const getGeneric = (generichash: string, generickey: string) => {
68
+ if (!generichash || !generickey) return null
69
+ const GenericComponent = global.__mpxGenericsMap?.[generichash]?.[generickey]?.()
70
+ if (!GenericComponent) return null
71
+
72
+ return memo(forwardRef((props: any, ref: any) => {
73
+ return createElement(GenericComponent, extendObject({}, {
74
+ ref: ref
75
+ }, props))
76
+ }))
77
+ }
78
+
79
+ const _SectionList = forwardRef<any, SectionListProps>((props = {}, ref) => {
80
+ const {
81
+ enhanced = false,
82
+ bounces = true,
83
+ scrollEventThrottle = 0,
84
+ height,
85
+ width,
86
+ listData,
87
+ generichash,
88
+ style = {},
89
+ itemHeight = {},
90
+ sectionHeaderHeight = {},
91
+ listHeaderHeight = {},
92
+ listHeaderData = null,
93
+ useListHeader = false,
94
+ listFooterData = null,
95
+ useListFooter = false,
96
+ 'genericrecycle-item': genericrecycleItem,
97
+ 'genericsection-header': genericsectionHeader,
98
+ 'genericlist-header': genericListHeader,
99
+ 'genericlist-footer': genericListFooter,
100
+ 'enable-var': enableVar,
101
+ 'external-var-context': externalVarContext,
102
+ 'parent-font-size': parentFontSize,
103
+ 'parent-width': parentWidth,
104
+ 'parent-height': parentHeight,
105
+ 'enable-sticky': enableSticky = false,
106
+ 'enable-back-to-top': enableBackToTop = false,
107
+ 'end-reached-threshold': onEndReachedThreshold = 0.1,
108
+ 'refresher-enabled': refresherEnabled,
109
+ 'show-scrollbar': showScrollbar = true,
110
+ 'refresher-triggered': refresherTriggered
111
+ } = props
112
+
113
+ const [refreshing, setRefreshing] = useState(!!refresherTriggered)
114
+
115
+ const scrollViewRef = useRef<any>(null)
116
+
117
+ const indexMap = useRef<{ [key: string]: string | number }>({})
118
+
119
+ const reverseIndexMap = useRef<{ [key: string]: number }>({})
120
+
121
+ const {
122
+ hasSelfPercent,
123
+ setWidth,
124
+ setHeight
125
+ } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
126
+
127
+ const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef })
128
+
129
+ useEffect(() => {
130
+ if (refreshing !== refresherTriggered) {
131
+ setRefreshing(!!refresherTriggered)
132
+ }
133
+ }, [refresherTriggered])
134
+
135
+ const onRefresh = () => {
136
+ const { bindrefresherrefresh } = props
137
+ bindrefresherrefresh &&
138
+ bindrefresherrefresh(
139
+ getCustomEvent('refresherrefresh', {}, { layoutRef }, props)
140
+ )
141
+ }
142
+
143
+ const onEndReached = () => {
144
+ const { bindscrolltolower } = props
145
+ bindscrolltolower &&
146
+ bindscrolltolower(
147
+ getCustomEvent('scrolltolower', {}, { layoutRef }, props)
148
+ )
149
+ }
150
+
151
+ const onScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
152
+ const { bindscroll } = props
153
+ bindscroll &&
154
+ bindscroll(
155
+ getCustomEvent('scroll', event.nativeEvent, { layoutRef }, props)
156
+ )
157
+ }
158
+
159
+ // 通过sectionIndex和rowIndex获取原始索引
160
+ const getOriginalIndex = (sectionIndex: number, rowIndex: number | 'header'): number => {
161
+ const key = `${sectionIndex}_${rowIndex}`
162
+ return reverseIndexMap.current[key] ?? -1 // 如果找不到,返回-1
163
+ }
164
+
165
+ const scrollToIndex = ({ index, animated, viewOffset = 0, viewPosition = 0 }: ScrollPositionParams) => {
166
+ if (scrollViewRef.current) {
167
+ // 通过索引映射表快速定位位置
168
+ const position = indexMap.current[index]
169
+ const [sectionIndex, itemIndex] = (position as string).split('_')
170
+ scrollViewRef.current.scrollToLocation?.({
171
+ itemIndex: itemIndex === 'header' ? 0 : Number(itemIndex) + 1,
172
+ sectionIndex: Number(sectionIndex) || 0,
173
+ animated,
174
+ viewOffset,
175
+ viewPosition
176
+ })
177
+ }
178
+ }
179
+
180
+ const getItemHeight = ({ sectionIndex, rowIndex }: { sectionIndex: number, rowIndex: number }) => {
181
+ if (!itemHeight) {
182
+ return 0
183
+ }
184
+ if ((itemHeight as ItemHeightType).getter) {
185
+ const item = convertedListData[sectionIndex].data[rowIndex]
186
+ // 使用getOriginalIndex获取原始索引
187
+ const originalIndex = getOriginalIndex(sectionIndex, rowIndex)
188
+ return (itemHeight as ItemHeightType).getter?.(item, originalIndex) || 0
189
+ } else {
190
+ return (itemHeight as ItemHeightType).value || 0
191
+ }
192
+ }
193
+
194
+ const getSectionHeaderHeight = ({ sectionIndex }: { sectionIndex: number }) => {
195
+ const item = convertedListData[sectionIndex]
196
+ const { hasSectionHeader } = item
197
+ // 使用getOriginalIndex获取原始索引
198
+ const originalIndex = getOriginalIndex(sectionIndex, 'header')
199
+ if (!hasSectionHeader) return 0
200
+ if ((sectionHeaderHeight as ItemHeightType).getter) {
201
+ return (sectionHeaderHeight as ItemHeightType).getter?.(item, originalIndex) || 0
202
+ } else {
203
+ return (sectionHeaderHeight as ItemHeightType).value || 0
204
+ }
205
+ }
206
+
207
+ const convertedListData = useMemo(() => {
208
+ const sections: Section[] = []
209
+ let currentSection: Section | null = null
210
+ // 清空之前的索引映射
211
+ indexMap.current = {}
212
+ // 清空反向索引映射
213
+ reverseIndexMap.current = {}
214
+
215
+ // 处理 listData 为空的情况
216
+ if (!listData || !listData.length) {
217
+ return sections
218
+ }
219
+
220
+ listData.forEach((item: ListItem, index: number) => {
221
+ if (item.isSectionHeader) {
222
+ // 如果已经存在一个 section,先把它添加到 sections 中
223
+ if (currentSection) {
224
+ sections.push(currentSection)
225
+ }
226
+ // 创建新的 section
227
+ currentSection = {
228
+ headerData: item,
229
+ data: [],
230
+ hasSectionHeader: true,
231
+ _originalItemIndex: index
232
+ }
233
+ // 为 section header 添加索引映射
234
+ const sectionIndex = sections.length
235
+ indexMap.current[index] = `${sectionIndex}_header`
236
+ // 添加反向索引映射
237
+ reverseIndexMap.current[`${sectionIndex}_header`] = index
238
+ } else {
239
+ // 如果没有当前 section,创建一个默认的
240
+ if (!currentSection) {
241
+ // 创建默认section (无header的section)
242
+ currentSection = {
243
+ headerData: null,
244
+ data: [],
245
+ hasSectionHeader: false,
246
+ _originalItemIndex: -1
247
+ }
248
+ }
249
+ // 将 item 添加到当前 section 的 data 中
250
+ const itemIndex = currentSection.data.length
251
+ currentSection.data.push(extendObject({}, item, {
252
+ _originalItemIndex: index
253
+ }))
254
+ let sectionIndex
255
+ // 为 item 添加索引映射 - 存储格式为: "sectionIndex_itemIndex"
256
+ if (!currentSection.hasSectionHeader && sections.length === 0) {
257
+ // 在默认section中(第一个且无header)
258
+ sectionIndex = 0
259
+ indexMap.current[index] = `${sectionIndex}_${itemIndex}`
260
+ } else {
261
+ // 在普通section中
262
+ sectionIndex = sections.length
263
+ indexMap.current[index] = `${sectionIndex}_${itemIndex}`
264
+ }
265
+ // 添加反向索引映射
266
+ reverseIndexMap.current[`${sectionIndex}_${itemIndex}`] = index
267
+ }
268
+ })
269
+ // 添加最后一个 section
270
+ if (currentSection) {
271
+ sections.push(currentSection)
272
+ }
273
+ return sections
274
+ }, [listData])
275
+
276
+ const { getItemLayout } = useMemo(() => {
277
+ const layouts: Array<{ length: number, offset: number, index: number }> = []
278
+ let offset = 0
279
+
280
+ if (useListHeader) {
281
+ // 计算列表头部的高度
282
+ offset += listHeaderHeight.getter?.() || listHeaderHeight.value || 0
283
+ }
284
+
285
+ // 遍历所有 sections
286
+ convertedListData.forEach((section: Section, sectionIndex: number) => {
287
+ // 添加 section header 的位置信息
288
+ const headerHeight = getSectionHeaderHeight({ sectionIndex })
289
+ layouts.push({
290
+ length: headerHeight,
291
+ offset,
292
+ index: layouts.length
293
+ })
294
+ offset += headerHeight
295
+
296
+ // 添加该 section 中所有 items 的位置信息
297
+ section.data.forEach((item: ListItem, itemIndex: number) => {
298
+ const contenteight = getItemHeight({ sectionIndex, rowIndex: itemIndex })
299
+ layouts.push({
300
+ length: contenteight,
301
+ offset,
302
+ index: layouts.length
303
+ })
304
+ offset += contenteight
305
+ })
306
+
307
+ // 添加该 section 尾部位置信息
308
+ // 因为即使 sectionList 没传 renderSectionFooter,getItemLayout 中的 index 的计算也会包含尾部节点
309
+ layouts.push({
310
+ length: 0,
311
+ offset,
312
+ index: layouts.length
313
+ })
314
+ })
315
+ return {
316
+ itemLayouts: layouts,
317
+ getItemLayout: (data: any, index: number) => layouts[index]
318
+ }
319
+ }, [convertedListData, useListHeader, itemHeight.value, itemHeight.getter, sectionHeaderHeight.value, sectionHeaderHeight.getter, listHeaderHeight.value, listHeaderHeight.getter])
320
+
321
+ const scrollAdditionalProps = extendObject(
322
+ {
323
+ alwaysBounceVertical: false,
324
+ alwaysBounceHorizontal: false,
325
+ scrollEventThrottle: scrollEventThrottle,
326
+ scrollsToTop: enableBackToTop,
327
+ showsHorizontalScrollIndicator: showScrollbar,
328
+ onEndReachedThreshold,
329
+ ref: scrollViewRef,
330
+ bounces: false,
331
+ stickySectionHeadersEnabled: enableSticky,
332
+ onScroll: onScroll,
333
+ onEndReached: onEndReached
334
+ },
335
+ layoutProps
336
+ )
337
+
338
+ if (enhanced) {
339
+ Object.assign(scrollAdditionalProps, {
340
+ bounces
341
+ })
342
+ }
343
+ if (refresherEnabled) {
344
+ Object.assign(scrollAdditionalProps, {
345
+ refreshing: refreshing
346
+ })
347
+ }
348
+
349
+ useImperativeHandle(ref, () => {
350
+ return {
351
+ ...props,
352
+ scrollToIndex
353
+ }
354
+ })
355
+
356
+ const innerProps = useInnerProps(extendObject({}, props, scrollAdditionalProps), [
357
+ 'id',
358
+ 'show-scrollbar',
359
+ 'lower-threshold',
360
+ 'refresher-triggered',
361
+ 'refresher-enabled',
362
+ 'bindrefresherrefresh'
363
+ ], { layoutRef })
364
+
365
+ // 使用 ref 保存最新的数据,避免数据变化时组件销毁重建
366
+ const listHeaderDataRef = useRef(listHeaderData)
367
+ listHeaderDataRef.current = listHeaderData
368
+
369
+ const listFooterDataRef = useRef(listFooterData)
370
+ listFooterDataRef.current = listFooterData
371
+
372
+ // 使用 useMemo 获取 GenericComponent 并创建渲染函数,避免每次组件更新都重新创建函数引用导致不必要的重新渲染
373
+ const renderItem = useMemo(
374
+ () => {
375
+ const ItemComponent = getGeneric(generichash, genericrecycleItem)
376
+ if (!ItemComponent) return undefined
377
+ return ({ item }: { item: any }) => createElement(ItemComponent, { itemData: item })
378
+ },
379
+ [generichash, genericrecycleItem]
380
+ )
381
+
382
+ const renderSectionHeader = useMemo(
383
+ () => {
384
+ const SectionHeaderComponent = getGeneric(generichash, genericsectionHeader)
385
+ if (!SectionHeaderComponent) return undefined
386
+ return (sectionData: { section: Section }) => {
387
+ if (!sectionData.section.hasSectionHeader) return null
388
+ return createElement(SectionHeaderComponent, { itemData: sectionData.section.headerData })
389
+ }
390
+ },
391
+ [generichash, genericsectionHeader]
392
+ )
393
+
394
+ const ListHeaderComponent = useMemo(
395
+ () => {
396
+ if (!useListHeader) return null
397
+ const ListHeaderGenericComponent = getGeneric(generichash, genericListHeader)
398
+ if (!ListHeaderGenericComponent) return null
399
+ return () => createElement(ListHeaderGenericComponent, { listHeaderData: listHeaderDataRef.current })
400
+ },
401
+ [useListHeader, generichash, genericListHeader]
402
+ )
403
+
404
+ const ListFooterComponent = useMemo(
405
+ () => {
406
+ if (!useListFooter) return null
407
+ const ListFooterGenericComponent = getGeneric(generichash, genericListFooter)
408
+ if (!ListFooterGenericComponent) return null
409
+ return () => createElement(ListFooterGenericComponent, { listFooterData: listFooterDataRef.current })
410
+ },
411
+ [useListFooter, generichash, genericListFooter]
412
+ )
413
+
414
+ return createElement(
415
+ SectionList,
416
+ extendObject(
417
+ {
418
+ style: [{ height, width }, style, layoutStyle],
419
+ sections: convertedListData,
420
+ renderItem: renderItem,
421
+ getItemLayout: getItemLayout,
422
+ ListHeaderComponent: useListHeader ? ListHeaderComponent : null,
423
+ ListFooterComponent: useListFooter ? ListFooterComponent : null,
424
+ renderSectionHeader: renderSectionHeader,
425
+ refreshControl: refresherEnabled
426
+ ? React.createElement(RefreshControl, {
427
+ onRefresh: onRefresh,
428
+ refreshing: refreshing
429
+ })
430
+ : undefined
431
+ },
432
+ innerProps
433
+ )
434
+ )
435
+ })
436
+
437
+ _SectionList.displayName = 'MpxSectionList'
438
+
439
+ export default _SectionList
@@ -33,9 +33,8 @@ const _StickyHeader = forwardRef<HandlerRef<View, StickyHeaderProps>, StickyHead
33
33
  'parent-height': parentHeight
34
34
  } = props
35
35
 
36
- const scrollViewContext = useContext(ScrollViewContext)
36
+ const { scrollOffset, gestureRef: scrollViewRef } = useContext(ScrollViewContext)
37
37
  const stickyContext = useContext(StickyContext)
38
- const { scrollOffset } = scrollViewContext
39
38
  const { registerStickyHeader, unregisterStickyHeader } = stickyContext
40
39
  const headerRef = useRef<View>(null)
41
40
  const isStickOnTopRef = useRef(false)
@@ -67,7 +66,6 @@ const _StickyHeader = forwardRef<HandlerRef<View, StickyHeaderProps>, StickyHead
67
66
 
68
67
  function updatePosition () {
69
68
  if (headerRef.current) {
70
- const scrollViewRef = scrollViewContext.gestureRef
71
69
  if (scrollViewRef && scrollViewRef.current) {
72
70
  headerRef.current.measureLayout(
73
71
  scrollViewRef.current,
@@ -95,7 +93,7 @@ const _StickyHeader = forwardRef<HandlerRef<View, StickyHeaderProps>, StickyHead
95
93
  })
96
94
 
97
95
  useEffect(() => {
98
- if (!bindstickontopchange) return
96
+ if (!bindstickontopchange || !scrollOffset) return
99
97
 
100
98
  const listener = scrollOffset.addListener((state: { value: number }) => {
101
99
  const currentScrollValue = state.value
@@ -115,29 +113,31 @@ const _StickyHeader = forwardRef<HandlerRef<View, StickyHeaderProps>, StickyHead
115
113
  return () => {
116
114
  scrollOffset.removeListener(listener)
117
115
  }
118
- }, [])
116
+ }, [bindstickontopchange, scrollOffset])
119
117
 
120
118
  const animatedStyle = useMemo(() => {
121
- const translateY = Animated.subtract(scrollOffset, headerTopAnimated).interpolate({
122
- inputRange: [0, 1],
123
- outputRange: [0, 1],
124
- extrapolateLeft: 'clamp',
125
- extrapolateRight: 'extend'
126
- })
127
-
128
- const finalTranslateY = offsetTop === 0
129
- ? translateY
130
- : Animated.add(
131
- translateY,
132
- Animated.subtract(scrollOffset, headerTopAnimated).interpolate({
133
- inputRange: [0, 1],
134
- outputRange: [0, offsetTop],
135
- extrapolate: 'clamp'
136
- })
137
- )
119
+ if (scrollOffset) {
120
+ const translateY = Animated.subtract(scrollOffset, headerTopAnimated).interpolate({
121
+ inputRange: [0, 1],
122
+ outputRange: [0, 1],
123
+ extrapolateLeft: 'clamp',
124
+ extrapolateRight: 'extend'
125
+ })
126
+
127
+ const finalTranslateY = offsetTop === 0
128
+ ? translateY
129
+ : Animated.add(
130
+ translateY,
131
+ Animated.subtract(scrollOffset, headerTopAnimated).interpolate({
132
+ inputRange: [0, 1],
133
+ outputRange: [0, offsetTop],
134
+ extrapolate: 'clamp'
135
+ })
136
+ )
138
137
 
139
- return {
140
- transform: [{ translateY: finalTranslateY }]
138
+ return {
139
+ transform: [{ translateY: finalTranslateY }]
140
+ }
141
141
  }
142
142
  }, [scrollOffset, headerTopAnimated, offsetTop])
143
143