@react-native-ohos/flash-list 1.6.4-rc.1

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 (298) hide show
  1. package/LICENSE +7 -0
  2. package/README.OpenSource +11 -0
  3. package/README.md +9 -0
  4. package/dist/AnimatedFlashList.d.ts +6 -0
  5. package/dist/AnimatedFlashList.d.ts.map +1 -0
  6. package/dist/AnimatedFlashList.js +8 -0
  7. package/dist/AnimatedFlashList.js.map +1 -0
  8. package/dist/FlashList.d.ts +126 -0
  9. package/dist/FlashList.d.ts.map +1 -0
  10. package/dist/FlashList.js +524 -0
  11. package/dist/FlashList.js.map +1 -0
  12. package/dist/FlashListProps.d.ts +256 -0
  13. package/dist/FlashListProps.d.ts.map +1 -0
  14. package/dist/FlashListProps.js +9 -0
  15. package/dist/FlashListProps.js.map +1 -0
  16. package/dist/GridLayoutProviderWithProps.d.ts +42 -0
  17. package/dist/GridLayoutProviderWithProps.d.ts.map +1 -0
  18. package/dist/GridLayoutProviderWithProps.js +115 -0
  19. package/dist/GridLayoutProviderWithProps.js.map +1 -0
  20. package/dist/MasonryFlashList.d.ts +51 -0
  21. package/dist/MasonryFlashList.d.ts.map +1 -0
  22. package/dist/MasonryFlashList.js +252 -0
  23. package/dist/MasonryFlashList.js.map +1 -0
  24. package/dist/PureComponentWrapper.d.ts +22 -0
  25. package/dist/PureComponentWrapper.d.ts.map +1 -0
  26. package/dist/PureComponentWrapper.js +37 -0
  27. package/dist/PureComponentWrapper.js.map +1 -0
  28. package/dist/__tests__/AverageWindow.test.d.ts +2 -0
  29. package/dist/__tests__/AverageWindow.test.d.ts.map +1 -0
  30. package/dist/__tests__/AverageWindow.test.js +69 -0
  31. package/dist/__tests__/AverageWindow.test.js.map +1 -0
  32. package/dist/__tests__/ContentContainerUtils.test.d.ts +2 -0
  33. package/dist/__tests__/ContentContainerUtils.test.d.ts.map +1 -0
  34. package/dist/__tests__/ContentContainerUtils.test.js +85 -0
  35. package/dist/__tests__/ContentContainerUtils.test.js.map +1 -0
  36. package/dist/__tests__/FlashList.test.d.ts +2 -0
  37. package/dist/__tests__/FlashList.test.d.ts.map +1 -0
  38. package/dist/__tests__/FlashList.test.js +792 -0
  39. package/dist/__tests__/FlashList.test.js.map +1 -0
  40. package/dist/__tests__/GridLayoutProviderWithProps.test.d.ts +2 -0
  41. package/dist/__tests__/GridLayoutProviderWithProps.test.d.ts.map +1 -0
  42. package/dist/__tests__/GridLayoutProviderWithProps.test.js +143 -0
  43. package/dist/__tests__/GridLayoutProviderWithProps.test.js.map +1 -0
  44. package/dist/__tests__/MasonryFlashList.test.d.ts +2 -0
  45. package/dist/__tests__/MasonryFlashList.test.d.ts.map +1 -0
  46. package/dist/__tests__/MasonryFlashList.test.js +254 -0
  47. package/dist/__tests__/MasonryFlashList.test.js.map +1 -0
  48. package/dist/__tests__/PlatformHelper.web.test.d.ts +2 -0
  49. package/dist/__tests__/PlatformHelper.web.test.d.ts.map +1 -0
  50. package/dist/__tests__/PlatformHelper.web.test.js +33 -0
  51. package/dist/__tests__/PlatformHelper.web.test.js.map +1 -0
  52. package/dist/__tests__/ViewabilityHelper.test.d.ts +2 -0
  53. package/dist/__tests__/ViewabilityHelper.test.d.ts.map +1 -0
  54. package/dist/__tests__/ViewabilityHelper.test.js +187 -0
  55. package/dist/__tests__/ViewabilityHelper.test.js.map +1 -0
  56. package/dist/__tests__/helpers/mountFlashList.d.ts +19 -0
  57. package/dist/__tests__/helpers/mountFlashList.d.ts.map +1 -0
  58. package/dist/__tests__/helpers/mountFlashList.js +44 -0
  59. package/dist/__tests__/helpers/mountFlashList.js.map +1 -0
  60. package/dist/__tests__/helpers/mountMasonryFlashList.d.ts +18 -0
  61. package/dist/__tests__/helpers/mountMasonryFlashList.d.ts.map +1 -0
  62. package/dist/__tests__/helpers/mountMasonryFlashList.js +49 -0
  63. package/dist/__tests__/helpers/mountMasonryFlashList.js.map +1 -0
  64. package/dist/__tests__/useBlankAreaTracker.test.d.ts +2 -0
  65. package/dist/__tests__/useBlankAreaTracker.test.d.ts.map +1 -0
  66. package/dist/__tests__/useBlankAreaTracker.test.js +177 -0
  67. package/dist/__tests__/useBlankAreaTracker.test.js.map +1 -0
  68. package/dist/benchmark/AutoScrollHelper.d.ts +18 -0
  69. package/dist/benchmark/AutoScrollHelper.d.ts.map +1 -0
  70. package/dist/benchmark/AutoScrollHelper.js +68 -0
  71. package/dist/benchmark/AutoScrollHelper.js.map +1 -0
  72. package/dist/benchmark/JSFPSMonitor.d.ts +23 -0
  73. package/dist/benchmark/JSFPSMonitor.d.ts.map +1 -0
  74. package/dist/benchmark/JSFPSMonitor.js +65 -0
  75. package/dist/benchmark/JSFPSMonitor.js.map +1 -0
  76. package/dist/benchmark/roundToDecimalPlaces.d.ts +2 -0
  77. package/dist/benchmark/roundToDecimalPlaces.d.ts.map +1 -0
  78. package/dist/benchmark/roundToDecimalPlaces.js +9 -0
  79. package/dist/benchmark/roundToDecimalPlaces.js.map +1 -0
  80. package/dist/benchmark/useBenchmark.d.ts +35 -0
  81. package/dist/benchmark/useBenchmark.d.ts.map +1 -0
  82. package/dist/benchmark/useBenchmark.js +167 -0
  83. package/dist/benchmark/useBenchmark.js.map +1 -0
  84. package/dist/benchmark/useBlankAreaTracker.d.ts +34 -0
  85. package/dist/benchmark/useBlankAreaTracker.d.ts.map +1 -0
  86. package/dist/benchmark/useBlankAreaTracker.js +67 -0
  87. package/dist/benchmark/useBlankAreaTracker.js.map +1 -0
  88. package/dist/benchmark/useDataMultiplier.d.ts +9 -0
  89. package/dist/benchmark/useDataMultiplier.d.ts.map +1 -0
  90. package/dist/benchmark/useDataMultiplier.js +25 -0
  91. package/dist/benchmark/useDataMultiplier.js.map +1 -0
  92. package/dist/benchmark/useFlatListBenchmark.d.ts +13 -0
  93. package/dist/benchmark/useFlatListBenchmark.d.ts.map +1 -0
  94. package/dist/benchmark/useFlatListBenchmark.js +100 -0
  95. package/dist/benchmark/useFlatListBenchmark.js.map +1 -0
  96. package/dist/errors/CustomError.d.ts +8 -0
  97. package/dist/errors/CustomError.d.ts.map +1 -0
  98. package/dist/errors/CustomError.js +14 -0
  99. package/dist/errors/CustomError.js.map +1 -0
  100. package/dist/errors/ExceptionList.d.ts +24 -0
  101. package/dist/errors/ExceptionList.d.ts.map +1 -0
  102. package/dist/errors/ExceptionList.js +26 -0
  103. package/dist/errors/ExceptionList.js.map +1 -0
  104. package/dist/errors/Warnings.d.ts +9 -0
  105. package/dist/errors/Warnings.d.ts.map +1 -0
  106. package/dist/errors/Warnings.js +13 -0
  107. package/dist/errors/Warnings.js.map +1 -0
  108. package/dist/fabric/AutoLayoutNativeComponent.d.ts +19 -0
  109. package/dist/fabric/AutoLayoutNativeComponent.d.ts.map +1 -0
  110. package/dist/fabric/AutoLayoutNativeComponent.js +29 -0
  111. package/dist/fabric/AutoLayoutNativeComponent.js.map +1 -0
  112. package/dist/fabric/CellContainerNativeComponent.d.ts +8 -0
  113. package/dist/fabric/CellContainerNativeComponent.d.ts.map +1 -0
  114. package/dist/fabric/CellContainerNativeComponent.js +29 -0
  115. package/dist/fabric/CellContainerNativeComponent.js.map +1 -0
  116. package/dist/index.d.ts +14 -0
  117. package/dist/index.d.ts.map +1 -0
  118. package/dist/index.js +32 -0
  119. package/dist/index.js.map +1 -0
  120. package/dist/native/auto-layout/AutoLayoutView.d.ts +22 -0
  121. package/dist/native/auto-layout/AutoLayoutView.d.ts.map +1 -0
  122. package/dist/native/auto-layout/AutoLayoutView.js +48 -0
  123. package/dist/native/auto-layout/AutoLayoutView.js.map +1 -0
  124. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.android.d.ts +4 -0
  125. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.android.d.ts.map +1 -0
  126. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.android.js +6 -0
  127. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.android.js.map +1 -0
  128. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.d.ts +5 -0
  129. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.d.ts.map +1 -0
  130. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.harmony.d.ts +4 -0
  131. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.harmony.d.ts.map +1 -0
  132. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.harmony.js +29 -0
  133. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.harmony.js.map +1 -0
  134. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.ios.d.ts +4 -0
  135. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.ios.d.ts.map +1 -0
  136. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.ios.js +6 -0
  137. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.ios.js.map +1 -0
  138. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.js +6 -0
  139. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.js.map +1 -0
  140. package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.d.ts +16 -0
  141. package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.d.ts.map +1 -0
  142. package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.js +3 -0
  143. package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.js.map +1 -0
  144. package/dist/native/cell-container/CellContainer.android.d.ts +6 -0
  145. package/dist/native/cell-container/CellContainer.android.d.ts.map +1 -0
  146. package/dist/native/cell-container/CellContainer.android.js +9 -0
  147. package/dist/native/cell-container/CellContainer.android.js.map +1 -0
  148. package/dist/native/cell-container/CellContainer.d.ts +8 -0
  149. package/dist/native/cell-container/CellContainer.d.ts.map +1 -0
  150. package/dist/native/cell-container/CellContainer.harmony.d.ts +6 -0
  151. package/dist/native/cell-container/CellContainer.harmony.d.ts.map +1 -0
  152. package/dist/native/cell-container/CellContainer.harmony.js +32 -0
  153. package/dist/native/cell-container/CellContainer.harmony.js.map +1 -0
  154. package/dist/native/cell-container/CellContainer.ios.d.ts +6 -0
  155. package/dist/native/cell-container/CellContainer.ios.d.ts.map +1 -0
  156. package/dist/native/cell-container/CellContainer.ios.js +9 -0
  157. package/dist/native/cell-container/CellContainer.ios.js.map +1 -0
  158. package/dist/native/cell-container/CellContainer.js +11 -0
  159. package/dist/native/cell-container/CellContainer.js.map +1 -0
  160. package/dist/native/cell-container/CellContainer.web.d.ts +7 -0
  161. package/dist/native/cell-container/CellContainer.web.d.ts.map +1 -0
  162. package/dist/native/cell-container/CellContainer.web.js +13 -0
  163. package/dist/native/cell-container/CellContainer.web.js.map +1 -0
  164. package/dist/native/config/PlatformHelper.android.d.ts +26 -0
  165. package/dist/native/config/PlatformHelper.android.d.ts.map +1 -0
  166. package/dist/native/config/PlatformHelper.android.js +23 -0
  167. package/dist/native/config/PlatformHelper.android.js.map +1 -0
  168. package/dist/native/config/PlatformHelper.d.ts +26 -0
  169. package/dist/native/config/PlatformHelper.d.ts.map +1 -0
  170. package/dist/native/config/PlatformHelper.harmony.d.ts +26 -0
  171. package/dist/native/config/PlatformHelper.harmony.d.ts.map +1 -0
  172. package/dist/native/config/PlatformHelper.harmony.js +22 -0
  173. package/dist/native/config/PlatformHelper.harmony.js.map +1 -0
  174. package/dist/native/config/PlatformHelper.ios.d.ts +26 -0
  175. package/dist/native/config/PlatformHelper.ios.d.ts.map +1 -0
  176. package/dist/native/config/PlatformHelper.ios.js +22 -0
  177. package/dist/native/config/PlatformHelper.ios.js.map +1 -0
  178. package/dist/native/config/PlatformHelper.js +23 -0
  179. package/dist/native/config/PlatformHelper.js.map +1 -0
  180. package/dist/native/config/PlatformHelper.web.d.ts +27 -0
  181. package/dist/native/config/PlatformHelper.web.d.ts.map +1 -0
  182. package/dist/native/config/PlatformHelper.web.js +25 -0
  183. package/dist/native/config/PlatformHelper.web.js.map +1 -0
  184. package/dist/tsconfig.tsbuildinfo +1 -0
  185. package/dist/utils/AverageWindow.d.ts +21 -0
  186. package/dist/utils/AverageWindow.d.ts.map +1 -0
  187. package/dist/utils/AverageWindow.js +49 -0
  188. package/dist/utils/AverageWindow.js.map +1 -0
  189. package/dist/utils/ContentContainerUtils.d.ts +27 -0
  190. package/dist/utils/ContentContainerUtils.d.ts.map +1 -0
  191. package/dist/utils/ContentContainerUtils.js +48 -0
  192. package/dist/utils/ContentContainerUtils.js.map +1 -0
  193. package/dist/viewability/ViewToken.d.ts +8 -0
  194. package/dist/viewability/ViewToken.d.ts.map +1 -0
  195. package/dist/viewability/ViewToken.js +3 -0
  196. package/dist/viewability/ViewToken.js.map +1 -0
  197. package/dist/viewability/ViewabilityHelper.d.ts +25 -0
  198. package/dist/viewability/ViewabilityHelper.d.ts.map +1 -0
  199. package/dist/viewability/ViewabilityHelper.js +104 -0
  200. package/dist/viewability/ViewabilityHelper.js.map +1 -0
  201. package/dist/viewability/ViewabilityManager.d.ts +24 -0
  202. package/dist/viewability/ViewabilityManager.d.ts.map +1 -0
  203. package/dist/viewability/ViewabilityManager.js +94 -0
  204. package/dist/viewability/ViewabilityManager.js.map +1 -0
  205. package/harmony/flash_list/BuildProfile.ets +5 -0
  206. package/harmony/flash_list/LICENSE +7 -0
  207. package/harmony/flash_list/build-profile.json5 +8 -0
  208. package/harmony/flash_list/hvigorfile.ts +1 -0
  209. package/harmony/flash_list/index.ets +29 -0
  210. package/harmony/flash_list/obfuscation-rules.txt +18 -0
  211. package/harmony/flash_list/oh-package-lock.json5 +17 -0
  212. package/harmony/flash_list/oh-package.json5 +13 -0
  213. package/harmony/flash_list/src/main/cpp/AutoLayoutNode.cpp +63 -0
  214. package/harmony/flash_list/src/main/cpp/AutoLayoutNode.h +57 -0
  215. package/harmony/flash_list/src/main/cpp/AutoLayoutShadow.cpp +140 -0
  216. package/harmony/flash_list/src/main/cpp/AutoLayoutShadow.h +66 -0
  217. package/harmony/flash_list/src/main/cpp/AutoLayoutViewComponentInstance.cpp +208 -0
  218. package/harmony/flash_list/src/main/cpp/AutoLayoutViewComponentInstance.h +78 -0
  219. package/harmony/flash_list/src/main/cpp/AutoLayoutViewEventEmitRequestHandler.h +53 -0
  220. package/harmony/flash_list/src/main/cpp/AutoLayoutViewJSIBinder.h +50 -0
  221. package/harmony/flash_list/src/main/cpp/CMakeLists.txt +7 -0
  222. package/harmony/flash_list/src/main/cpp/CellContainerComponentInstance.cpp +80 -0
  223. package/harmony/flash_list/src/main/cpp/CellContainerComponentInstance.h +67 -0
  224. package/harmony/flash_list/src/main/cpp/CellContainerJSIBinder.h +39 -0
  225. package/harmony/flash_list/src/main/cpp/ComponentDescriptors.h +40 -0
  226. package/harmony/flash_list/src/main/cpp/EventEmitters.cpp +40 -0
  227. package/harmony/flash_list/src/main/cpp/EventEmitters.h +48 -0
  228. package/harmony/flash_list/src/main/cpp/FlashListPackage.h +78 -0
  229. package/harmony/flash_list/src/main/cpp/FlashListStackNode.cpp +89 -0
  230. package/harmony/flash_list/src/main/cpp/FlashListStackNode.h +59 -0
  231. package/harmony/flash_list/src/main/cpp/Props.cpp +52 -0
  232. package/harmony/flash_list/src/main/cpp/Props.h +64 -0
  233. package/harmony/flash_list/src/main/cpp/ShadowNodes.cpp +34 -0
  234. package/harmony/flash_list/src/main/cpp/ShadowNodes.h +48 -0
  235. package/harmony/flash_list/src/main/ets/Logger.ets +64 -0
  236. package/harmony/flash_list/src/main/ets/RNAutoLayoutShadow.ets +154 -0
  237. package/harmony/flash_list/src/main/ets/RNAutoLayoutView.ets +252 -0
  238. package/harmony/flash_list/src/main/ets/RNCellContainer.ets +113 -0
  239. package/harmony/flash_list/src/main/module.json5 +7 -0
  240. package/harmony/flash_list/src/main/resources/base/element/color.json +8 -0
  241. package/harmony/flash_list/src/main/resources/base/element/string.json +16 -0
  242. package/harmony/flash_list/src/main/resources/base/media/icon.png +0 -0
  243. package/harmony/flash_list/src/main/resources/base/profile/main_pages.json +5 -0
  244. package/harmony/flash_list/src/main/resources/en_US/element/string.json +16 -0
  245. package/harmony/flash_list/src/main/resources/zh_CN/element/string.json +16 -0
  246. package/harmony/flash_list.har +0 -0
  247. package/jestSetup.js +16 -0
  248. package/package.json +88 -0
  249. package/src/AnimatedFlashList.ts +11 -0
  250. package/src/FlashList.tsx +870 -0
  251. package/src/FlashListProps.ts +335 -0
  252. package/src/GridLayoutProviderWithProps.ts +180 -0
  253. package/src/MasonryFlashList.tsx +476 -0
  254. package/src/PureComponentWrapper.tsx +42 -0
  255. package/src/__tests__/AverageWindow.test.ts +80 -0
  256. package/src/__tests__/ContentContainerUtils.test.ts +130 -0
  257. package/src/__tests__/FlashList.test.tsx +886 -0
  258. package/src/__tests__/GridLayoutProviderWithProps.test.ts +179 -0
  259. package/src/__tests__/MasonryFlashList.test.ts +292 -0
  260. package/src/__tests__/PlatformHelper.web.test.ts +45 -0
  261. package/src/__tests__/ViewabilityHelper.test.ts +283 -0
  262. package/src/__tests__/helpers/mountFlashList.tsx +62 -0
  263. package/src/__tests__/helpers/mountMasonryFlashList.tsx +70 -0
  264. package/src/__tests__/useBlankAreaTracker.test.tsx +204 -0
  265. package/src/benchmark/AutoScrollHelper.ts +70 -0
  266. package/src/benchmark/JSFPSMonitor.ts +74 -0
  267. package/src/benchmark/roundToDecimalPlaces.ts +4 -0
  268. package/src/benchmark/useBenchmark.ts +240 -0
  269. package/src/benchmark/useBlankAreaTracker.ts +117 -0
  270. package/src/benchmark/useDataMultiplier.ts +19 -0
  271. package/src/benchmark/useFlatListBenchmark.ts +107 -0
  272. package/src/errors/CustomError.ts +10 -0
  273. package/src/errors/ExceptionList.ts +28 -0
  274. package/src/errors/Warnings.ts +15 -0
  275. package/src/fabric/AutoLayoutNativeComponent.ts +51 -0
  276. package/src/fabric/CellContainerNativeComponent.ts +34 -0
  277. package/src/index.ts +43 -0
  278. package/src/native/auto-layout/AutoLayoutView.tsx +73 -0
  279. package/src/native/auto-layout/AutoLayoutViewNativeComponent.android.ts +7 -0
  280. package/src/native/auto-layout/AutoLayoutViewNativeComponent.harmony.ts +30 -0
  281. package/src/native/auto-layout/AutoLayoutViewNativeComponent.ios.ts +7 -0
  282. package/src/native/auto-layout/AutoLayoutViewNativeComponent.ts +7 -0
  283. package/src/native/auto-layout/AutoLayoutViewNativeComponentProps.ts +17 -0
  284. package/src/native/cell-container/CellContainer.android.ts +7 -0
  285. package/src/native/cell-container/CellContainer.harmony.ts +30 -0
  286. package/src/native/cell-container/CellContainer.ios.ts +6 -0
  287. package/src/native/cell-container/CellContainer.tsx +14 -0
  288. package/src/native/cell-container/CellContainer.web.tsx +9 -0
  289. package/src/native/config/PlatformHelper.android.ts +29 -0
  290. package/src/native/config/PlatformHelper.harmony.ts +51 -0
  291. package/src/native/config/PlatformHelper.ios.ts +28 -0
  292. package/src/native/config/PlatformHelper.ts +29 -0
  293. package/src/native/config/PlatformHelper.web.ts +34 -0
  294. package/src/utils/AverageWindow.ts +49 -0
  295. package/src/utils/ContentContainerUtils.ts +92 -0
  296. package/src/viewability/ViewToken.ts +7 -0
  297. package/src/viewability/ViewabilityHelper.ts +162 -0
  298. package/src/viewability/ViewabilityManager.ts +134 -0
@@ -0,0 +1,154 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2024 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { CellContainerDescriptor } from "./RNCellContainer";
26
+ import { RNOHContext } from '@rnoh/react-native-openharmony';
27
+ import Logger from './Logger';
28
+
29
+ export class AutoLayoutShadow {
30
+ horizontal: boolean = false;
31
+ scrollOffset: number = 0;
32
+ offsetFromStart: number = 0;
33
+ windowSize: number = 0;
34
+ renderOffset: number = 0;
35
+
36
+ blankOffsetAtStart: number = 0; // Tracks blank area from the top
37
+ blankOffsetAtEnd: number = 0; // Tracks blank area from the bottom
38
+
39
+ lastMaxBoundOverall: number = 0; // Tracks where the last pixel is drawn in the overall
40
+
41
+ private lastMaxBound: number = 0; // Tracks where the last pixel is drawn in the visible window
42
+ private lastMinBound: number = 0; // Tracks where first pixel is drawn in the visible window
43
+
44
+ /** Checks for overlaps or gaps between adjacent items and then applies a correction (Only Grid layouts with varying spans)
45
+ * Performance: RecyclerListView renders very small number of views and this is not going to trigger multiple layouts on Android side. Not expecting any major perf issue. */
46
+ clearGapsAndOverlaps(sortedItems: number[], ctx: RNOHContext): void {
47
+ let maxBound = 0;
48
+ let minBound = Number.MAX_SAFE_INTEGER;
49
+ let maxBoundNeighbour = 0;
50
+ this.lastMaxBoundOverall = 0;
51
+ for (let i = 0; i < sortedItems.length - 1; i++) {
52
+ const cell = ctx.descriptorRegistry.getDescriptor<CellContainerDescriptor>(sortedItems[i]);
53
+ Logger.debug(`[RNOH]: in AutoLayoutShadow cell: ${JSON.stringify(cell)}`)
54
+ const neighbour = ctx.descriptorRegistry.getDescriptor<CellContainerDescriptor>(sortedItems[i+1]);
55
+ Logger.debug(`[RNOH]: in AutoLayoutShadow neighbour: ${JSON.stringify(neighbour)}`)
56
+ let isNeighbourConsecutive = neighbour.rawProps.index === cell.rawProps.index ?? -1 + 1;
57
+ if (this.isWithinBounds(cell)) {
58
+ if (!this.horizontal) {
59
+ maxBound = Math.max(maxBound, cell.layoutMetrics.frame.origin.y + cell.layoutMetrics.frame.size.height);
60
+ minBound = Math.min(minBound, cell.layoutMetrics.frame.origin.y);
61
+ maxBoundNeighbour = maxBound;
62
+ if (isNeighbourConsecutive) {
63
+ if (cell.layoutMetrics.frame.origin.x < neighbour.layoutMetrics.frame.origin.x) {
64
+ if (cell.layoutMetrics.frame.origin.x + cell.layoutMetrics.frame.size.width !==
65
+ neighbour.layoutMetrics.frame.origin.x) {
66
+ neighbour.layoutMetrics.frame.origin.x = cell.layoutMetrics.frame.origin.x + cell.layoutMetrics.frame.size.width;
67
+ }
68
+ if (cell.layoutMetrics.frame.origin.y !== neighbour.layoutMetrics.frame.origin.y) {
69
+ neighbour.layoutMetrics.frame.origin.y = cell.layoutMetrics.frame.origin.y;
70
+ }
71
+ } else {
72
+ neighbour.layoutMetrics.frame.origin.y = maxBound;
73
+ }
74
+ }
75
+ if (this.isWithinBounds(neighbour)) {
76
+ maxBoundNeighbour = Math.max(maxBound, neighbour.layoutMetrics.frame.origin.y + neighbour.layoutMetrics.frame.size.height);
77
+ }
78
+ } else {
79
+ maxBound = Math.max(maxBound, cell.layoutMetrics.frame.origin.x + cell.layoutMetrics.frame.size.width);
80
+ minBound = Math.min(minBound, cell.layoutMetrics.frame.origin.x);
81
+ maxBoundNeighbour = maxBound;
82
+ if (cell.layoutMetrics.frame.origin.y < neighbour.layoutMetrics.frame.origin.y) {
83
+ if (cell.layoutMetrics.frame.origin.y + cell.layoutMetrics.frame.size.height !== neighbour.layoutMetrics.frame.origin.y) {
84
+ neighbour.layoutMetrics.frame.origin.y = cell.layoutMetrics.frame.origin.y + cell.layoutMetrics.frame.size.height;
85
+ }
86
+ if (cell.layoutMetrics.frame.origin.x !== neighbour.layoutMetrics.frame.origin.x) {
87
+ neighbour.layoutMetrics.frame.origin.x = cell.layoutMetrics.frame.origin.x;
88
+ }
89
+ } else {
90
+ neighbour.layoutMetrics.frame.origin.x = maxBound;
91
+ }
92
+ if (this.isWithinBounds(neighbour)) {
93
+ maxBoundNeighbour = Math.max(maxBound, neighbour.layoutMetrics.frame.origin.x + neighbour.layoutMetrics.frame.size.width);
94
+ }
95
+ }
96
+ }
97
+ this.lastMaxBoundOverall = Math.max(
98
+ this.lastMaxBoundOverall,
99
+ this.horizontal ? cell.layoutMetrics.frame.origin.x + cell.layoutMetrics.frame.size.width :
100
+ cell.layoutMetrics.frame.origin.y + cell.layoutMetrics.frame.size.height
101
+ );
102
+ this.lastMaxBoundOverall = Math.max(
103
+ this.lastMaxBoundOverall,
104
+ this.horizontal ? neighbour.layoutMetrics.frame.origin.x + neighbour.layoutMetrics.frame.size.width :
105
+ neighbour.layoutMetrics.frame.origin.y + neighbour.layoutMetrics.frame.size.height
106
+ );
107
+ }
108
+ this.lastMaxBound = maxBoundNeighbour;
109
+ this.lastMinBound = minBound;
110
+ }
111
+
112
+ /** Offset provided by react can be one frame behind the real one, it's important that this method is called with offset taken directly from
113
+ * scrollview object */
114
+ computeBlankFromGivenOffset(
115
+ actualScrollOffset: number,
116
+ distanceFromWindowStart: number,
117
+ distanceFromWindowEnd: number
118
+ ): number {
119
+ const actualOffset = actualScrollOffset - this.offsetFromStart;
120
+ this.blankOffsetAtStart = this.lastMinBound - actualOffset - distanceFromWindowStart;
121
+ this.blankOffsetAtEnd =
122
+ actualOffset +
123
+ this.windowSize -
124
+ this.renderOffset -
125
+ this.lastMaxBound -
126
+ distanceFromWindowEnd;
127
+ return Math.max(this.blankOffsetAtStart, this.blankOffsetAtEnd);
128
+ }
129
+
130
+ /** It's important to avoid correcting views outside the render window. An item that isn't being recycled might still remain in the view tree. If views outside get considered then gaps between
131
+ * unused items will cause algorithm to fail.*/
132
+ private isWithinBounds(cell: CellContainerDescriptor): boolean {
133
+ const scrollOffset = this.scrollOffset - this.offsetFromStart;
134
+ if (!this.horizontal) {
135
+ return (
136
+ (cell.layoutMetrics.frame.origin.y >= (scrollOffset - this.renderOffset) ||
137
+ (cell.layoutMetrics.frame.origin.y + cell.layoutMetrics.frame.size.height) >=
138
+ (scrollOffset - this.renderOffset) ) &&
139
+ (cell.layoutMetrics.frame.origin.y <= (scrollOffset + this.windowSize) ||
140
+ (cell.layoutMetrics.frame.origin.y + cell.layoutMetrics.frame.size.height) <=
141
+ (scrollOffset + this.windowSize) )
142
+ );
143
+ } else {
144
+ return (
145
+ (cell.layoutMetrics.frame.origin.x >= (scrollOffset - this.renderOffset) ||
146
+ (cell.layoutMetrics.frame.origin.x + cell.layoutMetrics.frame.size.width) >=
147
+ (scrollOffset - this.renderOffset)) &&
148
+ (cell.layoutMetrics.frame.origin.x <= (scrollOffset + this.windowSize) ||
149
+ (cell.layoutMetrics.frame.origin.x + cell.layoutMetrics.frame.size.width) <=
150
+ (scrollOffset + this.windowSize))
151
+ );
152
+ }
153
+ }
154
+ }
@@ -0,0 +1,252 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2024 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import {
26
+ Descriptor,
27
+ ComponentBuilderContext,
28
+ RNComponentFactory,
29
+ RNOHContext,
30
+ RNViewBase,
31
+ ViewBaseProps,
32
+ ViewRawProps,
33
+ Tag,
34
+ ViewDescriptorWrapperBase,
35
+ } from '@rnoh/react-native-openharmony';
36
+ import { ScrollViewDescriptor } from '@rnoh/react-native-openharmony/src/main/ets/RNOHCorePackage/components/RNScrollView/RNScrollView'
37
+ import { ViewBaseDescriptor } from '@rnoh/react-native-openharmony/src/main/ets/RNOHCorePackage/components/RNViewBase/RNViewBase'
38
+ import { CellContainerDescriptor } from "./RNCellContainer";
39
+ import { AutoLayoutShadow } from "./RNAutoLayoutShadow";
40
+ import Logger from './Logger';
41
+ import { _RNScrollViewManager } from '@rnoh/react-native-openharmony/src/main/ets/RNOHCorePackage/components/RNScrollView/RNScrollViewManager';
42
+
43
+ export interface AutoLayoutViewState {}
44
+
45
+ export interface AutoLayoutViewRawProps extends ViewRawProps {
46
+ scrollOffset?: number
47
+ windowSize?: number
48
+ renderAheadOffset?: number
49
+ horizontal?: number
50
+ enableInstrumentation?: boolean
51
+ disableAutoLayout?: boolean
52
+ }
53
+
54
+ export const FLASH_LIST_TYPE: string = "AutoLayoutView";
55
+
56
+ export type AutoLayoutViewDescriptor = Descriptor<"AutoLayoutView", ViewBaseProps, AutoLayoutViewState, AutoLayoutViewRawProps>
57
+
58
+ class AutoLayoutViewDescriptorWrapper extends ViewDescriptorWrapperBase<"AutoLayoutView", ViewBaseProps, AutoLayoutViewState, AutoLayoutViewRawProps> {
59
+ }
60
+
61
+ @Component
62
+ export struct RNAutoLayoutView {
63
+ ctx!: RNOHContext
64
+ tag: number = 0
65
+ @BuilderParam buildCustomComponent: (componentBuilderContext: ComponentBuilderContext) => void
66
+ @State descriptor: AutoLayoutViewDescriptor = Object() as AutoLayoutViewDescriptor
67
+ @State descriptorWrapper: AutoLayoutViewDescriptorWrapper | undefined = undefined
68
+ @State private childrenTags: Tag[] = []
69
+ private alShadow: AutoLayoutShadow = new AutoLayoutShadow()
70
+ private footerDescriptor: CellContainerDescriptor = Object() as CellContainerDescriptor
71
+ private parentViewDescriptor: ViewBaseDescriptor = Object() as ViewBaseDescriptor
72
+ private parentScrollViewDescriptor: ScrollViewDescriptor = Object() as ScrollViewDescriptor
73
+ private unregisterDescriptorChangesListener?: () => void = undefined
74
+
75
+ aboutToAppear() {
76
+ this.descriptor = this.ctx.descriptorRegistry.getDescriptor<AutoLayoutViewDescriptor>(this.tag)
77
+ this.descriptorWrapper = new AutoLayoutViewDescriptorWrapper(this.descriptor)
78
+ this.onDescriptorChange(this.descriptor)
79
+ this.unregisterDescriptorChangesListener = this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
80
+ (newDescriptor) => {
81
+ this.onDescriptorChange(newDescriptor as AutoLayoutViewDescriptor);
82
+ // this.descriptor = newDescriptor as AutoLayoutViewDescriptor
83
+ }
84
+ )
85
+ Logger.debug(`[RNOH]: in AutoLayoutViewDescriptor rawprops: ${JSON.stringify(this.descriptor.rawProps)}`)
86
+ }
87
+
88
+ aboutToDisappear() {
89
+ this.unregisterDescriptorChangesListener?.();
90
+ }
91
+
92
+ onDescriptorChange(newDescriptor: AutoLayoutViewDescriptor) {
93
+ this.childrenTags = this.descriptor.childrenTags;
94
+ this.descriptor = newDescriptor;
95
+ Logger.debug(`[RNOH]: in RNAutoLayoutView this.descriptor: ${JSON.stringify(this.descriptor)}`)
96
+ this.descriptorWrapper = new AutoLayoutViewDescriptorWrapper(this.descriptor);
97
+
98
+ const footerTag = this.getFooterTag();
99
+ this.footerDescriptor = this.ctx.descriptorRegistry.getDescriptor<CellContainerDescriptor>(footerTag);
100
+ Logger.debug(`[RNOH]: in RNAutoLayoutView footer descriptor: ${JSON.stringify(this.footerDescriptor)}`)
101
+
102
+ const autoLayoutParentTag = this.descriptor.parentTag;
103
+ this.parentViewDescriptor = this.ctx.descriptorRegistry.getDescriptor<ViewBaseDescriptor>(autoLayoutParentTag);
104
+ Logger.debug(`[RNOH]: in RNAutoLayoutView parentViewDescriptor: ${JSON.stringify(this.parentViewDescriptor)}`)
105
+ const autoLayoutGrandparentTag = this.parentViewDescriptor.parentTag
106
+ const autoLayoutGrandparentDescriptor = this.ctx.descriptorRegistry.getDescriptor<ViewBaseDescriptor>(autoLayoutGrandparentTag);
107
+ Logger.debug(`[RNOH]: in RNAutoLayoutView autoLayoutGrandparentDescriptor: ${JSON.stringify(autoLayoutGrandparentDescriptor)}`)
108
+ const parentScrollViewTag = autoLayoutGrandparentDescriptor.parentTag;
109
+ this.parentScrollViewDescriptor = this.ctx.descriptorRegistry.getDescriptor<ScrollViewDescriptor>(parentScrollViewTag);
110
+ Logger.debug(`[RNOH]: in RNAutoLayoutView parentScrollViewDescriptor: ${JSON.stringify(this.parentScrollViewDescriptor)}`)
111
+
112
+ this.alShadow.horizontal = this.descriptor.rawProps.horizontal === 1
113
+ this.alShadow.scrollOffset = this.descriptor.rawProps.scrollOffset as number
114
+ this.alShadow.windowSize = this.descriptor.rawProps.windowSize as number
115
+ this.alShadow.renderOffset = this.descriptor.rawProps.renderAheadOffset as number
116
+
117
+ Logger.debug(`[RNOH]: in RNAutoLayoutView descriptor: ${JSON.stringify(this.descriptor)}`)
118
+ this.fixLayout();
119
+ this.fixFooter();
120
+
121
+ if (this.descriptor.rawProps.enableInstrumentation && this.parentScrollViewDescriptor !== null) {
122
+ let scrollContainerSize = this.alShadow.horizontal ?
123
+ this.parentScrollViewDescriptor.layoutMetrics.frame.size.width :
124
+ this.parentScrollViewDescriptor.layoutMetrics.frame.size.height;
125
+ let scrollOffset = this.alShadow.horizontal ?
126
+ this.parentScrollViewDescriptor.props.contentOffsetX :
127
+ this.parentScrollViewDescriptor.props.contentOffsetY;
128
+ let startOffset = this.alShadow.horizontal ?
129
+ this.descriptor.layoutMetrics.frame.origin.x :
130
+ this.descriptor.layoutMetrics.frame.origin.y;
131
+ let endOffset: number = this.alShadow.horizontal ?
132
+ (this.descriptor.layoutMetrics.frame.origin.x + this.descriptor.layoutMetrics.frame.size.width) :
133
+ (this.descriptor.layoutMetrics.frame.origin.y + this.descriptor.layoutMetrics.frame.size.height)
134
+
135
+ let distanceFromWindowStart = Math.max(startOffset - scrollOffset, 0)
136
+ let distanceFromWindowEnd = Math.max(scrollOffset + scrollContainerSize - endOffset, 0)
137
+ this.descriptor.rawProps.windowSize = this.descriptor.layoutMetrics.frame.size.height
138
+
139
+ this.alShadow.computeBlankFromGivenOffset(scrollOffset, distanceFromWindowStart, distanceFromWindowEnd)
140
+ this.emitBlankAreaEvent();
141
+
142
+ }
143
+
144
+ Logger.debug(`[RNOH]: in RNAutoLayoutView aboutToAppear scrollViewDescriptor: ${JSON.stringify(this.parentScrollViewDescriptor)}`)
145
+ this.parentScrollViewDescriptor.state.contentSizeHeight = this.parentScrollViewDescriptor.layoutMetrics.frame.size.height;
146
+ Logger.debug(`[RNOH]: in RNAutoLayoutView aboutToAppear After scrollViewDescriptor: ${JSON.stringify(this.parentScrollViewDescriptor)}`)
147
+ }
148
+
149
+ fixLayout(): void {
150
+ Logger.debug(`[RNOH]: in RNAutoLayoutView fixLayout: start `)
151
+ if (this.childrenTags.length > 1 && !this.descriptor.rawProps.disableAutoLayout) {
152
+ Logger.debug(`[RNOH]: in RNAutoLayoutView fixLayout children: ` + this.childrenTags)
153
+ this.alShadow.offsetFromStart = this.alShadow.horizontal ?
154
+ this.descriptor.layoutMetrics.frame.origin.x :
155
+ this.descriptor.layoutMetrics.frame.origin.y;
156
+ this.alShadow.clearGapsAndOverlaps(this.childrenTags, this.ctx);
157
+ }
158
+ }
159
+
160
+ fixFooter(): void {
161
+ if (this.descriptor.rawProps.disableAutoLayout || this.parentScrollViewDescriptor === null) {
162
+ return;
163
+ }
164
+ const isAutoLayoutEndVisible = this.alShadow.horizontal ?
165
+ (this.descriptor.layoutMetrics.frame.origin.x + this.descriptor.layoutMetrics.frame.size.width) <=
166
+ (this.parentScrollViewDescriptor.layoutMetrics.frame.size.width) :
167
+ (this.descriptor.layoutMetrics.frame.origin.y + this.descriptor.layoutMetrics.frame.size.height) <=
168
+ (this.parentScrollViewDescriptor.layoutMetrics.frame.size.height);
169
+ if (!isAutoLayoutEndVisible) {
170
+ return;
171
+ }
172
+ const diff = this.getFooterDiff();
173
+ if (diff === 0 || this.footerDescriptor == null || this.parentViewDescriptor == null) {
174
+ return;
175
+ }
176
+ if (this.alShadow.horizontal) {
177
+ this.footerDescriptor.layoutMetrics.frame.origin.x += diff;
178
+ this.descriptor.layoutMetrics.frame.origin.x += diff;
179
+ this.parentViewDescriptor.layoutMetrics.frame.origin.x += diff;
180
+ } else {
181
+ this.footerDescriptor.layoutMetrics.frame.origin.y += diff
182
+ this.descriptor.layoutMetrics.frame.origin.y += diff;
183
+ Logger.debug(`[RNOH]: in RNAutoLayoutView aboutToAppear autoLayoutParentDescriptor: ${JSON.stringify(this.parentViewDescriptor)}`)
184
+ this.parentViewDescriptor.layoutMetrics.frame.origin.y += diff;
185
+ Logger.debug(`[RNOH]: in RNAutoLayoutView aboutToAppear After autoLayoutParentDescriptor: ${JSON.stringify(this.parentViewDescriptor)}`)
186
+ }
187
+ }
188
+
189
+ getFooterDiff(): number {
190
+ if (this.childrenTags.length === 0) {
191
+ this.alShadow.lastMaxBoundOverall = 0;
192
+ } else {
193
+ const lastChildTag = this.childrenTags[this.childrenTags.length - 1];
194
+ const lastChildDescriptor = this.ctx.descriptorRegistry.getDescriptor<CellContainerDescriptor>(lastChildTag);
195
+ this.alShadow.lastMaxBoundOverall = this.alShadow.horizontal ?
196
+ (lastChildDescriptor.layoutMetrics.frame.origin.x + lastChildDescriptor.layoutMetrics.frame.size.width) :
197
+ (lastChildDescriptor.layoutMetrics.frame.origin.y + lastChildDescriptor.layoutMetrics.frame.size.height);
198
+ }
199
+ const autoLayoutEnd = this.alShadow.horizontal ? this.descriptor.layoutMetrics.frame.size.width : this.descriptor.layoutMetrics.frame.size.height;
200
+ Logger.debug(`[RNOH]: in RNAutoLayoutView fixFooter getFooterDiff lastMaxBoundOverall: ${JSON.stringify(this.alShadow.lastMaxBoundOverall)}`)
201
+ Logger.debug(`[RNOH]: in RNAutoLayoutView fixFooter getFooterDiff autoLayoutEnd: ${JSON.stringify(autoLayoutEnd)}`)
202
+ return autoLayoutEnd - this.alShadow.lastMaxBoundOverall;
203
+ }
204
+
205
+ getFooterTag(): Tag | null {
206
+ let ParentTag: Tag = this.descriptor.parentTag as Tag;
207
+ let ParentDescriptor = this.ctx.descriptorRegistry.getDescriptor<ViewBaseDescriptor>(ParentTag);
208
+ let ParentChildrenTags: Tag[] = ParentDescriptor.childrenTags;
209
+ for (let i = 0; i < ParentChildrenTags.length; i++) {
210
+ const viewTag = ParentChildrenTags[i];
211
+ const cellContainer = this.ctx.descriptorRegistry.getDescriptor<CellContainerDescriptor>(viewTag);
212
+ if (cellContainer.rawProps.index === -1) {
213
+ Logger.debug(`[RNOH]: in RNAutoLayoutView fixFooter getFooterTag: ${JSON.stringify(viewTag)}`)
214
+ return viewTag;
215
+ }
216
+ }
217
+ return null;
218
+ }
219
+
220
+ // sortTagByIndex(childrenTags: Tag[]): Tag[] {
221
+ // let TagIndexMap = new List<[Tag, number]>();
222
+ // for (let idx = 0; idx < childrenTags.length; idx++) {
223
+ // const ChildDescriptor: CellContainerDescriptor = this.ctx.descriptorRegistry.getDescriptor(childrenTags[idx]) as CellContainerDescriptor;
224
+ // TagIndexMap.add([childrenTags[idx], ChildDescriptor.props.index])
225
+ // Logger.debug(`[RNOH]: before TagIndexMap: ${TagIndexMap[idx]}`)
226
+ // }
227
+ // TagIndexMap.sort((a, b) => a[1] - b[1])
228
+ // for (let idx = 0; idx < TagIndexMap.length; idx++) {
229
+ // Logger.debug(`[RNOH]: after TagIndexMap: ${TagIndexMap[idx]}`)
230
+ // }
231
+ // return
232
+ // }
233
+
234
+ emitBlankAreaEvent() {
235
+ this.ctx.rnInstance.emitComponentEvent(
236
+ this.descriptor.tag,
237
+ FLASH_LIST_TYPE,
238
+ {
239
+ offsetStart: this.alShadow.blankOffsetAtStart,
240
+ offsetEnd: this.alShadow.blankOffsetAtEnd,
241
+ }
242
+ )
243
+ }
244
+
245
+ build() {
246
+ RNViewBase({ ctx: this.ctx, tag: this.tag }) {
247
+ ForEach(this.descriptor.childrenTags, (childrenTag: Tag) => {
248
+ RNComponentFactory({ ctx: this.ctx, tag: childrenTag, buildCustomComponent: this.buildCustomComponent })
249
+ }, (childrenTag: Tag) => childrenTag.toString())
250
+ }
251
+ }
252
+ }
@@ -0,0 +1,113 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2024 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import {
26
+ Descriptor,
27
+ ComponentBuilderContext,
28
+ RNComponentFactory,
29
+ RNOHContext,
30
+ RNViewBase,
31
+ ViewBaseProps,
32
+ ViewRawProps,
33
+ ColorSegments,
34
+ BorderColors,
35
+ Tag,
36
+ ViewDescriptorWrapperBase
37
+ } from '@rnoh/react-native-openharmony';
38
+ import Logger from './Logger';
39
+
40
+ export const CELL_CONTAINER_TYPE: string = "CellContainer";
41
+
42
+ export interface CellContainerRawProps extends ViewRawProps {
43
+ index?: number
44
+ }
45
+
46
+ export interface CellContainerState {}
47
+
48
+ export type CellContainerDescriptor = Descriptor<"CellContainer", ViewBaseProps, CellContainerState, CellContainerRawProps>
49
+
50
+ class CellContainerDescriptorWrapper extends ViewDescriptorWrapperBase<"CellContainer", ViewBaseProps, CellContainerState, CellContainerRawProps> {
51
+ }
52
+
53
+ @Component
54
+ export struct RNCellContainer {
55
+ ctx!: RNOHContext
56
+ tag: number = 0
57
+ @BuilderParam buildCustomComponent: (componentBuilderContext: ComponentBuilderContext) => void
58
+ @State descriptor: CellContainerDescriptor = Object() as CellContainerDescriptor
59
+ @State descriptorWrapper: CellContainerDescriptorWrapper | undefined = undefined
60
+ private unregisterDescriptorChangesListener?: () => void = undefined
61
+ @State index: number = -1;
62
+ // @State private childrenTags: Tag[] = []
63
+
64
+ aboutToAppear() {
65
+ this.initComponent();
66
+ this.descriptor = this.ctx.descriptorRegistry.getDescriptor<CellContainerDescriptor>(this.tag)
67
+ this.descriptorWrapper = new CellContainerDescriptorWrapper(this.descriptor)
68
+
69
+ this.unregisterDescriptorChangesListener = this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
70
+ (newDescriptor) => {
71
+ this.descriptor = (newDescriptor as CellContainerDescriptor)
72
+ }
73
+ )
74
+ Logger.debug(`[RNOH]: in RNCellContainer descriptor: ${JSON.stringify(this.descriptor)}`)
75
+ Logger.debug(`[RNOH]: in RNCellContainer descriptorWrapper: ${JSON.stringify(this.descriptorWrapper)}`)
76
+ }
77
+
78
+ aboutToDisappear() {
79
+ this.unregisterDescriptorChangesListener?.()
80
+ }
81
+
82
+ initComponent() {
83
+ let descriptor = this.ctx.descriptorRegistry.getDescriptor<CellContainerDescriptor>(this.tag);
84
+ this.setDescriptor(descriptor)
85
+ // const parentTag = descriptor.parentTag;
86
+ this.unregisterDescriptorChangesListener = this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
87
+ (newDescriptor) => {
88
+ this.setDescriptor(newDescriptor as CellContainerDescriptor)
89
+ }
90
+ )
91
+ }
92
+
93
+ private setDescriptor(descriptor: CellContainerDescriptor) {
94
+ this.descriptorWrapper = new CellContainerDescriptorWrapper(descriptor)
95
+ }
96
+
97
+ setIndex(value: number): void {
98
+ this.index = value;
99
+ }
100
+
101
+ getIndex(): number {
102
+ Logger.debug(`[RNOH]: in RNCellContainer index: ${JSON.stringify(this.index)}`)
103
+ return this.index;
104
+ }
105
+
106
+ build() {
107
+ RNViewBase({ ctx: this.ctx, tag: this.tag }) {
108
+ ForEach(this.descriptor.childrenTags, (tag: Tag) => {
109
+ RNComponentFactory({ ctx: this.ctx, tag: tag, buildCustomComponent: this.buildCustomComponent })
110
+ }, (tag: Tag) => tag.toString())
111
+ }
112
+ }
113
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ module: {
3
+ name: 'flash_list',
4
+ type: 'har',
5
+ deviceTypes: ['default'],
6
+ },
7
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "color": [
3
+ {
4
+ "name": "start_window_background",
5
+ "value": "#FFFFFF"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "module_desc",
5
+ "value": "module description"
6
+ },
7
+ {
8
+ "name": "EntryAbility_desc",
9
+ "value": "description"
10
+ },
11
+ {
12
+ "name": "EntryAbility_label",
13
+ "value": "label"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "src": [
3
+ "pages/Index"
4
+ ]
5
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "module_desc",
5
+ "value": "module description"
6
+ },
7
+ {
8
+ "name": "EntryAbility_desc",
9
+ "value": "description"
10
+ },
11
+ {
12
+ "name": "EntryAbility_label",
13
+ "value": "label"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "string": [
3
+ {
4
+ "name": "module_desc",
5
+ "value": "模块描述"
6
+ },
7
+ {
8
+ "name": "EntryAbility_desc",
9
+ "value": "description"
10
+ },
11
+ {
12
+ "name": "EntryAbility_label",
13
+ "value": "label"
14
+ }
15
+ ]
16
+ }
Binary file
package/jestSetup.js ADDED
@@ -0,0 +1,16 @@
1
+ jest.mock("@shopify/flash-list", () => {
2
+ const ActualFlashList = jest.requireActual("@shopify/flash-list").FlashList;
3
+ class MockFlashList extends ActualFlashList {
4
+ componentDidMount() {
5
+ super.componentDidMount();
6
+ this.rlvRef?._scrollComponent?._scrollViewRef?.props.onLayout({
7
+ nativeEvent: { layout: { height: 900, width: 400 } },
8
+ });
9
+ }
10
+ }
11
+ return {
12
+ ...jest.requireActual("@shopify/flash-list"),
13
+ FlashList: MockFlashList,
14
+ AnimatedFlashList: MockFlashList,
15
+ };
16
+ });