@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.
- package/LICENSE +20 -0
- package/MGWishList.podspec +40 -0
- package/README.md +281 -0
- package/android/CMakeLists.txt +86 -0
- package/android/build.gradle +72 -0
- package/android/gradle.properties +5 -0
- package/android/spotless.gradle +24 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/wishlist/ContentContainer.kt +22 -0
- package/android/src/main/java/com/wishlist/Orchestrator.kt +38 -0
- package/android/src/main/java/com/wishlist/TemplateContainer.kt +30 -0
- package/android/src/main/java/com/wishlist/TemplateContainerViewManager.kt +65 -0
- package/android/src/main/java/com/wishlist/TemplateInterceptor.kt +29 -0
- package/android/src/main/java/com/wishlist/TemplateInterceptorViewManager.kt +23 -0
- package/android/src/main/java/com/wishlist/UIScheduler.kt +15 -0
- package/android/src/main/java/com/wishlist/Wishlist.kt +135 -0
- package/android/src/main/java/com/wishlist/WishlistManagerModule.kt +51 -0
- package/android/src/main/java/com/wishlist/WishlistPackage.kt +47 -0
- package/android/src/main/java/com/wishlist/WishlistSoLoader.kt +17 -0
- package/android/src/main/java/com/wishlist/WishlistViewManager.kt +69 -0
- package/android/src/main/jni/ErrorHandlerAndroid.cpp +16 -0
- package/android/src/main/jni/ErrorHandlerAndroid.h +13 -0
- package/android/src/main/jni/JNIStateRegistry.cpp +22 -0
- package/android/src/main/jni/JNIStateRegistry.h +23 -0
- package/android/src/main/jni/OnLoad.cpp +12 -0
- package/android/src/main/jni/Orchestrator.cpp +167 -0
- package/android/src/main/jni/Orchestrator.hpp +78 -0
- package/android/src/main/jni/UISchedulerAndroid.cpp +20 -0
- package/android/src/main/jni/UISchedulerAndroid.h +18 -0
- package/android/src/main/jni/WishlistManagerModule.cpp +91 -0
- package/android/src/main/jni/WishlistManagerModule.hpp +43 -0
- package/android/src/main/jni/wishlist.h +19 -0
- package/cpp/ContentContainer/MGContentContainerComponentDescriptor.h +40 -0
- package/cpp/ContentContainer/MGContentContainerShadowNode.cpp +21 -0
- package/cpp/ContentContainer/MGContentContainerShadowNode.h +30 -0
- package/cpp/ContentContainer/MGContentContainerState.cpp +31 -0
- package/cpp/ContentContainer/MGContentContainerState.h +39 -0
- package/cpp/DataBinding/MGBindingProvider.hpp +21 -0
- package/cpp/DataBinding/MGDataBinding.hpp +23 -0
- package/cpp/DataBinding/MGDataBindingImpl.cpp +112 -0
- package/cpp/DataBinding/MGDataBindingImpl.hpp +35 -0
- package/cpp/DependencyInjection/MGDI.hpp +33 -0
- package/cpp/DependencyInjection/MGDIImpl.cpp +65 -0
- package/cpp/DependencyInjection/MGDIImpl.hpp +45 -0
- package/cpp/DependencyInjection/MGUIManagerHolder.cpp +21 -0
- package/cpp/DependencyInjection/MGUIManagerHolder.h +24 -0
- package/cpp/ItemProvider/ComponentsPool.cpp +91 -0
- package/cpp/ItemProvider/ComponentsPool.h +49 -0
- package/cpp/ItemProvider/ItemProvider.cpp +60 -0
- package/cpp/ItemProvider/ItemProvider.h +67 -0
- package/cpp/ItemProvider/ShadowNodeBinding.cpp +356 -0
- package/cpp/ItemProvider/ShadowNodeBinding.h +59 -0
- package/cpp/ItemProvider/ShadowNodeCopyMachine.cpp +95 -0
- package/cpp/ItemProvider/ShadowNodeCopyMachine.h +25 -0
- package/cpp/MGErrorHandler.h +12 -0
- package/cpp/MGViewportCarer/MGVSyncRequester.hpp +18 -0
- package/cpp/MGViewportCarer/MGViewportCarer.hpp +42 -0
- package/cpp/MGViewportCarer/MGViewportCarerImpl.cpp +453 -0
- package/cpp/MGViewportCarer/MGViewportCarerImpl.h +80 -0
- package/cpp/MGViewportCarer/MGViewportCarerListener.hpp +27 -0
- package/cpp/TemplateContainer/MGTemplateContainerComponentDescriptor.h +15 -0
- package/cpp/TemplateContainer/MGTemplateContainerShadowNode.cpp +43 -0
- package/cpp/TemplateContainer/MGTemplateContainerShadowNode.h +42 -0
- package/cpp/TemplateContainer/MGTemplateContainerState.cpp +37 -0
- package/cpp/TemplateContainer/MGTemplateContainerState.h +39 -0
- package/cpp/UIScheduler/MGUIScheduler.cpp +8 -0
- package/cpp/UIScheduler/MGUIScheduler.hpp +18 -0
- package/cpp/Wishlist/MGWishlistComponentDescriptor.h +14 -0
- package/cpp/Wishlist/MGWishlistShadowNode.cpp +49 -0
- package/cpp/Wishlist/MGWishlistShadowNode.h +37 -0
- package/cpp/Wishlist/MGWishlistState.cpp +57 -0
- package/cpp/Wishlist/MGWishlistState.h +42 -0
- package/cpp/WishlistDefine.h +3 -0
- package/cpp/WishlistJsRuntime.cpp +139 -0
- package/cpp/WishlistJsRuntime.h +59 -0
- package/ios/MGContentContainerComponent.h +9 -0
- package/ios/MGContentContainerComponent.mm +34 -0
- package/ios/MGErrorHandlerIOS.h +13 -0
- package/ios/MGErrorHandlerIOS.mm +12 -0
- package/ios/MGObjCJSIUtils.h +63 -0
- package/ios/MGTemplateContainerComponent.h +12 -0
- package/ios/MGTemplateContainerComponent.mm +105 -0
- package/ios/MGTemplateInterceptorComponent.h +9 -0
- package/ios/MGTemplateInterceptorComponent.mm +72 -0
- package/ios/MGWishListComponent.h +17 -0
- package/ios/MGWishListComponent.mm +187 -0
- package/ios/MGWishlistManager.h +21 -0
- package/ios/MGWishlistManager.mm +319 -0
- package/ios/MGWishlistQueue.h +11 -0
- package/ios/MGWishlistQueue.m +34 -0
- package/ios/Orchestrator/MGOrchestrator.h +35 -0
- package/ios/Orchestrator/MGOrchestrator.mm +139 -0
- package/ios/Orchestrator/MGOrchestratorCppAdapter.cpp +25 -0
- package/ios/Orchestrator/MGOrchestratorCppAdapter.hpp +32 -0
- package/ios/UIScheduleriOS/MGUIScheduleriOS.hpp +19 -0
- package/ios/UIScheduleriOS/MGUIScheduleriOS.mm +21 -0
- package/lib/commonjs/Colors.js +399 -0
- package/lib/commonjs/Colors.js.map +1 -0
- package/lib/commonjs/ComponentPool.js +28 -0
- package/lib/commonjs/ComponentPool.js.map +1 -0
- package/lib/commonjs/Components/ForEach.js +21 -0
- package/lib/commonjs/Components/ForEach.js.map +1 -0
- package/lib/commonjs/Components/ForEachBase.js +19 -0
- package/lib/commonjs/Components/ForEachBase.js.map +1 -0
- package/lib/commonjs/Components/IF.js +34 -0
- package/lib/commonjs/Components/IF.js.map +1 -0
- package/lib/commonjs/Components/Pressable.js +73 -0
- package/lib/commonjs/Components/Pressable.js.map +1 -0
- package/lib/commonjs/Components/Switch.js +52 -0
- package/lib/commonjs/Components/Switch.js.map +1 -0
- package/lib/commonjs/Components/WishlistImage.js +29 -0
- package/lib/commonjs/Components/WishlistImage.js.map +1 -0
- package/lib/commonjs/Components/WishlistText.js +24 -0
- package/lib/commonjs/Components/WishlistText.js.map +1 -0
- package/lib/commonjs/Components/WishlistView.js +10 -0
- package/lib/commonjs/Components/WishlistView.js.map +1 -0
- package/lib/commonjs/EventHandler.js +72 -0
- package/lib/commonjs/EventHandler.js.map +1 -0
- package/lib/commonjs/InflatorRepository.js +155 -0
- package/lib/commonjs/InflatorRepository.js.map +1 -0
- package/lib/commonjs/OrchestratorBinding.js +12 -0
- package/lib/commonjs/OrchestratorBinding.js.map +1 -0
- package/lib/commonjs/Specs/NativeContentContainer.js +12 -0
- package/lib/commonjs/Specs/NativeContentContainer.js.map +1 -0
- package/lib/commonjs/Specs/NativeTemplateContainer.js +12 -0
- package/lib/commonjs/Specs/NativeTemplateContainer.js.map +1 -0
- package/lib/commonjs/Specs/NativeTemplateInterceptor.js +10 -0
- package/lib/commonjs/Specs/NativeTemplateInterceptor.js.map +1 -0
- package/lib/commonjs/Specs/NativeWishlist.js +16 -0
- package/lib/commonjs/Specs/NativeWishlist.js.map +1 -0
- package/lib/commonjs/Specs/NativeWishlistManager.js +9 -0
- package/lib/commonjs/Specs/NativeWishlistManager.js.map +1 -0
- package/lib/commonjs/TemplateContext.js +17 -0
- package/lib/commonjs/TemplateContext.js.map +1 -0
- package/lib/commonjs/TemplateItem.js +2 -0
- package/lib/commonjs/TemplateItem.js.map +1 -0
- package/lib/commonjs/TemplateValue.js +68 -0
- package/lib/commonjs/TemplateValue.js.map +1 -0
- package/lib/commonjs/Utils.js +20 -0
- package/lib/commonjs/Utils.js.map +1 -0
- package/lib/commonjs/Wishlist.js +290 -0
- package/lib/commonjs/Wishlist.js.map +1 -0
- package/lib/commonjs/WishlistContext.js +17 -0
- package/lib/commonjs/WishlistContext.js.map +1 -0
- package/lib/commonjs/WishlistData.js +149 -0
- package/lib/commonjs/WishlistData.js.map +1 -0
- package/lib/commonjs/WishlistDataCopy.js +115 -0
- package/lib/commonjs/WishlistDataCopy.js.map +1 -0
- package/lib/commonjs/WishlistJsRuntime.android.js +22 -0
- package/lib/commonjs/WishlistJsRuntime.android.js.map +1 -0
- package/lib/commonjs/WishlistJsRuntime.js +42 -0
- package/lib/commonjs/WishlistJsRuntime.js.map +1 -0
- package/lib/commonjs/createTemplateComponent.js +196 -0
- package/lib/commonjs/createTemplateComponent.js.map +1 -0
- package/lib/commonjs/global.d.js +2 -0
- package/lib/commonjs/global.d.js.map +1 -0
- package/lib/commonjs/index.js +83 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/renderTemplate.js +14 -0
- package/lib/commonjs/renderTemplate.js.map +1 -0
- package/lib/module/Colors.js +395 -0
- package/lib/module/Colors.js.map +1 -0
- package/lib/module/ComponentPool.js +24 -0
- package/lib/module/ComponentPool.js.map +1 -0
- package/lib/module/Components/ForEach.js +17 -0
- package/lib/module/Components/ForEach.js.map +1 -0
- package/lib/module/Components/ForEachBase.js +14 -0
- package/lib/module/Components/ForEachBase.js.map +1 -0
- package/lib/module/Components/IF.js +29 -0
- package/lib/module/Components/IF.js.map +1 -0
- package/lib/module/Components/Pressable.js +68 -0
- package/lib/module/Components/Pressable.js.map +1 -0
- package/lib/module/Components/Switch.js +45 -0
- package/lib/module/Components/Switch.js.map +1 -0
- package/lib/module/Components/WishlistImage.js +25 -0
- package/lib/module/Components/WishlistImage.js.map +1 -0
- package/lib/module/Components/WishlistText.js +20 -0
- package/lib/module/Components/WishlistText.js.map +1 -0
- package/lib/module/Components/WishlistView.js +6 -0
- package/lib/module/Components/WishlistView.js.map +1 -0
- package/lib/module/EventHandler.js +66 -0
- package/lib/module/EventHandler.js.map +1 -0
- package/lib/module/InflatorRepository.js +149 -0
- package/lib/module/InflatorRepository.js.map +1 -0
- package/lib/module/OrchestratorBinding.js +8 -0
- package/lib/module/OrchestratorBinding.js.map +1 -0
- package/lib/module/Specs/NativeContentContainer.js +7 -0
- package/lib/module/Specs/NativeContentContainer.js.map +1 -0
- package/lib/module/Specs/NativeTemplateContainer.js +7 -0
- package/lib/module/Specs/NativeTemplateContainer.js.map +1 -0
- package/lib/module/Specs/NativeTemplateInterceptor.js +5 -0
- package/lib/module/Specs/NativeTemplateInterceptor.js.map +1 -0
- package/lib/module/Specs/NativeWishlist.js +11 -0
- package/lib/module/Specs/NativeWishlist.js.map +1 -0
- package/lib/module/Specs/NativeWishlistManager.js +5 -0
- package/lib/module/Specs/NativeWishlistManager.js.map +1 -0
- package/lib/module/TemplateContext.js +12 -0
- package/lib/module/TemplateContext.js.map +1 -0
- package/lib/module/TemplateItem.js +2 -0
- package/lib/module/TemplateItem.js.map +1 -0
- package/lib/module/TemplateValue.js +63 -0
- package/lib/module/TemplateValue.js.map +1 -0
- package/lib/module/Utils.js +15 -0
- package/lib/module/Utils.js.map +1 -0
- package/lib/module/Wishlist.js +284 -0
- package/lib/module/Wishlist.js.map +1 -0
- package/lib/module/WishlistContext.js +12 -0
- package/lib/module/WishlistContext.js.map +1 -0
- package/lib/module/WishlistData.js +144 -0
- package/lib/module/WishlistData.js.map +1 -0
- package/lib/module/WishlistDataCopy.js +111 -0
- package/lib/module/WishlistDataCopy.js.map +1 -0
- package/lib/module/WishlistJsRuntime.android.js +16 -0
- package/lib/module/WishlistJsRuntime.android.js.map +1 -0
- package/lib/module/WishlistJsRuntime.js +35 -0
- package/lib/module/WishlistJsRuntime.js.map +1 -0
- package/lib/module/createTemplateComponent.js +191 -0
- package/lib/module/createTemplateComponent.js.map +1 -0
- package/lib/module/global.d.js +2 -0
- package/lib/module/global.d.js.map +1 -0
- package/lib/module/index.js +14 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/renderTemplate.js +10 -0
- package/lib/module/renderTemplate.js.map +1 -0
- package/lib/typescript/Colors.d.ts +7 -0
- package/lib/typescript/Colors.d.ts.map +1 -0
- package/lib/typescript/ComponentPool.d.ts +10 -0
- package/lib/typescript/ComponentPool.d.ts.map +1 -0
- package/lib/typescript/Components/ForEach.d.ts +2 -0
- package/lib/typescript/Components/ForEach.d.ts.map +1 -0
- package/lib/typescript/Components/ForEachBase.d.ts +3 -0
- package/lib/typescript/Components/ForEachBase.d.ts.map +1 -0
- package/lib/typescript/Components/IF.d.ts +3 -0
- package/lib/typescript/Components/IF.d.ts.map +1 -0
- package/lib/typescript/Components/Pressable.d.ts +15 -0
- package/lib/typescript/Components/Pressable.d.ts.map +1 -0
- package/lib/typescript/Components/Switch.d.ts +17 -0
- package/lib/typescript/Components/Switch.d.ts.map +1 -0
- package/lib/typescript/Components/WishlistImage.d.ts +3 -0
- package/lib/typescript/Components/WishlistImage.d.ts.map +1 -0
- package/lib/typescript/Components/WishlistText.d.ts +3 -0
- package/lib/typescript/Components/WishlistText.d.ts.map +1 -0
- package/lib/typescript/Components/WishlistView.d.ts +3 -0
- package/lib/typescript/Components/WishlistView.d.ts.map +1 -0
- package/lib/typescript/EventHandler.d.ts +9 -0
- package/lib/typescript/EventHandler.d.ts.map +1 -0
- package/lib/typescript/InflatorRepository.d.ts +28 -0
- package/lib/typescript/InflatorRepository.d.ts.map +1 -0
- package/lib/typescript/OrchestratorBinding.d.ts +13 -0
- package/lib/typescript/OrchestratorBinding.d.ts.map +1 -0
- package/lib/typescript/Specs/NativeContentContainer.d.ts +6 -0
- package/lib/typescript/Specs/NativeContentContainer.d.ts.map +1 -0
- package/lib/typescript/Specs/NativeTemplateContainer.d.ts +9 -0
- package/lib/typescript/Specs/NativeTemplateContainer.d.ts.map +1 -0
- package/lib/typescript/Specs/NativeTemplateInterceptor.d.ts +6 -0
- package/lib/typescript/Specs/NativeTemplateInterceptor.d.ts.map +1 -0
- package/lib/typescript/Specs/NativeWishlist.d.ts +22 -0
- package/lib/typescript/Specs/NativeWishlist.d.ts.map +1 -0
- package/lib/typescript/Specs/NativeWishlistManager.d.ts +7 -0
- package/lib/typescript/Specs/NativeWishlistManager.d.ts.map +1 -0
- package/lib/typescript/TemplateContext.d.ts +9 -0
- package/lib/typescript/TemplateContext.d.ts.map +1 -0
- package/lib/typescript/TemplateItem.d.ts +13 -0
- package/lib/typescript/TemplateItem.d.ts.map +1 -0
- package/lib/typescript/TemplateValue.d.ts +16 -0
- package/lib/typescript/TemplateValue.d.ts.map +1 -0
- package/lib/typescript/Utils.d.ts +3 -0
- package/lib/typescript/Utils.d.ts.map +1 -0
- package/lib/typescript/Wishlist.d.ts +59 -0
- package/lib/typescript/Wishlist.d.ts.map +1 -0
- package/lib/typescript/WishlistContext.d.ts +11 -0
- package/lib/typescript/WishlistContext.d.ts.map +1 -0
- package/lib/typescript/WishlistData.d.ts +20 -0
- package/lib/typescript/WishlistData.d.ts.map +1 -0
- package/lib/typescript/WishlistDataCopy.d.ts +25 -0
- package/lib/typescript/WishlistDataCopy.d.ts.map +1 -0
- package/lib/typescript/WishlistJsRuntime.android.d.ts +4 -0
- package/lib/typescript/WishlistJsRuntime.android.d.ts.map +1 -0
- package/lib/typescript/WishlistJsRuntime.d.ts +6 -0
- package/lib/typescript/WishlistJsRuntime.d.ts.map +1 -0
- package/lib/typescript/createTemplateComponent.d.ts +35 -0
- package/lib/typescript/createTemplateComponent.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +8 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/renderTemplate.d.ts +3 -0
- package/lib/typescript/renderTemplate.d.ts.map +1 -0
- package/package.json +195 -0
- package/src/Colors.ts +474 -0
- package/src/ComponentPool.ts +33 -0
- package/src/Components/ForEach.tsx +22 -0
- package/src/Components/ForEachBase.tsx +8 -0
- package/src/Components/IF.tsx +20 -0
- package/src/Components/Pressable.tsx +111 -0
- package/src/Components/Switch.tsx +49 -0
- package/src/Components/WishlistImage.tsx +25 -0
- package/src/Components/WishlistText.tsx +14 -0
- package/src/Components/WishlistView.tsx +4 -0
- package/src/EventHandler.ts +78 -0
- package/src/InflatorRepository.ts +231 -0
- package/src/OrchestratorBinding.ts +15 -0
- package/src/Specs/NativeContentContainer.ts +9 -0
- package/src/Specs/NativeTemplateContainer.ts +13 -0
- package/src/Specs/NativeTemplateInterceptor.ts +8 -0
- package/src/Specs/NativeWishlist.ts +42 -0
- package/src/Specs/NativeWishlistManager.ts +7 -0
- package/src/TemplateContext.tsx +14 -0
- package/src/TemplateItem.ts +15 -0
- package/src/TemplateValue.tsx +101 -0
- package/src/Utils.ts +15 -0
- package/src/Wishlist.tsx +417 -0
- package/src/WishlistContext.tsx +15 -0
- package/src/WishlistData.ts +179 -0
- package/src/WishlistDataCopy.ts +138 -0
- package/src/WishlistJsRuntime.android.ts +20 -0
- package/src/WishlistJsRuntime.ts +59 -0
- package/src/createTemplateComponent.tsx +263 -0
- package/src/global.d.ts +1 -0
- package/src/index.ts +17 -0
- package/src/renderTemplate.ts +22 -0
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
#include "MGViewportCarerImpl.h"
|
|
2
|
+
|
|
3
|
+
#include "MGContentContainerShadowNode.h"
|
|
4
|
+
#include "MGUIManagerHolder.h"
|
|
5
|
+
#include "MGWishlistShadowNode.h"
|
|
6
|
+
#include "WishlistDefine.h"
|
|
7
|
+
#include "WishlistJsRuntime.h"
|
|
8
|
+
|
|
9
|
+
namespace Wishlist {
|
|
10
|
+
|
|
11
|
+
using namespace facebook::react;
|
|
12
|
+
|
|
13
|
+
MGViewportCarerImpl::MGViewportCarerImpl()
|
|
14
|
+
: contentOffset_(0),
|
|
15
|
+
initialContentSize_(0),
|
|
16
|
+
windowHeight_(0),
|
|
17
|
+
windowWidth_(0),
|
|
18
|
+
surfaceId_(0),
|
|
19
|
+
inflatorId_(""),
|
|
20
|
+
componentsPool_(std::make_shared<ComponentsPool>()),
|
|
21
|
+
itemProvider_(nullptr),
|
|
22
|
+
window_({}),
|
|
23
|
+
wishListNode_(nullptr),
|
|
24
|
+
lc_({}),
|
|
25
|
+
di_({}),
|
|
26
|
+
firstItemKeyForStartReached_(""),
|
|
27
|
+
lastItemKeyForEndReached_(""),
|
|
28
|
+
listener_({}),
|
|
29
|
+
ignoreScrollEvents_(false) {}
|
|
30
|
+
|
|
31
|
+
void MGViewportCarerImpl::setDI(const std::weak_ptr<MGDI> &di) {
|
|
32
|
+
di_ = di;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
void MGViewportCarerImpl::setListener(
|
|
36
|
+
const std::weak_ptr<MGViewportCarerListener> &listener) {
|
|
37
|
+
listener_ = listener;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
void MGViewportCarerImpl::setInitialValues(
|
|
41
|
+
const std::shared_ptr<MGWishlistShadowNode> &wishListNode,
|
|
42
|
+
const LayoutContext &lc) {
|
|
43
|
+
wishListNode_ = wishListNode;
|
|
44
|
+
lc_ = lc;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
void MGViewportCarerImpl::initialRenderAsync(
|
|
48
|
+
MGDims dimensions,
|
|
49
|
+
float initialContentSize,
|
|
50
|
+
int originItem,
|
|
51
|
+
const std::vector<std::shared_ptr<ShadowNode const>> ®isteredViews,
|
|
52
|
+
const std::vector<std::string> &names,
|
|
53
|
+
const std::string &inflatorId) {
|
|
54
|
+
WishlistJsRuntime::getInstance().accessRuntime([=](jsi::Runtime &rt) {
|
|
55
|
+
componentsPool_->setRegisteredViews(registeredViews);
|
|
56
|
+
componentsPool_->setNames(names);
|
|
57
|
+
|
|
58
|
+
itemProvider_ = std::static_pointer_cast<ItemProvider>(
|
|
59
|
+
std::make_shared<WorkletItemProvider>(
|
|
60
|
+
di_, dimensions.width, lc_, inflatorId));
|
|
61
|
+
itemProvider_->setComponentsPool(componentsPool_);
|
|
62
|
+
|
|
63
|
+
surfaceId_ = wishListNode_->getFamily().getSurfaceId();
|
|
64
|
+
initialContentSize_ = initialContentSize;
|
|
65
|
+
contentOffset_ = initialContentSize / 2;
|
|
66
|
+
windowHeight_ = dimensions.height;
|
|
67
|
+
windowWidth_ = dimensions.width;
|
|
68
|
+
inflatorId_ = inflatorId;
|
|
69
|
+
|
|
70
|
+
window_.push_back(itemProvider_->provide(originItem, nullptr));
|
|
71
|
+
window_.back().offset = initialContentSize / 2;
|
|
72
|
+
updateWindow();
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
void MGViewportCarerImpl::didScrollAsync(
|
|
77
|
+
MGDims dimensions,
|
|
78
|
+
float contentOffset,
|
|
79
|
+
const std::string &inflatorId) {
|
|
80
|
+
#if MG_WISHLIST_DEBUG
|
|
81
|
+
static int scrollEventId = 0;
|
|
82
|
+
int currentScrollEventId = scrollEventId++;
|
|
83
|
+
std::cout << "didScrollAsync UI {eventId: " << currentScrollEventId
|
|
84
|
+
<< ", contentOffset: " << contentOffset << "}" << std::endl;
|
|
85
|
+
#endif
|
|
86
|
+
WishlistJsRuntime::getInstance().accessRuntime([=](jsi::Runtime &rt) {
|
|
87
|
+
if (ignoreScrollEvents_) {
|
|
88
|
+
#if MG_WISHLIST_DEBUG
|
|
89
|
+
std::cout << "didScrollAsync BG ignore events skip {eventId: "
|
|
90
|
+
<< currentScrollEventId << ", offset: " << contentOffset << "}"
|
|
91
|
+
<< std::endl;
|
|
92
|
+
#endif
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (dimensions.width != windowWidth_ || inflatorId != inflatorId_) {
|
|
97
|
+
itemProvider_ = std::static_pointer_cast<ItemProvider>(
|
|
98
|
+
std::make_shared<WorkletItemProvider>(
|
|
99
|
+
di_, dimensions.width, lc_, inflatorId));
|
|
100
|
+
itemProvider_->setComponentsPool(componentsPool_);
|
|
101
|
+
windowWidth_ = dimensions.width;
|
|
102
|
+
inflatorId_ = inflatorId;
|
|
103
|
+
} else {
|
|
104
|
+
std::set<int> dirty =
|
|
105
|
+
di_.lock()->getDataBinding()->applyChangesAndGetDirtyIndices(
|
|
106
|
+
{window_[0].index, window_.back().index});
|
|
107
|
+
for (auto &item : window_) {
|
|
108
|
+
if (dirty.count(item.index) > 0) {
|
|
109
|
+
item.dirty = true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// MG_NO_OFFSET means that we keep the current offset.
|
|
115
|
+
if (contentOffset != MG_NO_OFFSET) {
|
|
116
|
+
contentOffset_ = contentOffset;
|
|
117
|
+
}
|
|
118
|
+
windowHeight_ = dimensions.height;
|
|
119
|
+
|
|
120
|
+
#if MG_WISHLIST_DEBUG
|
|
121
|
+
std::cout << "didScrollAsync BG updateWindow {eventId: "
|
|
122
|
+
<< currentScrollEventId << ", contentOffset: " << contentOffset
|
|
123
|
+
<< "}" << std::endl;
|
|
124
|
+
#endif
|
|
125
|
+
updateWindow();
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
void MGViewportCarerImpl::didUpdateContentOffset() {
|
|
130
|
+
WishlistJsRuntime::getInstance().accessRuntime([=](jsi::Runtime &rt) {
|
|
131
|
+
#if MG_WISHLIST_DEBUG
|
|
132
|
+
std::cout << "didUpdateContentOffset BG" << std::endl;
|
|
133
|
+
#endif
|
|
134
|
+
ignoreScrollEvents_ = false;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
void MGViewportCarerImpl::updateWindow() {
|
|
139
|
+
float topEdge = contentOffset_ - windowHeight_;
|
|
140
|
+
float bottomEdge = contentOffset_ + 2 * windowHeight_;
|
|
141
|
+
bool startReached = false;
|
|
142
|
+
bool endReached = false;
|
|
143
|
+
bool changed = false;
|
|
144
|
+
|
|
145
|
+
assert(!window_.empty());
|
|
146
|
+
|
|
147
|
+
#if MG_WISHLIST_DEBUG
|
|
148
|
+
std::cout << "updateWindow {contentOffset: " << contentOffset_
|
|
149
|
+
<< ", topEdge: " << topEdge << ", bottomEdge: " << bottomEdge << "}"
|
|
150
|
+
<< std::endl;
|
|
151
|
+
std::cout << "before:" << std::endl;
|
|
152
|
+
for (auto &item : window_) {
|
|
153
|
+
std::cout << "{key: " << item.key << ", offset: " << item.offset
|
|
154
|
+
<< ", height: " << item.height << "}" << std::endl;
|
|
155
|
+
}
|
|
156
|
+
#endif
|
|
157
|
+
|
|
158
|
+
float currentOffset = window_[0].offset;
|
|
159
|
+
for (auto &item : window_) {
|
|
160
|
+
if (item.dirty) {
|
|
161
|
+
std::shared_ptr<ShadowNodeBinding> prevSn = nullptr;
|
|
162
|
+
if (item.sn) {
|
|
163
|
+
prevSn = std::make_shared<ShadowNodeBinding>(
|
|
164
|
+
item.sn, componentsPool_, item.type, item.key);
|
|
165
|
+
}
|
|
166
|
+
WishItem wishItem = itemProvider_->provide(item.index, prevSn);
|
|
167
|
+
if (wishItem.sn == nullptr) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
swap(item.sn, wishItem.sn);
|
|
171
|
+
item.offset = currentOffset - (wishItem.height - item.height);
|
|
172
|
+
item.height = wishItem.height;
|
|
173
|
+
item.type = wishItem.type;
|
|
174
|
+
item.key = wishItem.key;
|
|
175
|
+
item.dirty = false;
|
|
176
|
+
changed = true;
|
|
177
|
+
}
|
|
178
|
+
currentOffset = item.offset + item.height;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Add above
|
|
182
|
+
while (true) {
|
|
183
|
+
WishItem item = window_.front();
|
|
184
|
+
|
|
185
|
+
if (item.offset > topEdge) {
|
|
186
|
+
WishItem wishItem = itemProvider_->provide(item.index - 1, nullptr);
|
|
187
|
+
if (wishItem.sn == nullptr) {
|
|
188
|
+
startReached = true;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
wishItem.offset = item.offset - wishItem.height;
|
|
192
|
+
window_.push_front(wishItem);
|
|
193
|
+
changed = true;
|
|
194
|
+
} else {
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Add below
|
|
200
|
+
while (true) {
|
|
201
|
+
WishItem item = window_.back();
|
|
202
|
+
float bottom = item.offset + item.height;
|
|
203
|
+
|
|
204
|
+
if (bottom < bottomEdge) {
|
|
205
|
+
WishItem wishItem = itemProvider_->provide(item.index + 1, nullptr);
|
|
206
|
+
if (wishItem.sn == nullptr) {
|
|
207
|
+
endReached = true;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
wishItem.offset = bottom;
|
|
211
|
+
window_.push_back(wishItem);
|
|
212
|
+
changed = true;
|
|
213
|
+
} else {
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
std::vector<WishItem> itemsToRemove;
|
|
219
|
+
|
|
220
|
+
// remove above
|
|
221
|
+
while (true) {
|
|
222
|
+
WishItem item = window_.front();
|
|
223
|
+
float bottom = item.offset + item.height;
|
|
224
|
+
if (bottom <= topEdge) {
|
|
225
|
+
window_.pop_front();
|
|
226
|
+
itemsToRemove.push_back(item);
|
|
227
|
+
changed = true;
|
|
228
|
+
continue;
|
|
229
|
+
} else {
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// remove below
|
|
235
|
+
while (true) {
|
|
236
|
+
WishItem item = window_.back();
|
|
237
|
+
if (item.offset >= bottomEdge) {
|
|
238
|
+
window_.pop_back();
|
|
239
|
+
itemsToRemove.push_back(item);
|
|
240
|
+
changed = true;
|
|
241
|
+
continue;
|
|
242
|
+
} else {
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Bail out early if no changes to the window.
|
|
248
|
+
if (!changed) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// This will be used to adjust scroll position to maintain the visible content
|
|
253
|
+
// position.
|
|
254
|
+
float contentOffsetAdjustment = 0;
|
|
255
|
+
|
|
256
|
+
// Make sure we don't have negative offsets, this can happen when
|
|
257
|
+
// we are at the start of the list.
|
|
258
|
+
if (window_.front().offset < 0) {
|
|
259
|
+
contentOffsetAdjustment -= window_.front().offset;
|
|
260
|
+
float newOffset = 0;
|
|
261
|
+
for (auto &item : window_) {
|
|
262
|
+
item.offset = newOffset;
|
|
263
|
+
newOffset = newOffset + item.height;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// We reach the start of the list and still have extra offset
|
|
268
|
+
// we need to remove it so that the content size is exact and
|
|
269
|
+
// the list stops scrolling correctly.
|
|
270
|
+
if (startReached && window_.front().offset > 0) {
|
|
271
|
+
contentOffsetAdjustment -= window_.front().offset;
|
|
272
|
+
|
|
273
|
+
float newOffset = 0;
|
|
274
|
+
for (auto &item : window_) {
|
|
275
|
+
item.offset = newOffset;
|
|
276
|
+
newOffset = newOffset + item.height;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
// We are no longer at the start of the list and don't have extra offset
|
|
280
|
+
// we need to add it back.
|
|
281
|
+
else if (!startReached && window_.front().offset <= 0) {
|
|
282
|
+
auto newOffset = initialContentSize_ / 2;
|
|
283
|
+
for (auto &item : window_) {
|
|
284
|
+
item.offset += newOffset;
|
|
285
|
+
}
|
|
286
|
+
contentOffsetAdjustment += newOffset;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (contentOffsetAdjustment != 0) {
|
|
290
|
+
contentOffset_ += contentOffsetAdjustment;
|
|
291
|
+
ignoreScrollEvents_ = true;
|
|
292
|
+
#if MG_WISHLIST_DEBUG
|
|
293
|
+
std::cout << "updateWindow adjust content offset {adjustment: "
|
|
294
|
+
<< contentOffsetAdjustment << ", offset: " << contentOffset_
|
|
295
|
+
<< "}" << std::endl;
|
|
296
|
+
#endif
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
pushChildren(contentOffsetAdjustment != 0 ? contentOffset_ : MG_NO_OFFSET);
|
|
300
|
+
|
|
301
|
+
for (auto &item : itemsToRemove) {
|
|
302
|
+
componentsPool_->returnToPool(item.sn);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (startReached) {
|
|
306
|
+
auto firstItemKey = window_.front().key;
|
|
307
|
+
if (firstItemKey != firstItemKeyForStartReached_) {
|
|
308
|
+
notifyAboutStartReached();
|
|
309
|
+
firstItemKeyForStartReached_ = firstItemKey;
|
|
310
|
+
}
|
|
311
|
+
} else {
|
|
312
|
+
firstItemKeyForStartReached_ = "";
|
|
313
|
+
}
|
|
314
|
+
if (endReached) {
|
|
315
|
+
auto lastItemKey = window_.back().key;
|
|
316
|
+
if (lastItemKey != lastItemKeyForEndReached_) {
|
|
317
|
+
notifyAboutEndReached();
|
|
318
|
+
lastItemKeyForEndReached_ = lastItemKey;
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
lastItemKeyForEndReached_ = "";
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
#if MG_WISHLIST_DEBUG
|
|
325
|
+
std::cout << "after:" << std::endl;
|
|
326
|
+
for (auto &item : window_) {
|
|
327
|
+
std::cout << "{key: " << item.key << ", offset: " << item.offset
|
|
328
|
+
<< ", height: " << item.height << "}" << std::endl;
|
|
329
|
+
}
|
|
330
|
+
#endif
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
std::shared_ptr<ShadowNode> MGViewportCarerImpl::getOffseter(float offset) {
|
|
334
|
+
std::shared_ptr<const YogaLayoutableShadowNode> offseterTemplate =
|
|
335
|
+
std::static_pointer_cast<const YogaLayoutableShadowNode>(
|
|
336
|
+
componentsPool_->getNodeForType("__offsetComponent"));
|
|
337
|
+
|
|
338
|
+
auto &cd = offseterTemplate->getComponentDescriptor();
|
|
339
|
+
PropsParserContext propsParserContext{
|
|
340
|
+
surfaceId_, *cd.getContextContainer().get()};
|
|
341
|
+
|
|
342
|
+
// todo remove color
|
|
343
|
+
folly::dynamic props = folly::dynamic::object;
|
|
344
|
+
props["height"] = offset;
|
|
345
|
+
props["width"] = windowWidth_;
|
|
346
|
+
props["backgroundColor"] = 0x00001111;
|
|
347
|
+
|
|
348
|
+
Props::Shared newProps = cd.cloneProps(
|
|
349
|
+
propsParserContext, offseterTemplate->getProps(), RawProps(props));
|
|
350
|
+
|
|
351
|
+
return offseterTemplate->clone({newProps, nullptr, nullptr});
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
void MGViewportCarerImpl::pushChildren(float contentOffset) {
|
|
355
|
+
std::shared_ptr<ShadowNode> sWishList = wishListNode_;
|
|
356
|
+
if (sWishList == nullptr) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
MGUIManagerHolder::getInstance()
|
|
361
|
+
.getUIManager()
|
|
362
|
+
->getShadowTreeRegistry()
|
|
363
|
+
.visit(surfaceId_, [&](const ShadowTree &st) {
|
|
364
|
+
ShadowTreeCommitTransaction transaction =
|
|
365
|
+
[&](RootShadowNode const &oldRootShadowNode)
|
|
366
|
+
-> std::shared_ptr<RootShadowNode> {
|
|
367
|
+
return std::static_pointer_cast<RootShadowNode>(
|
|
368
|
+
oldRootShadowNode.cloneTree(
|
|
369
|
+
sWishList->getFamily(),
|
|
370
|
+
[&](const ShadowNode &sn) -> std::shared_ptr<ShadowNode> {
|
|
371
|
+
auto children =
|
|
372
|
+
std::make_shared<std::vector<std::shared_ptr<const ShadowNode>>>();
|
|
373
|
+
|
|
374
|
+
children->push_back(getOffseter(window_[0].offset));
|
|
375
|
+
|
|
376
|
+
for (WishItem &wishItem : window_) {
|
|
377
|
+
if (wishItem.sn != nullptr) {
|
|
378
|
+
children->push_back(wishItem.sn);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
auto contentContainer = std::static_pointer_cast<
|
|
383
|
+
const MGContentContainerShadowNode>(
|
|
384
|
+
sn.getChildren()[0]);
|
|
385
|
+
|
|
386
|
+
// TODO: This solution seems a little bit hacky still.
|
|
387
|
+
// We need to update most recent state before creating
|
|
388
|
+
// cloning the shadow node as it will be used to initialize
|
|
389
|
+
// children.
|
|
390
|
+
auto stateData =
|
|
391
|
+
std::make_shared<MGContentContainerState>(children);
|
|
392
|
+
auto state = std::make_shared<
|
|
393
|
+
MGContentContainerShadowNode::ConcreteState>(
|
|
394
|
+
stateData, *contentContainer->getState());
|
|
395
|
+
contentContainer->getFamily().setMostRecentState(state);
|
|
396
|
+
|
|
397
|
+
auto newContentContainer =
|
|
398
|
+
std::static_pointer_cast<MGContentContainerShadowNode>(
|
|
399
|
+
contentContainer->clone(
|
|
400
|
+
{nullptr, children, nullptr}));
|
|
401
|
+
|
|
402
|
+
newContentContainer->setWishlistChildren(children);
|
|
403
|
+
|
|
404
|
+
auto wishlistChildren =
|
|
405
|
+
std::make_shared<std::vector<std::shared_ptr<const ShadowNode>>>(
|
|
406
|
+
std::vector<std::shared_ptr<const ShadowNode>>{newContentContainer});
|
|
407
|
+
|
|
408
|
+
auto newWishlistSn =
|
|
409
|
+
std::static_pointer_cast<MGWishlistShadowNode>(
|
|
410
|
+
sn.clone(ShadowNodeFragment{
|
|
411
|
+
nullptr, wishlistChildren, nullptr}));
|
|
412
|
+
|
|
413
|
+
newWishlistSn->updateContentOffset(contentOffset);
|
|
414
|
+
|
|
415
|
+
return newWishlistSn;
|
|
416
|
+
}));
|
|
417
|
+
};
|
|
418
|
+
st.commit(transaction, {});
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
notifyAboutPushedChildren();
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// TODO That could cause a lag we may need to push it through state
|
|
425
|
+
void MGViewportCarerImpl::notifyAboutPushedChildren() {
|
|
426
|
+
auto listener = listener_.lock();
|
|
427
|
+
if (listener != nullptr) {
|
|
428
|
+
std::vector<Item> newWindow;
|
|
429
|
+
for (auto &item : window_) {
|
|
430
|
+
newWindow.push_back({item.offset, item.height, item.index, item.key});
|
|
431
|
+
}
|
|
432
|
+
di_.lock()->getUIScheduler()->scheduleOnUI(
|
|
433
|
+
[newWindow, listener]() { listener->didPushChildren(newWindow); });
|
|
434
|
+
WishlistJsRuntime::getInstance().accessRuntime([=](jsi::Runtime &rt) {
|
|
435
|
+
jsi::Function didPushChildren =
|
|
436
|
+
rt.global()
|
|
437
|
+
.getPropertyAsObject(rt, "global")
|
|
438
|
+
.getPropertyAsObject(rt, "__wishlistInflatorRegistry")
|
|
439
|
+
.getPropertyAsFunction(rt, "didPushChildren");
|
|
440
|
+
didPushChildren.call(rt, 0);
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
void MGViewportCarerImpl::notifyAboutStartReached() {
|
|
446
|
+
wishListNode_->getConcreteEventEmitter().onStartReached({});
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
void MGViewportCarerImpl::notifyAboutEndReached() {
|
|
450
|
+
wishListNode_->getConcreteEventEmitter().onEndReached({});
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
}; // namespace Wishlist
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <react/renderer/uimanager/UIManager.h>
|
|
4
|
+
#include <stdio.h>
|
|
5
|
+
#include <deque>
|
|
6
|
+
#include <iostream>
|
|
7
|
+
#include <set>
|
|
8
|
+
#include "ItemProvider.h"
|
|
9
|
+
#include "MGDI.hpp"
|
|
10
|
+
#include "MGViewportCarer.hpp"
|
|
11
|
+
|
|
12
|
+
namespace facebook::react {
|
|
13
|
+
class MGWishlistShadowNode;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
namespace Wishlist {
|
|
17
|
+
|
|
18
|
+
// TODO make this class testable by injecting componentsPool and itemProvider
|
|
19
|
+
// or their factories
|
|
20
|
+
class MGViewportCarerImpl final : public MGViewportCarer {
|
|
21
|
+
public:
|
|
22
|
+
MGViewportCarerImpl();
|
|
23
|
+
|
|
24
|
+
void setInitialValues(
|
|
25
|
+
const std::shared_ptr<MGWishlistShadowNode> &wishListNode,
|
|
26
|
+
const LayoutContext &lc);
|
|
27
|
+
|
|
28
|
+
void setDI(const std::weak_ptr<MGDI> &_di);
|
|
29
|
+
|
|
30
|
+
void setListener(const std::weak_ptr<MGViewportCarerListener> &listener);
|
|
31
|
+
|
|
32
|
+
void initialRenderAsync(
|
|
33
|
+
MGDims dimensions,
|
|
34
|
+
float initialContentSize,
|
|
35
|
+
int originItem,
|
|
36
|
+
const std::vector<std::shared_ptr<ShadowNode const>> ®isteredViews,
|
|
37
|
+
const std::vector<std::string> &names,
|
|
38
|
+
const std::string &inflatorId) override;
|
|
39
|
+
|
|
40
|
+
void didScrollAsync(
|
|
41
|
+
MGDims dimensions,
|
|
42
|
+
float contentOffset,
|
|
43
|
+
const std::string &inflatorId) override;
|
|
44
|
+
|
|
45
|
+
void didUpdateContentOffset() override;
|
|
46
|
+
|
|
47
|
+
private:
|
|
48
|
+
void updateWindow();
|
|
49
|
+
|
|
50
|
+
void updateContentOffset(float contentOffset);
|
|
51
|
+
|
|
52
|
+
std::shared_ptr<ShadowNode> getOffseter(float offset);
|
|
53
|
+
|
|
54
|
+
void pushChildren(float contentOffset);
|
|
55
|
+
|
|
56
|
+
void notifyAboutPushedChildren();
|
|
57
|
+
|
|
58
|
+
void notifyAboutStartReached();
|
|
59
|
+
|
|
60
|
+
void notifyAboutEndReached();
|
|
61
|
+
|
|
62
|
+
float contentOffset_;
|
|
63
|
+
float initialContentSize_;
|
|
64
|
+
float windowHeight_;
|
|
65
|
+
float windowWidth_;
|
|
66
|
+
int surfaceId_;
|
|
67
|
+
std::string inflatorId_;
|
|
68
|
+
std::shared_ptr<ComponentsPool> componentsPool_;
|
|
69
|
+
std::shared_ptr<ItemProvider> itemProvider_;
|
|
70
|
+
std::deque<WishItem> window_;
|
|
71
|
+
std::shared_ptr<MGWishlistShadowNode> wishListNode_;
|
|
72
|
+
LayoutContext lc_;
|
|
73
|
+
std::weak_ptr<MGDI> di_;
|
|
74
|
+
std::string firstItemKeyForStartReached_;
|
|
75
|
+
std::string lastItemKeyForEndReached_;
|
|
76
|
+
std::weak_ptr<MGViewportCarerListener> listener_;
|
|
77
|
+
bool ignoreScrollEvents_;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
}; // namespace Wishlist
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MGViewportCarerListener.hpp
|
|
3
|
+
// MGWishList
|
|
4
|
+
//
|
|
5
|
+
// Created by Szymon on 13/01/2023.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <stdio.h>
|
|
11
|
+
#include <string>
|
|
12
|
+
#include "MGViewportCarer.hpp"
|
|
13
|
+
|
|
14
|
+
namespace Wishlist {
|
|
15
|
+
|
|
16
|
+
struct Item {
|
|
17
|
+
float offset;
|
|
18
|
+
float height;
|
|
19
|
+
int index;
|
|
20
|
+
std::string key;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
struct MGViewportCarerListener {
|
|
24
|
+
virtual void didPushChildren(std::vector<Item> newWindow) = 0;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
}; // namespace Wishlist
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
4
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
5
|
+
#include <iostream>
|
|
6
|
+
#include "MGTemplateContainerShadowNode.h"
|
|
7
|
+
|
|
8
|
+
namespace facebook {
|
|
9
|
+
namespace react {
|
|
10
|
+
|
|
11
|
+
using MGTemplateContainerComponentDescriptor =
|
|
12
|
+
ConcreteComponentDescriptor<MGTemplateContainerShadowNode>;
|
|
13
|
+
|
|
14
|
+
} // namespace react
|
|
15
|
+
} // namespace facebook
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#include "MGTemplateContainerShadowNode.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 MGTemplateContainerComponentName[] = "MGTemplateContainer";
|
|
10
|
+
|
|
11
|
+
MGTemplateContainerShadowNode::MGTemplateContainerShadowNode(
|
|
12
|
+
ShadowNode const &sourceShadowNode,
|
|
13
|
+
ShadowNodeFragment const &fragment)
|
|
14
|
+
: ConcreteViewShadowNode(sourceShadowNode, fragment) {
|
|
15
|
+
auto &templateContainerSourceShadowNode =
|
|
16
|
+
static_cast<MGTemplateContainerShadowNode const &>(sourceShadowNode);
|
|
17
|
+
templates = templateContainerSourceShadowNode.templates;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
void MGTemplateContainerShadowNode::appendChild(
|
|
21
|
+
std::shared_ptr<ShadowNode const> const &childNode) {
|
|
22
|
+
this->templates.push_back(childNode);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
void MGTemplateContainerShadowNode::layout(LayoutContext layoutContext) {
|
|
26
|
+
updateStateIfNeeded();
|
|
27
|
+
ConcreteViewShadowNode::layout(layoutContext);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
void MGTemplateContainerShadowNode::updateStateIfNeeded() {
|
|
31
|
+
ensureUnsealed();
|
|
32
|
+
|
|
33
|
+
auto const ¤tState = getStateData();
|
|
34
|
+
if (this->templates == currentState.getTemplates()) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
auto state = MGTemplateContainerState{this->templates};
|
|
39
|
+
setStateData(std::move(state));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
} // namespace react
|
|
43
|
+
} // namespace facebook
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
5
|
+
#include <react/renderer/components/wishlist/EventEmitters.h>
|
|
6
|
+
#include <react/renderer/components/wishlist/Props.h>
|
|
7
|
+
#include <react/renderer/core/LayoutContext.h>
|
|
8
|
+
#include "MGTemplateContainerState.h"
|
|
9
|
+
|
|
10
|
+
namespace facebook {
|
|
11
|
+
namespace react {
|
|
12
|
+
|
|
13
|
+
JSI_EXPORT extern const char MGTemplateContainerComponentName[];
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* `ShadowNode` for <MGTemplateContainer> component.
|
|
17
|
+
*/
|
|
18
|
+
class JSI_EXPORT MGTemplateContainerShadowNode final
|
|
19
|
+
: public ConcreteViewShadowNode<
|
|
20
|
+
MGTemplateContainerComponentName,
|
|
21
|
+
MGTemplateContainerProps,
|
|
22
|
+
MGTemplateContainerEventEmitter,
|
|
23
|
+
MGTemplateContainerState> {
|
|
24
|
+
using ConcreteViewShadowNode::ConcreteViewShadowNode;
|
|
25
|
+
|
|
26
|
+
public:
|
|
27
|
+
MGTemplateContainerShadowNode(
|
|
28
|
+
ShadowNode const &sourceShadowNode,
|
|
29
|
+
ShadowNodeFragment const &fragment);
|
|
30
|
+
|
|
31
|
+
std::vector<std::shared_ptr<ShadowNode const>> templates;
|
|
32
|
+
|
|
33
|
+
void appendChild(std::shared_ptr<ShadowNode const> const &childNode) override;
|
|
34
|
+
|
|
35
|
+
void layout(LayoutContext layoutContext) override;
|
|
36
|
+
|
|
37
|
+
private:
|
|
38
|
+
void updateStateIfNeeded();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
} // namespace react
|
|
42
|
+
} // namespace facebook
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#include "MGTemplateContainerState.h"
|
|
2
|
+
|
|
3
|
+
#ifdef ANDROID
|
|
4
|
+
#include "JNIStateRegistry.h"
|
|
5
|
+
#endif
|
|
6
|
+
|
|
7
|
+
namespace facebook::react {
|
|
8
|
+
#ifdef ANDROID
|
|
9
|
+
namespace {
|
|
10
|
+
constexpr MapBuffer::Key TemplatesKey = 1;
|
|
11
|
+
} // namespace
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
const std::vector<std::shared_ptr<ShadowNode const>>
|
|
15
|
+
&MGTemplateContainerState::getTemplates() const {
|
|
16
|
+
return templates_;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
#ifdef ANDROID
|
|
20
|
+
|
|
21
|
+
folly::dynamic MGTemplateContainerState::getDynamic() const {
|
|
22
|
+
auto templatesRef =
|
|
23
|
+
Wishlist::JNIStateRegistry::getInstance().addValue((void *)&templates_);
|
|
24
|
+
return folly::dynamic::object("templates", templatesRef);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
MapBuffer MGTemplateContainerState::getMapBuffer() const {
|
|
28
|
+
auto templatesRef =
|
|
29
|
+
Wishlist::JNIStateRegistry::getInstance().addValue((void *)&templates_);
|
|
30
|
+
MapBufferBuilder builder;
|
|
31
|
+
builder.putInt(TemplatesKey, templatesRef);
|
|
32
|
+
return builder.build();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
} // namespace facebook::react
|