@leonsilicon/react-native-wishlist 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 (320) hide show
  1. package/LICENSE +20 -0
  2. package/MGWishList.podspec +40 -0
  3. package/README.md +281 -0
  4. package/android/CMakeLists.txt +86 -0
  5. package/android/build.gradle +72 -0
  6. package/android/gradle.properties +5 -0
  7. package/android/spotless.gradle +24 -0
  8. package/android/src/main/AndroidManifest.xml +4 -0
  9. package/android/src/main/java/com/wishlist/ContentContainer.kt +22 -0
  10. package/android/src/main/java/com/wishlist/Orchestrator.kt +38 -0
  11. package/android/src/main/java/com/wishlist/TemplateContainer.kt +30 -0
  12. package/android/src/main/java/com/wishlist/TemplateContainerViewManager.kt +65 -0
  13. package/android/src/main/java/com/wishlist/TemplateInterceptor.kt +29 -0
  14. package/android/src/main/java/com/wishlist/TemplateInterceptorViewManager.kt +23 -0
  15. package/android/src/main/java/com/wishlist/UIScheduler.kt +15 -0
  16. package/android/src/main/java/com/wishlist/Wishlist.kt +135 -0
  17. package/android/src/main/java/com/wishlist/WishlistManagerModule.kt +51 -0
  18. package/android/src/main/java/com/wishlist/WishlistPackage.kt +47 -0
  19. package/android/src/main/java/com/wishlist/WishlistSoLoader.kt +17 -0
  20. package/android/src/main/java/com/wishlist/WishlistViewManager.kt +69 -0
  21. package/android/src/main/jni/ErrorHandlerAndroid.cpp +16 -0
  22. package/android/src/main/jni/ErrorHandlerAndroid.h +13 -0
  23. package/android/src/main/jni/JNIStateRegistry.cpp +22 -0
  24. package/android/src/main/jni/JNIStateRegistry.h +23 -0
  25. package/android/src/main/jni/OnLoad.cpp +12 -0
  26. package/android/src/main/jni/Orchestrator.cpp +167 -0
  27. package/android/src/main/jni/Orchestrator.hpp +78 -0
  28. package/android/src/main/jni/UISchedulerAndroid.cpp +20 -0
  29. package/android/src/main/jni/UISchedulerAndroid.h +18 -0
  30. package/android/src/main/jni/WishlistManagerModule.cpp +91 -0
  31. package/android/src/main/jni/WishlistManagerModule.hpp +43 -0
  32. package/android/src/main/jni/wishlist.h +19 -0
  33. package/cpp/ContentContainer/MGContentContainerComponentDescriptor.h +40 -0
  34. package/cpp/ContentContainer/MGContentContainerShadowNode.cpp +21 -0
  35. package/cpp/ContentContainer/MGContentContainerShadowNode.h +30 -0
  36. package/cpp/ContentContainer/MGContentContainerState.cpp +31 -0
  37. package/cpp/ContentContainer/MGContentContainerState.h +39 -0
  38. package/cpp/DataBinding/MGBindingProvider.hpp +21 -0
  39. package/cpp/DataBinding/MGDataBinding.hpp +23 -0
  40. package/cpp/DataBinding/MGDataBindingImpl.cpp +112 -0
  41. package/cpp/DataBinding/MGDataBindingImpl.hpp +35 -0
  42. package/cpp/DependencyInjection/MGDI.hpp +33 -0
  43. package/cpp/DependencyInjection/MGDIImpl.cpp +65 -0
  44. package/cpp/DependencyInjection/MGDIImpl.hpp +45 -0
  45. package/cpp/DependencyInjection/MGUIManagerHolder.cpp +21 -0
  46. package/cpp/DependencyInjection/MGUIManagerHolder.h +24 -0
  47. package/cpp/ItemProvider/ComponentsPool.cpp +91 -0
  48. package/cpp/ItemProvider/ComponentsPool.h +49 -0
  49. package/cpp/ItemProvider/ItemProvider.cpp +60 -0
  50. package/cpp/ItemProvider/ItemProvider.h +67 -0
  51. package/cpp/ItemProvider/ShadowNodeBinding.cpp +356 -0
  52. package/cpp/ItemProvider/ShadowNodeBinding.h +59 -0
  53. package/cpp/ItemProvider/ShadowNodeCopyMachine.cpp +95 -0
  54. package/cpp/ItemProvider/ShadowNodeCopyMachine.h +25 -0
  55. package/cpp/MGErrorHandler.h +12 -0
  56. package/cpp/MGViewportCarer/MGVSyncRequester.hpp +18 -0
  57. package/cpp/MGViewportCarer/MGViewportCarer.hpp +42 -0
  58. package/cpp/MGViewportCarer/MGViewportCarerImpl.cpp +453 -0
  59. package/cpp/MGViewportCarer/MGViewportCarerImpl.h +80 -0
  60. package/cpp/MGViewportCarer/MGViewportCarerListener.hpp +27 -0
  61. package/cpp/TemplateContainer/MGTemplateContainerComponentDescriptor.h +15 -0
  62. package/cpp/TemplateContainer/MGTemplateContainerShadowNode.cpp +43 -0
  63. package/cpp/TemplateContainer/MGTemplateContainerShadowNode.h +42 -0
  64. package/cpp/TemplateContainer/MGTemplateContainerState.cpp +37 -0
  65. package/cpp/TemplateContainer/MGTemplateContainerState.h +39 -0
  66. package/cpp/UIScheduler/MGUIScheduler.cpp +8 -0
  67. package/cpp/UIScheduler/MGUIScheduler.hpp +18 -0
  68. package/cpp/Wishlist/MGWishlistComponentDescriptor.h +14 -0
  69. package/cpp/Wishlist/MGWishlistShadowNode.cpp +49 -0
  70. package/cpp/Wishlist/MGWishlistShadowNode.h +37 -0
  71. package/cpp/Wishlist/MGWishlistState.cpp +57 -0
  72. package/cpp/Wishlist/MGWishlistState.h +42 -0
  73. package/cpp/WishlistDefine.h +3 -0
  74. package/cpp/WishlistJsRuntime.cpp +139 -0
  75. package/cpp/WishlistJsRuntime.h +59 -0
  76. package/ios/MGContentContainerComponent.h +9 -0
  77. package/ios/MGContentContainerComponent.mm +34 -0
  78. package/ios/MGErrorHandlerIOS.h +13 -0
  79. package/ios/MGErrorHandlerIOS.mm +12 -0
  80. package/ios/MGObjCJSIUtils.h +63 -0
  81. package/ios/MGTemplateContainerComponent.h +12 -0
  82. package/ios/MGTemplateContainerComponent.mm +105 -0
  83. package/ios/MGTemplateInterceptorComponent.h +9 -0
  84. package/ios/MGTemplateInterceptorComponent.mm +72 -0
  85. package/ios/MGWishListComponent.h +17 -0
  86. package/ios/MGWishListComponent.mm +187 -0
  87. package/ios/MGWishlistManager.h +21 -0
  88. package/ios/MGWishlistManager.mm +319 -0
  89. package/ios/MGWishlistQueue.h +11 -0
  90. package/ios/MGWishlistQueue.m +34 -0
  91. package/ios/Orchestrator/MGOrchestrator.h +35 -0
  92. package/ios/Orchestrator/MGOrchestrator.mm +139 -0
  93. package/ios/Orchestrator/MGOrchestratorCppAdapter.cpp +25 -0
  94. package/ios/Orchestrator/MGOrchestratorCppAdapter.hpp +32 -0
  95. package/ios/UIScheduleriOS/MGUIScheduleriOS.hpp +19 -0
  96. package/ios/UIScheduleriOS/MGUIScheduleriOS.mm +21 -0
  97. package/lib/commonjs/Colors.js +399 -0
  98. package/lib/commonjs/Colors.js.map +1 -0
  99. package/lib/commonjs/ComponentPool.js +28 -0
  100. package/lib/commonjs/ComponentPool.js.map +1 -0
  101. package/lib/commonjs/Components/ForEach.js +21 -0
  102. package/lib/commonjs/Components/ForEach.js.map +1 -0
  103. package/lib/commonjs/Components/ForEachBase.js +19 -0
  104. package/lib/commonjs/Components/ForEachBase.js.map +1 -0
  105. package/lib/commonjs/Components/IF.js +34 -0
  106. package/lib/commonjs/Components/IF.js.map +1 -0
  107. package/lib/commonjs/Components/Pressable.js +73 -0
  108. package/lib/commonjs/Components/Pressable.js.map +1 -0
  109. package/lib/commonjs/Components/Switch.js +52 -0
  110. package/lib/commonjs/Components/Switch.js.map +1 -0
  111. package/lib/commonjs/Components/WishlistImage.js +29 -0
  112. package/lib/commonjs/Components/WishlistImage.js.map +1 -0
  113. package/lib/commonjs/Components/WishlistText.js +24 -0
  114. package/lib/commonjs/Components/WishlistText.js.map +1 -0
  115. package/lib/commonjs/Components/WishlistView.js +10 -0
  116. package/lib/commonjs/Components/WishlistView.js.map +1 -0
  117. package/lib/commonjs/EventHandler.js +72 -0
  118. package/lib/commonjs/EventHandler.js.map +1 -0
  119. package/lib/commonjs/InflatorRepository.js +155 -0
  120. package/lib/commonjs/InflatorRepository.js.map +1 -0
  121. package/lib/commonjs/OrchestratorBinding.js +12 -0
  122. package/lib/commonjs/OrchestratorBinding.js.map +1 -0
  123. package/lib/commonjs/Specs/NativeContentContainer.js +12 -0
  124. package/lib/commonjs/Specs/NativeContentContainer.js.map +1 -0
  125. package/lib/commonjs/Specs/NativeTemplateContainer.js +12 -0
  126. package/lib/commonjs/Specs/NativeTemplateContainer.js.map +1 -0
  127. package/lib/commonjs/Specs/NativeTemplateInterceptor.js +10 -0
  128. package/lib/commonjs/Specs/NativeTemplateInterceptor.js.map +1 -0
  129. package/lib/commonjs/Specs/NativeWishlist.js +16 -0
  130. package/lib/commonjs/Specs/NativeWishlist.js.map +1 -0
  131. package/lib/commonjs/Specs/NativeWishlistManager.js +9 -0
  132. package/lib/commonjs/Specs/NativeWishlistManager.js.map +1 -0
  133. package/lib/commonjs/TemplateContext.js +17 -0
  134. package/lib/commonjs/TemplateContext.js.map +1 -0
  135. package/lib/commonjs/TemplateItem.js +2 -0
  136. package/lib/commonjs/TemplateItem.js.map +1 -0
  137. package/lib/commonjs/TemplateValue.js +68 -0
  138. package/lib/commonjs/TemplateValue.js.map +1 -0
  139. package/lib/commonjs/Utils.js +20 -0
  140. package/lib/commonjs/Utils.js.map +1 -0
  141. package/lib/commonjs/Wishlist.js +290 -0
  142. package/lib/commonjs/Wishlist.js.map +1 -0
  143. package/lib/commonjs/WishlistContext.js +17 -0
  144. package/lib/commonjs/WishlistContext.js.map +1 -0
  145. package/lib/commonjs/WishlistData.js +149 -0
  146. package/lib/commonjs/WishlistData.js.map +1 -0
  147. package/lib/commonjs/WishlistDataCopy.js +115 -0
  148. package/lib/commonjs/WishlistDataCopy.js.map +1 -0
  149. package/lib/commonjs/WishlistJsRuntime.android.js +22 -0
  150. package/lib/commonjs/WishlistJsRuntime.android.js.map +1 -0
  151. package/lib/commonjs/WishlistJsRuntime.js +42 -0
  152. package/lib/commonjs/WishlistJsRuntime.js.map +1 -0
  153. package/lib/commonjs/createTemplateComponent.js +196 -0
  154. package/lib/commonjs/createTemplateComponent.js.map +1 -0
  155. package/lib/commonjs/global.d.js +2 -0
  156. package/lib/commonjs/global.d.js.map +1 -0
  157. package/lib/commonjs/index.js +83 -0
  158. package/lib/commonjs/index.js.map +1 -0
  159. package/lib/commonjs/package.json +1 -0
  160. package/lib/commonjs/renderTemplate.js +14 -0
  161. package/lib/commonjs/renderTemplate.js.map +1 -0
  162. package/lib/module/Colors.js +395 -0
  163. package/lib/module/Colors.js.map +1 -0
  164. package/lib/module/ComponentPool.js +24 -0
  165. package/lib/module/ComponentPool.js.map +1 -0
  166. package/lib/module/Components/ForEach.js +17 -0
  167. package/lib/module/Components/ForEach.js.map +1 -0
  168. package/lib/module/Components/ForEachBase.js +14 -0
  169. package/lib/module/Components/ForEachBase.js.map +1 -0
  170. package/lib/module/Components/IF.js +29 -0
  171. package/lib/module/Components/IF.js.map +1 -0
  172. package/lib/module/Components/Pressable.js +68 -0
  173. package/lib/module/Components/Pressable.js.map +1 -0
  174. package/lib/module/Components/Switch.js +45 -0
  175. package/lib/module/Components/Switch.js.map +1 -0
  176. package/lib/module/Components/WishlistImage.js +25 -0
  177. package/lib/module/Components/WishlistImage.js.map +1 -0
  178. package/lib/module/Components/WishlistText.js +20 -0
  179. package/lib/module/Components/WishlistText.js.map +1 -0
  180. package/lib/module/Components/WishlistView.js +6 -0
  181. package/lib/module/Components/WishlistView.js.map +1 -0
  182. package/lib/module/EventHandler.js +66 -0
  183. package/lib/module/EventHandler.js.map +1 -0
  184. package/lib/module/InflatorRepository.js +149 -0
  185. package/lib/module/InflatorRepository.js.map +1 -0
  186. package/lib/module/OrchestratorBinding.js +8 -0
  187. package/lib/module/OrchestratorBinding.js.map +1 -0
  188. package/lib/module/Specs/NativeContentContainer.js +7 -0
  189. package/lib/module/Specs/NativeContentContainer.js.map +1 -0
  190. package/lib/module/Specs/NativeTemplateContainer.js +7 -0
  191. package/lib/module/Specs/NativeTemplateContainer.js.map +1 -0
  192. package/lib/module/Specs/NativeTemplateInterceptor.js +5 -0
  193. package/lib/module/Specs/NativeTemplateInterceptor.js.map +1 -0
  194. package/lib/module/Specs/NativeWishlist.js +11 -0
  195. package/lib/module/Specs/NativeWishlist.js.map +1 -0
  196. package/lib/module/Specs/NativeWishlistManager.js +5 -0
  197. package/lib/module/Specs/NativeWishlistManager.js.map +1 -0
  198. package/lib/module/TemplateContext.js +12 -0
  199. package/lib/module/TemplateContext.js.map +1 -0
  200. package/lib/module/TemplateItem.js +2 -0
  201. package/lib/module/TemplateItem.js.map +1 -0
  202. package/lib/module/TemplateValue.js +63 -0
  203. package/lib/module/TemplateValue.js.map +1 -0
  204. package/lib/module/Utils.js +15 -0
  205. package/lib/module/Utils.js.map +1 -0
  206. package/lib/module/Wishlist.js +284 -0
  207. package/lib/module/Wishlist.js.map +1 -0
  208. package/lib/module/WishlistContext.js +12 -0
  209. package/lib/module/WishlistContext.js.map +1 -0
  210. package/lib/module/WishlistData.js +144 -0
  211. package/lib/module/WishlistData.js.map +1 -0
  212. package/lib/module/WishlistDataCopy.js +111 -0
  213. package/lib/module/WishlistDataCopy.js.map +1 -0
  214. package/lib/module/WishlistJsRuntime.android.js +16 -0
  215. package/lib/module/WishlistJsRuntime.android.js.map +1 -0
  216. package/lib/module/WishlistJsRuntime.js +35 -0
  217. package/lib/module/WishlistJsRuntime.js.map +1 -0
  218. package/lib/module/createTemplateComponent.js +191 -0
  219. package/lib/module/createTemplateComponent.js.map +1 -0
  220. package/lib/module/global.d.js +2 -0
  221. package/lib/module/global.d.js.map +1 -0
  222. package/lib/module/index.js +14 -0
  223. package/lib/module/index.js.map +1 -0
  224. package/lib/module/renderTemplate.js +10 -0
  225. package/lib/module/renderTemplate.js.map +1 -0
  226. package/lib/typescript/Colors.d.ts +7 -0
  227. package/lib/typescript/Colors.d.ts.map +1 -0
  228. package/lib/typescript/ComponentPool.d.ts +10 -0
  229. package/lib/typescript/ComponentPool.d.ts.map +1 -0
  230. package/lib/typescript/Components/ForEach.d.ts +2 -0
  231. package/lib/typescript/Components/ForEach.d.ts.map +1 -0
  232. package/lib/typescript/Components/ForEachBase.d.ts +3 -0
  233. package/lib/typescript/Components/ForEachBase.d.ts.map +1 -0
  234. package/lib/typescript/Components/IF.d.ts +3 -0
  235. package/lib/typescript/Components/IF.d.ts.map +1 -0
  236. package/lib/typescript/Components/Pressable.d.ts +15 -0
  237. package/lib/typescript/Components/Pressable.d.ts.map +1 -0
  238. package/lib/typescript/Components/Switch.d.ts +17 -0
  239. package/lib/typescript/Components/Switch.d.ts.map +1 -0
  240. package/lib/typescript/Components/WishlistImage.d.ts +3 -0
  241. package/lib/typescript/Components/WishlistImage.d.ts.map +1 -0
  242. package/lib/typescript/Components/WishlistText.d.ts +3 -0
  243. package/lib/typescript/Components/WishlistText.d.ts.map +1 -0
  244. package/lib/typescript/Components/WishlistView.d.ts +3 -0
  245. package/lib/typescript/Components/WishlistView.d.ts.map +1 -0
  246. package/lib/typescript/EventHandler.d.ts +9 -0
  247. package/lib/typescript/EventHandler.d.ts.map +1 -0
  248. package/lib/typescript/InflatorRepository.d.ts +28 -0
  249. package/lib/typescript/InflatorRepository.d.ts.map +1 -0
  250. package/lib/typescript/OrchestratorBinding.d.ts +13 -0
  251. package/lib/typescript/OrchestratorBinding.d.ts.map +1 -0
  252. package/lib/typescript/Specs/NativeContentContainer.d.ts +6 -0
  253. package/lib/typescript/Specs/NativeContentContainer.d.ts.map +1 -0
  254. package/lib/typescript/Specs/NativeTemplateContainer.d.ts +9 -0
  255. package/lib/typescript/Specs/NativeTemplateContainer.d.ts.map +1 -0
  256. package/lib/typescript/Specs/NativeTemplateInterceptor.d.ts +6 -0
  257. package/lib/typescript/Specs/NativeTemplateInterceptor.d.ts.map +1 -0
  258. package/lib/typescript/Specs/NativeWishlist.d.ts +22 -0
  259. package/lib/typescript/Specs/NativeWishlist.d.ts.map +1 -0
  260. package/lib/typescript/Specs/NativeWishlistManager.d.ts +7 -0
  261. package/lib/typescript/Specs/NativeWishlistManager.d.ts.map +1 -0
  262. package/lib/typescript/TemplateContext.d.ts +9 -0
  263. package/lib/typescript/TemplateContext.d.ts.map +1 -0
  264. package/lib/typescript/TemplateItem.d.ts +13 -0
  265. package/lib/typescript/TemplateItem.d.ts.map +1 -0
  266. package/lib/typescript/TemplateValue.d.ts +16 -0
  267. package/lib/typescript/TemplateValue.d.ts.map +1 -0
  268. package/lib/typescript/Utils.d.ts +3 -0
  269. package/lib/typescript/Utils.d.ts.map +1 -0
  270. package/lib/typescript/Wishlist.d.ts +59 -0
  271. package/lib/typescript/Wishlist.d.ts.map +1 -0
  272. package/lib/typescript/WishlistContext.d.ts +11 -0
  273. package/lib/typescript/WishlistContext.d.ts.map +1 -0
  274. package/lib/typescript/WishlistData.d.ts +20 -0
  275. package/lib/typescript/WishlistData.d.ts.map +1 -0
  276. package/lib/typescript/WishlistDataCopy.d.ts +25 -0
  277. package/lib/typescript/WishlistDataCopy.d.ts.map +1 -0
  278. package/lib/typescript/WishlistJsRuntime.android.d.ts +4 -0
  279. package/lib/typescript/WishlistJsRuntime.android.d.ts.map +1 -0
  280. package/lib/typescript/WishlistJsRuntime.d.ts +6 -0
  281. package/lib/typescript/WishlistJsRuntime.d.ts.map +1 -0
  282. package/lib/typescript/createTemplateComponent.d.ts +35 -0
  283. package/lib/typescript/createTemplateComponent.d.ts.map +1 -0
  284. package/lib/typescript/index.d.ts +8 -0
  285. package/lib/typescript/index.d.ts.map +1 -0
  286. package/lib/typescript/renderTemplate.d.ts +3 -0
  287. package/lib/typescript/renderTemplate.d.ts.map +1 -0
  288. package/package.json +195 -0
  289. package/src/Colors.ts +474 -0
  290. package/src/ComponentPool.ts +33 -0
  291. package/src/Components/ForEach.tsx +22 -0
  292. package/src/Components/ForEachBase.tsx +8 -0
  293. package/src/Components/IF.tsx +20 -0
  294. package/src/Components/Pressable.tsx +111 -0
  295. package/src/Components/Switch.tsx +49 -0
  296. package/src/Components/WishlistImage.tsx +25 -0
  297. package/src/Components/WishlistText.tsx +14 -0
  298. package/src/Components/WishlistView.tsx +4 -0
  299. package/src/EventHandler.ts +78 -0
  300. package/src/InflatorRepository.ts +231 -0
  301. package/src/OrchestratorBinding.ts +15 -0
  302. package/src/Specs/NativeContentContainer.ts +9 -0
  303. package/src/Specs/NativeTemplateContainer.ts +13 -0
  304. package/src/Specs/NativeTemplateInterceptor.ts +8 -0
  305. package/src/Specs/NativeWishlist.ts +42 -0
  306. package/src/Specs/NativeWishlistManager.ts +7 -0
  307. package/src/TemplateContext.tsx +14 -0
  308. package/src/TemplateItem.ts +15 -0
  309. package/src/TemplateValue.tsx +101 -0
  310. package/src/Utils.ts +15 -0
  311. package/src/Wishlist.tsx +417 -0
  312. package/src/WishlistContext.tsx +15 -0
  313. package/src/WishlistData.ts +179 -0
  314. package/src/WishlistDataCopy.ts +138 -0
  315. package/src/WishlistJsRuntime.android.ts +20 -0
  316. package/src/WishlistJsRuntime.ts +59 -0
  317. package/src/createTemplateComponent.tsx +263 -0
  318. package/src/global.d.ts +1 -0
  319. package/src/index.ts +17 -0
  320. package/src/renderTemplate.ts +22 -0
@@ -0,0 +1,417 @@
1
+ import React, {
2
+ createContext,
3
+ Ref,
4
+ useContext,
5
+ useEffect,
6
+ useImperativeHandle,
7
+ useMemo,
8
+ useRef,
9
+ } from 'react';
10
+ import {
11
+ StyleProp,
12
+ StyleSheet,
13
+ Text,
14
+ useWindowDimensions,
15
+ View,
16
+ ViewProps,
17
+ ViewStyle,
18
+ } from 'react-native';
19
+ import { ComponentPool } from './ComponentPool';
20
+ import { ForEach } from './Components/ForEach';
21
+ import { IF } from './Components/IF';
22
+ import { Pressable } from './Components/Pressable';
23
+ import { Case, Switch } from './Components/Switch';
24
+ import { WishlistImage } from './Components/WishlistImage';
25
+ import { WishlistText } from './Components/WishlistText';
26
+ import { WishlistView } from './Components/WishlistView';
27
+ import { initEventHandler } from './EventHandler';
28
+ import InflatorRepository, { InflateMethod } from './InflatorRepository';
29
+ import NativeContentContainer from './Specs/NativeContentContainer';
30
+ import NativeTemplateContainer from './Specs/NativeTemplateContainer';
31
+ import NativeTemplateInterceptor from './Specs/NativeTemplateInterceptor';
32
+ import NativeWishList, {
33
+ Commands as WishlistCommands,
34
+ } from './Specs/NativeWishlist';
35
+ import { TemplateContext } from './TemplateContext';
36
+ import { TemplateItem } from './TemplateItem';
37
+ import { generateId } from './Utils';
38
+ import { useWishlistContext, WishlistContext } from './WishlistContext';
39
+ import type { WishlistData, WishlistDataInternal } from './WishlistData';
40
+
41
+ type NestedTemplatesContextValue = {
42
+ templates: { [key: string]: any };
43
+ registerTemplate(type: string, component: any): void;
44
+ };
45
+
46
+ const TemplatesRegistryContext =
47
+ createContext<NestedTemplatesContextValue | null>(null);
48
+
49
+ function getTemplatesFromChildren(children: React.ReactNode, width: number) {
50
+ const nextTemplates: { [key: string]: React.ReactElement } = {
51
+ __offsetComponent: <View style={[styles.offsetView, { width }]} />,
52
+ __viewComponent: <View />,
53
+ __textComponent: (
54
+ <Text>
55
+ <Text> </Text>
56
+ </Text>
57
+ ),
58
+ __paragraphComponent: <Text> </Text>,
59
+ };
60
+ React.Children.forEach(children, (c) => {
61
+ if ((c as any).type.displayName === 'WishListTemplate') {
62
+ const templateElement = c as React.ReactElement<TemplateProps>;
63
+ nextTemplates[templateElement.props.type] = templateElement;
64
+ }
65
+ });
66
+ return nextTemplates;
67
+ }
68
+
69
+ export type WishListInstance = {
70
+ scrollToItem: (index: number, animated?: boolean) => void;
71
+ scrollToTop: () => void;
72
+ };
73
+
74
+ export type BaseItem = { type: string; key: string };
75
+
76
+ type Props = ViewProps & {
77
+ data: WishlistData<any>;
78
+ onStartReached?: () => void;
79
+ onEndReached?: () => void;
80
+ initialIndex?: number;
81
+ contentContainerStyle?: StyleProp<ViewStyle> | undefined;
82
+ /**
83
+ * Rendered at the bottom of all the items. Can be a React Component Class, a render function, or
84
+ * a rendered element.
85
+ */
86
+ ListFooterComponent?:
87
+ | React.ComponentType<any>
88
+ | React.ReactElement
89
+ | null
90
+ | undefined;
91
+ /**
92
+ * Rendered at the top of all the items. Can be a React Component Class, a render function, or
93
+ * a rendered element.
94
+ */
95
+ ListHeaderComponent?:
96
+ | React.ComponentType<any>
97
+ | React.ReactElement
98
+ | null
99
+ | undefined;
100
+ };
101
+
102
+ function ComponentBase<T extends BaseItem>(
103
+ {
104
+ children,
105
+ style,
106
+ data,
107
+ contentContainerStyle,
108
+ ListFooterComponent,
109
+ ListHeaderComponent,
110
+ ...rest
111
+ }: Props,
112
+ ref: React.Ref<WishListInstance>,
113
+ ) {
114
+ const nativeWishlist = useRef<InstanceType<typeof NativeWishList> | null>(
115
+ null,
116
+ );
117
+ const wishlistId = useRef<string | null>(null);
118
+ if (!wishlistId.current) {
119
+ wishlistId.current = generateId();
120
+ }
121
+
122
+ useImperativeHandle(
123
+ ref,
124
+ (): WishListInstance => ({
125
+ scrollToItem: (index: number, animated?: boolean) => {
126
+ if (nativeWishlist.current != null) {
127
+ console.log('scrollTo', index);
128
+ WishlistCommands.scrollToItem(
129
+ nativeWishlist.current,
130
+ index,
131
+ animated ?? true,
132
+ );
133
+ }
134
+ },
135
+ scrollToTop: () => {
136
+ if (nativeWishlist.current != null) {
137
+ WishlistCommands.scrollToItem(nativeWishlist.current, 0, true);
138
+ }
139
+ },
140
+ }),
141
+ );
142
+
143
+ const { width } = useWindowDimensions();
144
+ useMemo(() => initEventHandler(), []);
145
+
146
+ // Template registration and tracking
147
+ const childrenTemplates = useMemo(
148
+ () => getTemplatesFromChildren(children, width),
149
+ [children, width],
150
+ );
151
+
152
+ if (ListHeaderComponent) {
153
+ childrenTemplates.__wishlistHeader = React.isValidElement(
154
+ ListHeaderComponent,
155
+ ) ? (
156
+ ListHeaderComponent
157
+ ) : (
158
+ <ListHeaderComponent />
159
+ );
160
+ }
161
+
162
+ if (ListFooterComponent) {
163
+ childrenTemplates.__wishlistFooter = React.isValidElement(
164
+ ListFooterComponent,
165
+ ) ? (
166
+ ListFooterComponent
167
+ ) : (
168
+ <ListFooterComponent />
169
+ );
170
+ }
171
+
172
+ const templatesRegistry = useMemo<NestedTemplatesContextValue>(
173
+ () => ({
174
+ templates: {},
175
+ registerTemplate(type, component) {
176
+ if (this.templates[type]) {
177
+ return;
178
+ }
179
+
180
+ this.templates[type] = component;
181
+ },
182
+ }),
183
+ [],
184
+ );
185
+
186
+ const hasHeader = !!ListHeaderComponent;
187
+ const hasFooter = !!ListFooterComponent;
188
+
189
+ // Resolve inflator - either use the provided callback or use the mapping
190
+ const resolvedInflater: InflateMethod = useMemo(() => {
191
+ return (
192
+ index: number,
193
+ pool: ComponentPool,
194
+ previousItem: TemplateItem | null,
195
+ ) => {
196
+ 'worklet';
197
+ const internalData = data as WishlistDataInternal<T>;
198
+
199
+ let value: T | undefined;
200
+ if (hasHeader && index === internalData.__firstIndex() - 1) {
201
+ value = { key: '__wishlistHeader', type: '__wishlistHeader' } as T;
202
+ } else if (hasFooter && index === internalData.__lastIndex()) {
203
+ value = { key: '__wishlistFooter', type: '__wishlistFooter' } as T;
204
+ } else {
205
+ value = internalData.__at(index);
206
+ }
207
+
208
+ if (!value) {
209
+ return undefined;
210
+ }
211
+
212
+ const item =
213
+ previousItem != null &&
214
+ previousItem.type === value.type &&
215
+ previousItem.key === value.key
216
+ ? previousItem
217
+ : pool.getComponent(value.type);
218
+ if (!item) {
219
+ return undefined;
220
+ }
221
+
222
+ if (value.key == null) {
223
+ throw new Error('Every data cell has to contain unique key prop!');
224
+ }
225
+ // We set the key of the item here so that
226
+ // viewportObserver knows what's the key and is able to rerender it later on
227
+ item.key = value.key;
228
+ item.type = value.type;
229
+
230
+ return [item, value];
231
+ };
232
+ }, [data, hasFooter, hasHeader]);
233
+
234
+ const inflatorIdRef = useRef<string | null>(null);
235
+ const prevInflatorRef = useRef<typeof resolvedInflater | undefined>(
236
+ undefined,
237
+ );
238
+
239
+ // Inflator registration and tracking
240
+ const inflatorId = useMemo(() => {
241
+ if (prevInflatorRef.current !== resolvedInflater) {
242
+ // Unregister?
243
+ if (inflatorIdRef.current) {
244
+ InflatorRepository.unregister(inflatorIdRef.current);
245
+ }
246
+ // Register
247
+ inflatorIdRef.current = generateId();
248
+ InflatorRepository.register(inflatorIdRef.current, resolvedInflater);
249
+ }
250
+ return inflatorIdRef.current!;
251
+ }, [resolvedInflater]);
252
+
253
+ useEffect(() => {
254
+ (data as WishlistDataInternal<T>).__attach(wishlistId.current!);
255
+
256
+ return () => {
257
+ (data as WishlistDataInternal<T>).__detach(wishlistId.current!);
258
+ };
259
+ }, [data]);
260
+
261
+ const wishlistContext = useMemo(
262
+ () => ({
263
+ id: wishlistId.current!,
264
+ inflatorId,
265
+ data,
266
+ }),
267
+ [inflatorId, data],
268
+ );
269
+
270
+ return (
271
+ <WishlistContext.Provider value={wishlistContext}>
272
+ <TemplatesRegistryContext.Provider value={templatesRegistry}>
273
+ <>
274
+ {/* Prerender templates to register all the nested templates */}
275
+ <View style={styles.noDisplay}>
276
+ {Object.keys(childrenTemplates).map((c) => (
277
+ <View key={c + 'prerender'}>
278
+ <TemplateContext.Provider
279
+ value={{ templateType: c, renderChildren: true }}
280
+ >
281
+ {childrenTemplates[c]}
282
+ </TemplateContext.Provider>
283
+ </View>
284
+ ))}
285
+ </View>
286
+ <InnerComponent
287
+ inflatorId={inflatorId}
288
+ style={style}
289
+ nativeWishlist={nativeWishlist}
290
+ rest={rest}
291
+ templates={childrenTemplates}
292
+ nestedTemplates={templatesRegistry.templates}
293
+ contentContainerStyle={contentContainerStyle}
294
+ initialIndex={rest.initialIndex ?? (hasHeader ? -1 : 0)}
295
+ />
296
+ </>
297
+ </TemplatesRegistryContext.Provider>
298
+ </WishlistContext.Provider>
299
+ );
300
+ }
301
+
302
+ const Component = React.forwardRef(
303
+ ComponentBase as (
304
+ props: Props & { ref?: Ref<WishListInstance> },
305
+ ) => ReturnType<typeof ComponentBase>,
306
+ );
307
+
308
+ type InnerComponentProps = ViewProps & {
309
+ inflatorId: string;
310
+ nativeWishlist: any;
311
+ rest: any;
312
+ templates: { [key: string]: any };
313
+ nestedTemplates: { [key: string]: any };
314
+ contentContainerStyle?: StyleProp<ViewStyle> | undefined;
315
+ initialIndex: number;
316
+ };
317
+
318
+ function InnerComponent({
319
+ inflatorId,
320
+ style,
321
+ nativeWishlist,
322
+ rest,
323
+ templates,
324
+ nestedTemplates,
325
+ contentContainerStyle,
326
+ initialIndex,
327
+ }: InnerComponentProps) {
328
+ const combinedTemplates: { [key: string]: React.ReactElement<any> } = {
329
+ ...templates,
330
+ ...nestedTemplates,
331
+ };
332
+
333
+ const { id } = useWishlistContext();
334
+
335
+ const keys = Object.keys(combinedTemplates);
336
+ const names = JSON.stringify(keys);
337
+
338
+ return (
339
+ <NativeTemplateInterceptor
340
+ style={style}
341
+ collapsable={false}
342
+ removeClippedSubviews={false}
343
+ >
344
+ <NativeWishList
345
+ style={styles.flex}
346
+ ref={nativeWishlist}
347
+ removeClippedSubviews={false}
348
+ inflatorId={inflatorId}
349
+ onEndReached={rest?.onEndReached}
350
+ onStartReached={rest?.onStartReached}
351
+ initialIndex={initialIndex}
352
+ >
353
+ <NativeContentContainer
354
+ collapsable={false}
355
+ style={contentContainerStyle}
356
+ />
357
+ </NativeWishList>
358
+ <NativeTemplateContainer
359
+ names={names}
360
+ inflatorId={inflatorId}
361
+ wishlistId={id}
362
+ key={Math.random().toString()}
363
+ collapsable={false}
364
+ >
365
+ {Object.keys(combinedTemplates).map((c) => (
366
+ <View key={c}>
367
+ <TemplateContext.Provider value={{ templateType: c }}>
368
+ {combinedTemplates[c]}
369
+ </TemplateContext.Provider>
370
+ </View>
371
+ ))}
372
+ </NativeTemplateContainer>
373
+ </NativeTemplateInterceptor>
374
+ );
375
+ }
376
+
377
+ type TemplateProps = {
378
+ type: string;
379
+ children: React.ReactElement;
380
+ };
381
+
382
+ function Template({ children, type }: TemplateProps) {
383
+ const registry = useContext(TemplatesRegistryContext);
384
+ const templates = useContext(TemplateContext);
385
+
386
+ registry?.registerTemplate(type, children);
387
+
388
+ return templates?.renderChildren ? children : null;
389
+ }
390
+
391
+ Template.displayName = 'WishListTemplate';
392
+
393
+ export const Wishlist = {
394
+ Component,
395
+ Template,
396
+
397
+ Pressable,
398
+ View: WishlistView,
399
+ Image: WishlistImage,
400
+ Text: WishlistText,
401
+
402
+ IF,
403
+ Switch,
404
+ Case,
405
+ /**
406
+ * TODO(Szymon) It's just a prototype we have to think about matching new and old children
407
+ * TODO(Szymon) implement setChildren
408
+ */
409
+ ForEach,
410
+ };
411
+
412
+ const styles = StyleSheet.create({
413
+ flex: { flex: 1 },
414
+ noDisplay: { display: 'none' },
415
+ offsetView: { height: 0 },
416
+ contentContainer: {},
417
+ });
@@ -0,0 +1,15 @@
1
+ import { createContext, useContext } from 'react';
2
+
3
+ export const WishlistContext = createContext<{
4
+ id: string;
5
+ inflatorId: string;
6
+ data: Object;
7
+ } | null>(null);
8
+
9
+ export function useWishlistContext() {
10
+ const context = useContext(WishlistContext);
11
+ if (!context) {
12
+ throw Error('Must be rendered inside a Template component.');
13
+ }
14
+ return context;
15
+ }
@@ -0,0 +1,179 @@
1
+ import { useMemo } from 'react';
2
+ import { scheduleSyncUp } from './OrchestratorBinding';
3
+ import { useGeneratedId } from './Utils';
4
+ import { useWishlistContext } from './WishlistContext';
5
+ import {
6
+ createItemsDataStructure,
7
+ DataCopy,
8
+ Item,
9
+ UpdateJob,
10
+ } from './WishlistDataCopy';
11
+ import { createRunInJsFn, createRunInWishlistFn } from './WishlistJsRuntime';
12
+
13
+ export interface WishlistData<T extends Item> {
14
+ update: <ResT>(job: UpdateJob<T, ResT>) => Promise<ResT>;
15
+ }
16
+
17
+ export interface WishlistDataInternal<T extends Item> extends WishlistData<T> {
18
+ __attach: (wishlistId: string) => void;
19
+ __detach: (wishlistId: string) => void;
20
+ __at: (index: number) => T | undefined;
21
+ __firstIndex: () => number;
22
+ __lastIndex: () => number;
23
+ }
24
+
25
+ /**
26
+ * Creates an instance of Wishlist data which can be passed to Wishlist components.
27
+ */
28
+ export function useWishlistData<T extends Item>(
29
+ getInitialData: () => Array<T>,
30
+ ): WishlistData<T> {
31
+ const dataId = useGeneratedId();
32
+
33
+ // eslint-disable-next-line react-hooks/exhaustive-deps
34
+ const initialData = useMemo(getInitialData, []);
35
+
36
+ const getWishlistData = useMemo((): (() => WishlistDataInternal<T>) => {
37
+ return () => {
38
+ 'worklet';
39
+
40
+ if (!global.dataCtx) {
41
+ global.dataCtx = {};
42
+ }
43
+
44
+ if (global.dataCtx[dataId]) {
45
+ return global.dataCtx[dataId] as WishlistDataInternal<T>;
46
+ }
47
+
48
+ const currentlyRenderedCopy = createItemsDataStructure(initialData);
49
+ const attachedListIds = new Set<string>();
50
+ const pendingUpdates: Array<UpdateJob<T, unknown>> = [];
51
+
52
+ async function update<ResT>(updateJob: UpdateJob<T, ResT>) {
53
+ return new Promise<ResT>((resolve) => {
54
+ pendingUpdates.push((dataCopy: DataCopy<T>) => {
55
+ const result = updateJob(dataCopy);
56
+ resolve(result);
57
+ });
58
+ if (attachedListIds.size > 0) {
59
+ for (const id of attachedListIds) {
60
+ scheduleSyncUp(id);
61
+ }
62
+ } else {
63
+ // If we are not rendering a list yet, just apply changes immediately.
64
+ currentlyRenderedCopy.__applyChanges(pendingUpdates);
65
+ }
66
+ });
67
+ }
68
+
69
+ function __at(index: number) {
70
+ return currentlyRenderedCopy.at(index);
71
+ }
72
+
73
+ function __firstIndex() {
74
+ return 0 - currentlyRenderedCopy.__numberOfNegative;
75
+ }
76
+
77
+ function __lastIndex() {
78
+ return (
79
+ currentlyRenderedCopy.length -
80
+ currentlyRenderedCopy.__numberOfNegative
81
+ );
82
+ }
83
+
84
+ function __attach(wishlistId: string) {
85
+ attachedListIds.add(wishlistId);
86
+
87
+ if (!global.wishlists) {
88
+ global.wishlists = {};
89
+ }
90
+ if (!global.wishlists[wishlistId]) {
91
+ global.wishlists[wishlistId] = {};
92
+ }
93
+ global.wishlists[wishlistId].listener = () => {
94
+ const pendingUpdatesCopy = pendingUpdates.splice(
95
+ 0,
96
+ pendingUpdates.length,
97
+ );
98
+
99
+ return currentlyRenderedCopy.__applyChanges(pendingUpdatesCopy);
100
+ };
101
+ }
102
+
103
+ function __detach(wishlistId: string) {
104
+ global.wishlists[wishlistId].listener = undefined;
105
+ }
106
+
107
+ const internalData: WishlistDataInternal<T> = {
108
+ update,
109
+ __at,
110
+ __attach,
111
+ __detach,
112
+ __firstIndex,
113
+ __lastIndex,
114
+ };
115
+
116
+ global.dataCtx[dataId] = internalData;
117
+
118
+ return internalData;
119
+ };
120
+ // eslint-disable-next-line react-hooks/exhaustive-deps
121
+ }, []);
122
+
123
+ return useMemo(
124
+ (): WishlistDataInternal<T> => ({
125
+ update: <ResT>(updateJob: UpdateJob<T, ResT>) => {
126
+ 'worklet';
127
+
128
+ // This can be called from both JS and Wishlist context.
129
+ // TODO: Better api to check which JS runtime we are on.
130
+ if (global.dataCtx) {
131
+ return getWishlistData().update(updateJob);
132
+ } else {
133
+ return new Promise<ResT>((resolve) => {
134
+ const resolveJs = createRunInJsFn(resolve);
135
+ return createRunInWishlistFn(() => {
136
+ 'worklet';
137
+
138
+ getWishlistData().update(updateJob).then(resolveJs);
139
+ })();
140
+ });
141
+ }
142
+ },
143
+ __at(index: number) {
144
+ 'worklet';
145
+
146
+ return getWishlistData().__at(index);
147
+ },
148
+ __attach: (wishlistId: string) => {
149
+ createRunInWishlistFn(() => {
150
+ 'worklet';
151
+ getWishlistData().__attach(wishlistId);
152
+ })();
153
+ },
154
+ __detach: (wishlistId: string) => {
155
+ createRunInWishlistFn(() => {
156
+ 'worklet';
157
+ getWishlistData().__detach(wishlistId);
158
+ })();
159
+ },
160
+ __firstIndex: () => {
161
+ 'worklet';
162
+ return getWishlistData().__firstIndex();
163
+ },
164
+ __lastIndex: () => {
165
+ 'worklet';
166
+ return getWishlistData().__lastIndex();
167
+ },
168
+ }),
169
+ [getWishlistData],
170
+ );
171
+ }
172
+
173
+ /**
174
+ * Returns the data for the current Wishlist. Must be called inside template components.
175
+ */
176
+ export function useWishlistContextData<T extends Item>() {
177
+ const { data } = useWishlistContext();
178
+ return data as WishlistData<T>;
179
+ }