@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,78 @@
1
+ #pragma once
2
+
3
+ #include <fbjni/fbjni.h>
4
+ #include "MGDIImpl.hpp"
5
+
6
+ using namespace facebook;
7
+
8
+ namespace Wishlist {
9
+
10
+ class Orchestrator : public jni::HybridClass<Orchestrator> {
11
+ public:
12
+ Orchestrator(
13
+ jni::alias_ref<Orchestrator::javaobject> jThis,
14
+ const std::string &wishlistId,
15
+ int viewportCarerRef);
16
+
17
+ static constexpr auto kJavaDescriptor = "Lcom/wishlist/Orchestrator;";
18
+
19
+ static void registerNatives();
20
+
21
+ private:
22
+ static jni::local_ref<jhybriddata> initHybrid(
23
+ jni::alias_ref<jhybridobject> jThis,
24
+ std::string wishlistId,
25
+ int viewportCarerRef);
26
+
27
+ void renderAsync(
28
+ float width,
29
+ float height,
30
+ float initialContentSize,
31
+ int originItem,
32
+ int templatesRef,
33
+ jni::alias_ref<jni::JList<jni::JString>> names,
34
+ std::string inflatorId);
35
+
36
+ void didScrollAsync(
37
+ float width,
38
+ float height,
39
+ float contentOffset,
40
+ std::string inflatorId);
41
+
42
+ void handleVSync();
43
+
44
+ void didUpdateContentOffset();
45
+
46
+ void scrollToItem(int index);
47
+
48
+ void didPushChildren(std::vector<Item> items);
49
+
50
+ class Adapter final : public MGViewportCarerListener,
51
+ public MGVSyncRequester {
52
+ public:
53
+ Adapter(
54
+ std::function<void()> onRequestVSync,
55
+ std::function<void(std::vector<Item> items)> didPushChildren);
56
+
57
+ private:
58
+ void didPushChildren(std::vector<Item> newWindow) override;
59
+ void requestVSync() override;
60
+
61
+ std::function<void()> onRequestVSync_;
62
+ std::function<void(std::vector<Item> items)> didPushChildren_;
63
+ };
64
+
65
+ friend HybridBase;
66
+
67
+ jni::global_ref<Orchestrator::javaobject> javaPart_;
68
+ bool alreadyRendered_;
69
+ std::shared_ptr<MGDIImpl> di_;
70
+ std::shared_ptr<Adapter> adapter_;
71
+ float width_;
72
+ float height_;
73
+ std::string inflatorId_;
74
+ std::vector<Item> items_;
75
+ int pendingScrollToItem_;
76
+ };
77
+
78
+ } // namespace Wishlist
@@ -0,0 +1,20 @@
1
+ #include "UISchedulerAndroid.h"
2
+
3
+ #include <fbjni/NativeRunnable.h>
4
+
5
+ namespace Wishlist {
6
+
7
+ using namespace facebook::jni;
8
+
9
+ void UISchedulerAndroid::scheduleOnUI(std::function<void()> &&f) {
10
+ // TODO: Our thread should have access to JVM by default.
11
+ ThreadScope::WithClassLoader([&] {
12
+ static const auto cls = javaClassStatic();
13
+ static const auto method =
14
+ cls->getStaticMethod<void(JRunnable::javaobject)>("scheduleOnUI");
15
+ auto jrunnable = JNativeRunnable::newObjectCxxArgs(std::move(f));
16
+ method(cls, jrunnable.get());
17
+ });
18
+ }
19
+
20
+ }; // namespace Wishlist
@@ -0,0 +1,18 @@
1
+ #pragma once
2
+
3
+ #include <fbjni/fbjni.h>
4
+ #include "MGUIScheduler.hpp"
5
+
6
+ namespace Wishlist {
7
+
8
+ using namespace facebook::jni;
9
+
10
+ class UISchedulerAndroid final : public JavaClass<UISchedulerAndroid>,
11
+ public MGUIScheduler {
12
+ public:
13
+ static auto constexpr kJavaDescriptor = "Lcom/wishlist/UIScheduler;";
14
+
15
+ void scheduleOnUI(std::function<void()> &&f) override;
16
+ };
17
+
18
+ }; // namespace Wishlist
@@ -0,0 +1,91 @@
1
+ #include "WishlistManagerModule.hpp"
2
+
3
+ #include <fbjni/fbjni.h>
4
+ #include <react/fabric/FabricUIManagerBinding.h>
5
+ #include <react/renderer/core/ShadowNodeFamily.h>
6
+ #include "MGUIManagerHolder.h"
7
+ #include "WishlistJsRuntime.h"
8
+
9
+ using namespace facebook;
10
+ using namespace facebook::react;
11
+
12
+ namespace Wishlist {
13
+
14
+ local_ref<WishlistManagerModule::jhybriddata> WishlistManagerModule::initHybrid(
15
+ alias_ref<jclass>) {
16
+ return makeCxxInstance();
17
+ }
18
+
19
+ WishlistManagerModule::WishlistManagerModule() {}
20
+
21
+ WishlistManagerModule::~WishlistManagerModule() {
22
+ scheduler_->removeEventListener(eventListener_);
23
+ }
24
+
25
+ void WishlistManagerModule::nativeInstall(
26
+ jlong jsiRuntimeRef,
27
+ alias_ref<CallInvokerHolder::javaobject> jsCallInvokerHolder,
28
+ alias_ref<JFabricUIManager::javaobject> fabricUIManager) {
29
+ auto jsiRuntime{reinterpret_cast<jsi::Runtime *>(jsiRuntimeRef)};
30
+ auto const &jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker();
31
+ scheduler_ = fabricUIManager->getBinding()->getScheduler();
32
+
33
+ eventListener_ =
34
+ std::make_shared<EventListener>([this](const RawEvent &event) -> bool {
35
+ auto shadowNodeFamily = event.shadowNodeFamily.lock();
36
+ if (shadowNodeFamily == nullptr) {
37
+ return event.eventTarget != nullptr;
38
+ }
39
+
40
+ int tag = shadowNodeFamily->getTag();
41
+ if (tag >= 0) {
42
+ return shadowNodeFamily->getInstanceHandle() == nullptr;
43
+ }
44
+
45
+ auto eventPayload = event.eventPayload;
46
+ std::string type = event.type;
47
+ WishlistJsRuntime::getInstance().accessRuntime(
48
+ [this, type = std::move(type), tag, eventPayload](
49
+ jsi::Runtime &rt) {
50
+ try {
51
+ auto handleEvent =
52
+ rt.global()
53
+ .getPropertyAsObject(rt, "global")
54
+ .getPropertyAsFunction(rt, "handleEvent");
55
+ jsi::Value payload = eventPayload
56
+ ? eventPayload->asJSIValue(rt)
57
+ : jsi::Value::null();
58
+ handleEvent.call(rt, type, tag, payload);
59
+ } catch (std::exception &error) {
60
+ if (errorHandler_) {
61
+ errorHandler_->reportError(error.what());
62
+ }
63
+ }
64
+ });
65
+
66
+ return true;
67
+ });
68
+ scheduler_->addEventListener(eventListener_);
69
+
70
+ wishlistQueue_ = std::make_shared<WishlistDispatchQueue>();
71
+
72
+ WishlistJsRuntime::getInstance().initialize(
73
+ jsiRuntime,
74
+ [=](std::function<void()> &&f) {
75
+ jsCallInvoker->invokeAsync(std::move(f));
76
+ },
77
+ [=](std::function<void()> &&f) {
78
+ wishlistQueue_->dispatch(std::move(f));
79
+ });
80
+
81
+ MGUIManagerHolder::getInstance().setUIManager(scheduler_->getUIManager());
82
+ }
83
+
84
+ void WishlistManagerModule::registerNatives() {
85
+ registerHybrid(
86
+ {makeNativeMethod("initHybrid", WishlistManagerModule::initHybrid),
87
+ makeNativeMethod(
88
+ "nativeInstall", WishlistManagerModule::nativeInstall)});
89
+ }
90
+
91
+ } // namespace Wishlist
@@ -0,0 +1,43 @@
1
+ #pragma once
2
+
3
+ #include <ReactCommon/CallInvokerHolder.h>
4
+ #include <fbjni/fbjni.h>
5
+ #include <react/fabric/JFabricUIManager.h>
6
+ #include <react/renderer/core/EventListener.h>
7
+ #include <react/renderer/scheduler/Scheduler.h>
8
+ #include "ErrorHandlerAndroid.h"
9
+ #include "WishlistJsRuntime.h"
10
+
11
+ using namespace facebook::react;
12
+ using namespace facebook::jni;
13
+
14
+ namespace Wishlist {
15
+
16
+ class WishlistManagerModule : public HybridClass<WishlistManagerModule> {
17
+ public:
18
+ WishlistManagerModule();
19
+ ~WishlistManagerModule();
20
+
21
+ static constexpr auto kJavaDescriptor =
22
+ "Lcom/wishlist/WishlistManagerModule;";
23
+
24
+ static void registerNatives();
25
+
26
+ private:
27
+ static local_ref<jhybriddata> initHybrid(alias_ref<jclass>);
28
+
29
+ void nativeInstall(
30
+ jlong jsiRuntimeRef,
31
+ alias_ref<CallInvokerHolder::javaobject> jsCallInvokerHolder,
32
+ alias_ref<JFabricUIManager::javaobject> fabricUIManager);
33
+
34
+ private:
35
+ friend HybridBase;
36
+
37
+ std::shared_ptr<WishlistDispatchQueue> wishlistQueue_;
38
+ std::shared_ptr<Scheduler> scheduler_;
39
+ std::shared_ptr<EventListener> eventListener_;
40
+ std::shared_ptr<ErrorHandlerAndroid> errorHandler_;
41
+ };
42
+
43
+ } // namespace Wishlist
@@ -0,0 +1,19 @@
1
+ #pragma once
2
+
3
+ #include <ReactCommon/JavaTurboModule.h>
4
+ #include <ReactCommon/TurboModule.h>
5
+ #include <jsi/jsi.h>
6
+ #include "MGContentContainerComponentDescriptor.h"
7
+ #include "MGTemplateContainerComponentDescriptor.h"
8
+ #include "MGWishlistComponentDescriptor.h"
9
+
10
+ namespace facebook {
11
+ namespace react {
12
+
13
+ JSI_EXPORT
14
+ std::shared_ptr<TurboModule> wishlist_ModuleProvider(
15
+ const std::string &moduleName,
16
+ const JavaTurboModule::InitParams &params);
17
+
18
+ } // namespace react
19
+ } // namespace facebook
@@ -0,0 +1,40 @@
1
+ #pragma once
2
+
3
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
4
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
5
+ #include <iostream>
6
+ #include "MGContentContainerShadowNode.h"
7
+
8
+ namespace facebook {
9
+ namespace react {
10
+
11
+ class MGContentContainerComponentDescriptor
12
+ : public ConcreteComponentDescriptor<MGContentContainerShadowNode> {
13
+ using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
14
+
15
+ std::shared_ptr<ShadowNode> cloneShadowNode(
16
+ const ShadowNode &sourceShadowNode,
17
+ const ShadowNodeFragment &fragment) const override {
18
+ // React holds on to old shadow nodes so we need to make sure to get the
19
+ // latest state when cloning those to get the children that were set by
20
+ // Wishlist.
21
+ auto &mostRecentStateData = static_cast<ConcreteState const *>(
22
+ sourceShadowNode.getMostRecentState().get())
23
+ ->getData();
24
+ auto wishlistChildren = mostRecentStateData.wishlistChildren;
25
+ auto children =
26
+ wishlistChildren
27
+ ? std::make_shared<std::vector<std::shared_ptr<const ShadowNode>>>(
28
+ *wishlistChildren)
29
+ : fragment.children;
30
+ auto shadowNode = std::make_shared<MGContentContainerShadowNode>(
31
+ sourceShadowNode,
32
+ ShadowNodeFragment{fragment.props, children, fragment.state});
33
+
34
+ adopt(*shadowNode);
35
+ return shadowNode;
36
+ }
37
+ };
38
+
39
+ } // namespace react
40
+ } // namespace facebook
@@ -0,0 +1,21 @@
1
+ #include "MGContentContainerShadowNode.h"
2
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
3
+ #include <react/renderer/components/wishlist/Props.h>
4
+ #include <react/renderer/core/ComponentDescriptor.h>
5
+
6
+ namespace facebook {
7
+ namespace react {
8
+
9
+ extern const char MGContentContainerComponentName[] = "MGContentContainer";
10
+
11
+ void MGContentContainerShadowNode::setWishlistChildren(
12
+ const std::shared_ptr<WishlistChildrenList> &wishlistChildren) {
13
+ auto state = getStateData();
14
+ if (state.wishlistChildren != wishlistChildren) {
15
+ state.wishlistChildren = wishlistChildren;
16
+ setStateData(std::move(state));
17
+ }
18
+ }
19
+
20
+ } // namespace react
21
+ } // namespace facebook
@@ -0,0 +1,30 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
5
+ #include <react/renderer/components/wishlist/Props.h>
6
+ #include "MGContentContainerState.h"
7
+
8
+ namespace facebook {
9
+ namespace react {
10
+
11
+ JSI_EXPORT extern const char MGContentContainerComponentName[];
12
+
13
+ /*
14
+ * `ShadowNode` for <MGContentContainer> component.
15
+ */
16
+ class JSI_EXPORT MGContentContainerShadowNode final
17
+ : public ConcreteViewShadowNode<
18
+ MGContentContainerComponentName,
19
+ MGContentContainerProps,
20
+ ViewEventEmitter,
21
+ MGContentContainerState> {
22
+ using ConcreteViewShadowNode::ConcreteViewShadowNode;
23
+
24
+ public:
25
+ void setWishlistChildren(
26
+ const std::shared_ptr<WishlistChildrenList> &wishlistChildren);
27
+ };
28
+
29
+ } // namespace react
30
+ } // namespace facebook
@@ -0,0 +1,31 @@
1
+ #include "MGContentContainerState.h"
2
+
3
+ namespace facebook {
4
+ namespace react {
5
+
6
+ MGContentContainerState::MGContentContainerState()
7
+ : wishlistChildren(nullptr) {}
8
+
9
+ MGContentContainerState::MGContentContainerState(
10
+ const std::shared_ptr<WishlistChildrenList> &wishlistChildren)
11
+ : wishlistChildren(wishlistChildren) {}
12
+
13
+ #ifdef ANDROID
14
+
15
+ MGContentContainerState::MGContentContainerState(
16
+ MGContentContainerState const &previousState,
17
+ folly::dynamic /*data*/)
18
+ : wishlistChildren(previousState.wishlistChildren) {}
19
+
20
+ folly::dynamic MGContentContainerState::getDynamic() const {
21
+ return folly::dynamic::object;
22
+ }
23
+
24
+ MapBuffer MGContentContainerState::getMapBuffer() const {
25
+ return MapBufferBuilder::EMPTY();
26
+ }
27
+
28
+ #endif
29
+
30
+ } // namespace react
31
+ } // namespace facebook
@@ -0,0 +1,39 @@
1
+ #pragma once
2
+
3
+ #include <react/renderer/components/view/ConcreteViewShadowNode.h>
4
+ #include <memory>
5
+ #include <vector>
6
+
7
+ #ifdef ANDROID
8
+ #include <folly/dynamic.h>
9
+ #include <react/renderer/mapbuffer/MapBuffer.h>
10
+ #include <react/renderer/mapbuffer/MapBufferBuilder.h>
11
+ #endif
12
+
13
+ namespace facebook {
14
+ namespace react {
15
+
16
+ using WishlistChildrenList = std::vector<std::shared_ptr<const ShadowNode>>;
17
+
18
+ /*
19
+ * State for <MGContentContainer> component.
20
+ */
21
+ class JSI_EXPORT MGContentContainerState final {
22
+ public:
23
+ std::shared_ptr<WishlistChildrenList> wishlistChildren;
24
+
25
+ MGContentContainerState();
26
+ MGContentContainerState(
27
+ const std::shared_ptr<WishlistChildrenList> &wishlistChildren);
28
+
29
+ #ifdef ANDROID
30
+ MGContentContainerState(
31
+ MGContentContainerState const &previousState,
32
+ folly::dynamic data);
33
+ folly::dynamic getDynamic() const;
34
+ MapBuffer getMapBuffer() const;
35
+ #endif
36
+ };
37
+
38
+ } // namespace react
39
+ } // namespace facebook
@@ -0,0 +1,21 @@
1
+ //
2
+ // MGBindingProvider.hpp
3
+ // MGWishList
4
+ //
5
+ // Created by Szymon on 13/01/2023.
6
+ //
7
+
8
+ #pragma once
9
+
10
+ #include <jsi/jsi.h>
11
+ #include <stdio.h>
12
+
13
+ namespace Wishlist {
14
+
15
+ using namespace facebook;
16
+
17
+ struct MGBindingProvider {
18
+ virtual jsi::Value getBinding(jsi::Runtime &rt) = 0;
19
+ };
20
+
21
+ }; // namespace Wishlist
@@ -0,0 +1,23 @@
1
+ //
2
+ // MGDataBinding.hpp
3
+ // MGWishList
4
+ //
5
+ // Created by Szymon on 13/01/2023.
6
+ //
7
+
8
+ #pragma once
9
+
10
+ #include <stdio.h>
11
+ #include <memory>
12
+ #include <set>
13
+ #include <string>
14
+
15
+ namespace Wishlist {
16
+
17
+ struct MGDataBinding {
18
+ virtual std::set<int> applyChangesAndGetDirtyIndices(
19
+ std::pair<int, int> windowIndexRange) = 0;
20
+ virtual ~MGDataBinding() {}
21
+ };
22
+
23
+ }; // namespace Wishlist
@@ -0,0 +1,112 @@
1
+ //
2
+ // MGDataBindingImpl.cpp
3
+ // MGWishList
4
+ //
5
+ // Created by Szymon on 16/01/2023.
6
+ //
7
+
8
+ #include "MGDataBindingImpl.hpp"
9
+ #include "WishlistJsRuntime.h"
10
+
11
+ namespace Wishlist {
12
+
13
+ using namespace facebook;
14
+
15
+ MGDataBindingImpl::MGDataBindingImpl(
16
+ const std::string &wishlistId,
17
+ const std::weak_ptr<MGDI> &di)
18
+ : di(di), _wishlistId(wishlistId) {
19
+ registerBindings();
20
+ }
21
+
22
+ std::set<int> MGDataBindingImpl::applyChangesAndGetDirtyIndices(
23
+ std::pair<int, int> windowIndexRange) {
24
+ std::shared_ptr retainedDI = di.lock();
25
+ if (retainedDI == nullptr) {
26
+ return {};
27
+ }
28
+
29
+ auto &rt = WishlistJsRuntime::getInstance().getRuntime();
30
+ jsi::Object global = rt.global().getPropertyAsObject(rt, "global");
31
+ if (!global.hasProperty(rt, "wishlists")) {
32
+ global.setProperty(rt, "wishlists", jsi::Object(rt));
33
+ }
34
+
35
+ jsi::Object wishlists = global.getPropertyAsObject(rt, "wishlists");
36
+ jsi::Object obj = wishlists.getPropertyAsObject(rt, _wishlistId.c_str());
37
+ jsi::Value val = obj.getProperty(rt, "listener");
38
+ if (val.isObject()) {
39
+ jsi::Function f = val.getObject(rt).getFunction(rt);
40
+ try {
41
+ jsi::Array dirtyIndices = f.call(
42
+ rt,
43
+ jsi::Value(rt, windowIndexRange.first),
44
+ jsi::Value(rt, windowIndexRange.second))
45
+ .asObject(rt)
46
+ .asArray(rt);
47
+ std::set<int> res;
48
+ for (int i = 0; i < dirtyIndices.size(rt); ++i) {
49
+ int dirtyIndex = (int)dirtyIndices.getValueAtIndex(rt, i).asNumber();
50
+ res.insert(dirtyIndex);
51
+ }
52
+ return res;
53
+ } catch (std::exception &error) {
54
+ di.lock()->getErrorHandler()->reportError(error.what());
55
+ return {};
56
+ }
57
+ }
58
+ return {};
59
+ }
60
+
61
+ void MGDataBindingImpl::registerBindings() {
62
+ WishlistJsRuntime::getInstance().accessRuntime([=](jsi::Runtime &rt) {
63
+ jsi::Object global = rt.global().getPropertyAsObject(rt, "global");
64
+ if (!global.hasProperty(rt, "wishlists")) {
65
+ global.setProperty(rt, "wishlists", jsi::Object(rt));
66
+ }
67
+
68
+ jsi::Object wishlists = global.getPropertyAsObject(rt, "wishlists");
69
+
70
+ jsi::Object binding(rt);
71
+ if (wishlists.getProperty(rt, _wishlistId.c_str()).isObject()) {
72
+ binding = wishlists.getProperty(rt, _wishlistId.c_str()).asObject(rt);
73
+ }
74
+ std::weak_ptr<MGDI> weakDi = di;
75
+ binding.setProperty(
76
+ rt,
77
+ "scheduleSyncUp",
78
+ jsi::Function::createFromHostFunction(
79
+ rt,
80
+ jsi::PropNameID::forAscii(rt, "scheduleSyncUp"),
81
+ 1,
82
+ [=](jsi::Runtime &rt,
83
+ const jsi::Value &thisValue,
84
+ const jsi::Value *args,
85
+ size_t count) -> jsi::Value {
86
+ std::shared_ptr<MGDI> retainedDI = weakDi.lock();
87
+ if (retainedDI == nullptr) {
88
+ return jsi::Value::undefined();
89
+ }
90
+ std::shared_ptr<MGVSyncRequester> vsr =
91
+ retainedDI->getVSyncRequester();
92
+ vsr->requestVSync();
93
+ return jsi::Value::undefined();
94
+ }));
95
+
96
+ wishlists.setProperty(rt, _wishlistId.c_str(), binding);
97
+ });
98
+ }
99
+
100
+ void MGDataBindingImpl::unregisterBindings() {
101
+ WishlistJsRuntime::getInstance().accessRuntime([=](jsi::Runtime &rt) {
102
+ jsi::Object global = rt.global().getPropertyAsObject(rt, "global");
103
+ jsi::Object wishlists = global.getPropertyAsObject(rt, "wishlists");
104
+ wishlists.setProperty(rt, _wishlistId.c_str(), jsi::Value::undefined());
105
+ });
106
+ }
107
+
108
+ MGDataBindingImpl::~MGDataBindingImpl() {
109
+ unregisterBindings();
110
+ }
111
+
112
+ }; // namespace Wishlist
@@ -0,0 +1,35 @@
1
+ //
2
+ // MGDataBindingImpl.hpp
3
+ // MGWishList
4
+ //
5
+ // Created by Szymon on 16/01/2023.
6
+ //
7
+
8
+ #pragma once
9
+
10
+ #include <stdio.h>
11
+ #include <memory>
12
+ #include <set>
13
+ #include "MGDI.hpp"
14
+ #include "MGDataBinding.hpp"
15
+
16
+ namespace Wishlist {
17
+
18
+ struct MGDataBindingImpl : MGDataBinding {
19
+ std::weak_ptr<MGDI> di;
20
+ std::string _wishlistId;
21
+
22
+ MGDataBindingImpl(
23
+ const std::string &wishlistId,
24
+ const std::weak_ptr<MGDI> &di);
25
+
26
+ virtual std::set<int> applyChangesAndGetDirtyIndices(
27
+ std::pair<int, int> windowIndexRange);
28
+
29
+ void registerBindings();
30
+ void unregisterBindings();
31
+
32
+ virtual ~MGDataBindingImpl();
33
+ };
34
+
35
+ }; // namespace Wishlist
@@ -0,0 +1,33 @@
1
+ //
2
+ // MGDI.hpp
3
+ // MGWishList
4
+ //
5
+ // Created by Szymon on 13/01/2023.
6
+ //
7
+
8
+ #pragma once
9
+
10
+ #include <react/renderer/uimanager/UIManager.h>
11
+ #include <stdio.h>
12
+
13
+ #include "MGBindingProvider.hpp"
14
+ #include "MGDataBinding.hpp"
15
+ #include "MGErrorHandler.h"
16
+ #include "MGUIScheduler.hpp"
17
+ #include "MGVSyncRequester.hpp"
18
+ #include "MGViewportCarer.hpp"
19
+ #include "MGViewportCarerListener.hpp"
20
+
21
+ namespace Wishlist {
22
+
23
+ struct MGDI {
24
+ virtual std::shared_ptr<MGDataBinding> getDataBinding() = 0;
25
+ virtual std::shared_ptr<MGVSyncRequester> getVSyncRequester() = 0;
26
+ virtual std::shared_ptr<MGViewportCarer> getViewportCarer() = 0;
27
+ virtual std::shared_ptr<MGUIScheduler> getUIScheduler() = 0;
28
+ virtual std::shared_ptr<MGErrorHandler> getErrorHandler() = 0;
29
+
30
+ virtual ~MGDI() {}
31
+ };
32
+
33
+ }; // namespace Wishlist