@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,29 @@
|
|
|
1
|
+
package com.wishlist
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.view.View
|
|
5
|
+
import android.view.ViewGroup
|
|
6
|
+
import com.facebook.react.views.view.ReactViewGroup
|
|
7
|
+
|
|
8
|
+
class TemplateInterceptor(reactContext: Context) :
|
|
9
|
+
ReactViewGroup(reactContext), ViewGroup.OnHierarchyChangeListener {
|
|
10
|
+
private var wishlist: Wishlist? = null
|
|
11
|
+
|
|
12
|
+
init {
|
|
13
|
+
setOnHierarchyChangeListener(this)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
override fun onChildViewAdded(parent: View, child: View) {
|
|
17
|
+
if (child is Wishlist) {
|
|
18
|
+
wishlist = child
|
|
19
|
+
} else if (child is TemplateContainer && wishlist != null) {
|
|
20
|
+
child.wishlist = wishlist
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
override fun onChildViewRemoved(parent: View, child: View) {
|
|
25
|
+
if (child is Wishlist) {
|
|
26
|
+
wishlist = null
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package com.wishlist
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
4
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
5
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
6
|
+
import com.facebook.react.viewmanagers.MGTemplateInterceptorManagerDelegate
|
|
7
|
+
import com.facebook.react.viewmanagers.MGTemplateInterceptorManagerInterface
|
|
8
|
+
|
|
9
|
+
@ReactModule(name = TemplateInterceptorViewManager.REACT_CLASS)
|
|
10
|
+
class TemplateInterceptorViewManager :
|
|
11
|
+
ViewGroupManager<TemplateInterceptor>(),
|
|
12
|
+
MGTemplateInterceptorManagerInterface<TemplateInterceptor> {
|
|
13
|
+
companion object {
|
|
14
|
+
const val REACT_CLASS = "MGTemplateInterceptor"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
override fun getName() = REACT_CLASS
|
|
18
|
+
|
|
19
|
+
override fun createViewInstance(reactContext: ThemedReactContext) =
|
|
20
|
+
TemplateInterceptor(reactContext)
|
|
21
|
+
|
|
22
|
+
override fun getDelegate() = MGTemplateInterceptorManagerDelegate(this)
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
package com.wishlist
|
|
2
|
+
|
|
3
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
4
|
+
import com.facebook.react.bridge.UiThreadUtil
|
|
5
|
+
|
|
6
|
+
@DoNotStrip
|
|
7
|
+
class UIScheduler {
|
|
8
|
+
companion object {
|
|
9
|
+
@DoNotStrip
|
|
10
|
+
@JvmStatic
|
|
11
|
+
fun scheduleOnUI(runnable: Runnable) {
|
|
12
|
+
UiThreadUtil.runOnUiThread(runnable)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
package com.wishlist
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.view.View
|
|
5
|
+
import com.facebook.react.uimanager.PixelUtil
|
|
6
|
+
import com.facebook.react.views.scroll.ReactScrollView
|
|
7
|
+
|
|
8
|
+
private const val VIEWPORT_CARER_KEY = 1
|
|
9
|
+
private const val CONTENT_OFFSET_KEY = 2
|
|
10
|
+
|
|
11
|
+
class Wishlist(reactContext: Context) : ReactScrollView(reactContext) {
|
|
12
|
+
var inflatorId: String? = null
|
|
13
|
+
var wishlistId: String? = null
|
|
14
|
+
var initialIndex: Int = 0
|
|
15
|
+
private var orchestrator: Orchestrator? = null
|
|
16
|
+
private var templatesRef: Int? = null
|
|
17
|
+
private var names: List<String>? = null
|
|
18
|
+
private var didInitialScroll = false
|
|
19
|
+
private val initialContentSize = 100000f
|
|
20
|
+
private var pendingScrollOffset = Int.MIN_VALUE
|
|
21
|
+
private var ignoreScrollEvents = false
|
|
22
|
+
|
|
23
|
+
init {
|
|
24
|
+
clipChildren = true
|
|
25
|
+
clipToPadding = true
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
fun setTemplates(templatesRef: Int, names: List<String>) {
|
|
29
|
+
this.templatesRef = templatesRef
|
|
30
|
+
this.names = names
|
|
31
|
+
renderIfReady()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private fun renderIfReady() {
|
|
35
|
+
val templatesRef = this.templatesRef
|
|
36
|
+
val inflatorId = this.inflatorId
|
|
37
|
+
val names = this.names
|
|
38
|
+
if (names == null || templatesRef == null || inflatorId == null || width == 0 || height == 0) {
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var orchestrator = this.orchestrator
|
|
43
|
+
if (orchestrator == null) {
|
|
44
|
+
val viewportCarer = stateWrapper?.stateDataMapBuffer?.getInt(VIEWPORT_CARER_KEY) ?: return
|
|
45
|
+
orchestrator = Orchestrator(this, wishlistId!!, viewportCarer)
|
|
46
|
+
this.orchestrator = orchestrator
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
orchestrator.renderAsync(
|
|
50
|
+
PixelUtil.toDIPFromPixel(width.toFloat()),
|
|
51
|
+
PixelUtil.toDIPFromPixel(height.toFloat()),
|
|
52
|
+
initialContentSize,
|
|
53
|
+
initialIndex,
|
|
54
|
+
templatesRef,
|
|
55
|
+
names,
|
|
56
|
+
inflatorId)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private fun initialScrollIfReady() {
|
|
60
|
+
if (didInitialScroll) {
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
val contentView = getChildAt(0)
|
|
64
|
+
if (contentView == null || contentView.height == 0) {
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
scrollTo(0, PixelUtil.toPixelFromDIP(initialContentSize / 2).toInt())
|
|
68
|
+
didInitialScroll = true
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
override fun onLayoutChange(
|
|
72
|
+
v: View,
|
|
73
|
+
left: Int,
|
|
74
|
+
top: Int,
|
|
75
|
+
right: Int,
|
|
76
|
+
bottom: Int,
|
|
77
|
+
oldLeft: Int,
|
|
78
|
+
oldTop: Int,
|
|
79
|
+
oldRight: Int,
|
|
80
|
+
oldBottom: Int
|
|
81
|
+
) {
|
|
82
|
+
super.onLayoutChange(v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom)
|
|
83
|
+
initialScrollIfReady()
|
|
84
|
+
maybeScrollToOffsetForContentChange()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
|
|
88
|
+
super.onLayout(changed, l, t, r, b)
|
|
89
|
+
|
|
90
|
+
renderIfReady()
|
|
91
|
+
initialScrollIfReady()
|
|
92
|
+
maybeScrollToOffsetForContentChange()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
override fun onScrollChanged(x: Int, y: Int, oldX: Int, oldY: Int) {
|
|
96
|
+
super.onScrollChanged(x, y, oldX, oldY)
|
|
97
|
+
|
|
98
|
+
if (ignoreScrollEvents) {
|
|
99
|
+
return
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
orchestrator?.didScrollAsync(
|
|
103
|
+
PixelUtil.toDIPFromPixel(width.toFloat()),
|
|
104
|
+
PixelUtil.toDIPFromPixel(height.toFloat()),
|
|
105
|
+
PixelUtil.toDIPFromPixel(y.toFloat()),
|
|
106
|
+
inflatorId!!)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
fun scrollToItem(index: Int, animated: Boolean) {
|
|
110
|
+
orchestrator?.scrollToItem(index)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
fun scrollToOffsetForContentChange(offset: Float) {
|
|
114
|
+
// State is updated before content view is laid out so update the
|
|
115
|
+
// scroll position in layout handler.
|
|
116
|
+
pendingScrollOffset = PixelUtil.toPixelFromDIP(offset).toInt()
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private fun maybeScrollToOffsetForContentChange() {
|
|
120
|
+
if (pendingScrollOffset == Int.MIN_VALUE) {
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
val contentView = getChildAt(0)
|
|
124
|
+
if (contentView == null ||
|
|
125
|
+
contentView.height == 0 ||
|
|
126
|
+
pendingScrollOffset > contentView.height) {
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
ignoreScrollEvents = true
|
|
130
|
+
scrollTo(0, pendingScrollOffset)
|
|
131
|
+
orchestrator?.didUpdateContentOffset()
|
|
132
|
+
ignoreScrollEvents = false
|
|
133
|
+
pendingScrollOffset = Int.MIN_VALUE
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
package com.wishlist
|
|
2
|
+
|
|
3
|
+
import com.facebook.jni.HybridData
|
|
4
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.common.annotations.FrameworkAPI
|
|
7
|
+
import com.facebook.react.fabric.FabricUIManager
|
|
8
|
+
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl
|
|
9
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
10
|
+
import com.facebook.react.uimanager.UIManagerHelper
|
|
11
|
+
import com.facebook.react.uimanager.common.UIManagerType
|
|
12
|
+
|
|
13
|
+
@ReactModule(name = WishlistManagerModule.NAME)
|
|
14
|
+
class WishlistManagerModule(reactContext: ReactApplicationContext) :
|
|
15
|
+
NativeWishlistManagerSpec(reactContext) {
|
|
16
|
+
companion object {
|
|
17
|
+
const val NAME = "WishlistManager"
|
|
18
|
+
|
|
19
|
+
init {
|
|
20
|
+
WishlistSoLoader.staticInit()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@field:DoNotStrip private val mHybridData = initHybrid()
|
|
25
|
+
|
|
26
|
+
override fun getName() = NAME
|
|
27
|
+
|
|
28
|
+
@OptIn(FrameworkAPI::class)
|
|
29
|
+
override fun install(): Boolean = installInternal()
|
|
30
|
+
|
|
31
|
+
@FrameworkAPI
|
|
32
|
+
private fun installInternal(): Boolean {
|
|
33
|
+
val ctx = reactApplicationContext
|
|
34
|
+
val contextHolder = ctx.javaScriptContextHolder ?: return false
|
|
35
|
+
val callInvoker = ctx.jsCallInvokerHolder as? CallInvokerHolderImpl ?: return false
|
|
36
|
+
val fabricUIManager =
|
|
37
|
+
UIManagerHelper.getUIManager(ctx, UIManagerType.FABRIC) as? FabricUIManager
|
|
38
|
+
?: return false
|
|
39
|
+
nativeInstall(contextHolder.get(), callInvoker, fabricUIManager)
|
|
40
|
+
return true
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private external fun initHybrid(): HybridData
|
|
44
|
+
|
|
45
|
+
@FrameworkAPI
|
|
46
|
+
private external fun nativeInstall(
|
|
47
|
+
jsiRuntimeRef: Long,
|
|
48
|
+
jsCallInvokerHolder: CallInvokerHolderImpl,
|
|
49
|
+
fabricUIManager: FabricUIManager
|
|
50
|
+
)
|
|
51
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
package com.wishlist
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.ModuleSpec
|
|
5
|
+
import com.facebook.react.bridge.NativeModule
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
8
|
+
import com.facebook.react.module.annotations.ReactModuleList
|
|
9
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
10
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
11
|
+
|
|
12
|
+
@ReactModuleList(nativeModules = [WishlistManagerModule::class])
|
|
13
|
+
class WishlistPackage : BaseReactPackage() {
|
|
14
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
15
|
+
return if (name == WishlistManagerModule.NAME) {
|
|
16
|
+
WishlistManagerModule(reactContext)
|
|
17
|
+
} else {
|
|
18
|
+
null
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
override fun getViewManagers(reactContext: ReactApplicationContext): List<ModuleSpec> {
|
|
23
|
+
return listOf(
|
|
24
|
+
ModuleSpec.viewManagerSpec { WishlistViewManager() },
|
|
25
|
+
ModuleSpec.viewManagerSpec { TemplateContainerViewManager() },
|
|
26
|
+
ModuleSpec.viewManagerSpec { TemplateInterceptorViewManager() },
|
|
27
|
+
ModuleSpec.viewManagerSpec { ContentContainerViewManager() })
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
31
|
+
return ReactModuleInfoProvider {
|
|
32
|
+
val reactModule =
|
|
33
|
+
WishlistManagerModule::class.java.getAnnotation(ReactModule::class.java)
|
|
34
|
+
?: throw IllegalStateException("WishlistManagerModule must have @ReactModule")
|
|
35
|
+
|
|
36
|
+
mapOf(
|
|
37
|
+
WishlistManagerModule.NAME to
|
|
38
|
+
ReactModuleInfo(
|
|
39
|
+
reactModule.name,
|
|
40
|
+
WishlistManagerModule::class.java.name,
|
|
41
|
+
reactModule.canOverrideExistingModule,
|
|
42
|
+
reactModule.needsEagerInit,
|
|
43
|
+
reactModule.isCxxModule,
|
|
44
|
+
true))
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.wishlist
|
|
2
|
+
|
|
3
|
+
import com.facebook.soloader.SoLoader
|
|
4
|
+
|
|
5
|
+
class WishlistSoLoader {
|
|
6
|
+
companion object {
|
|
7
|
+
@Volatile private var didInit = false
|
|
8
|
+
|
|
9
|
+
fun staticInit() {
|
|
10
|
+
if (didInit) {
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
SoLoader.loadLibrary("react_codegen_wishlist")
|
|
14
|
+
didInit = true
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
package com.wishlist
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReadableArray
|
|
4
|
+
import com.facebook.react.common.MapBuilder
|
|
5
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
6
|
+
import com.facebook.react.uimanager.ReactStylesDiffMap
|
|
7
|
+
import com.facebook.react.uimanager.StateWrapper
|
|
8
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
9
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
10
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
11
|
+
import com.facebook.react.viewmanagers.MGWishlistManagerDelegate
|
|
12
|
+
import com.facebook.react.viewmanagers.MGWishlistManagerInterface
|
|
13
|
+
|
|
14
|
+
private const val CONTENT_OFFSET_KEY = 2
|
|
15
|
+
|
|
16
|
+
@ReactModule(name = WishlistViewManager.REACT_CLASS)
|
|
17
|
+
class WishlistViewManager : ViewGroupManager<Wishlist>(), MGWishlistManagerInterface<Wishlist> {
|
|
18
|
+
companion object {
|
|
19
|
+
const val REACT_CLASS = "MGWishlist"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private val mDelegate = MGWishlistManagerDelegate(this)
|
|
23
|
+
|
|
24
|
+
override fun getName() = REACT_CLASS
|
|
25
|
+
|
|
26
|
+
override fun createViewInstance(reactContext: ThemedReactContext) = Wishlist(reactContext)
|
|
27
|
+
|
|
28
|
+
override fun getDelegate() = mDelegate
|
|
29
|
+
|
|
30
|
+
override fun updateState(
|
|
31
|
+
view: Wishlist,
|
|
32
|
+
props: ReactStylesDiffMap?,
|
|
33
|
+
stateWrapper: StateWrapper?
|
|
34
|
+
): Any? {
|
|
35
|
+
if (stateWrapper != null) {
|
|
36
|
+
view.setStateWrapper(stateWrapper)
|
|
37
|
+
}
|
|
38
|
+
val stateData = stateWrapper?.stateDataMapBuffer
|
|
39
|
+
if (stateData != null && stateData.contains(CONTENT_OFFSET_KEY)) {
|
|
40
|
+
view.scrollToOffsetForContentChange(stateData.getDouble(CONTENT_OFFSET_KEY).toFloat())
|
|
41
|
+
}
|
|
42
|
+
return null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@ReactProp(name = "inflatorId")
|
|
46
|
+
override fun setInflatorId(view: Wishlist, value: String?) {
|
|
47
|
+
view.inflatorId = value
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@ReactProp(name = "initialIndex")
|
|
51
|
+
override fun setInitialIndex(view: Wishlist, value: Int) {
|
|
52
|
+
view.initialIndex = value
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
override fun scrollToItem(view: Wishlist, index: Int, animated: Boolean) {
|
|
56
|
+
view.scrollToItem(index, animated)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
override fun receiveCommand(root: Wishlist, commandId: String, args: ReadableArray?) {
|
|
60
|
+
mDelegate.receiveCommand(root, commandId, args)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
|
|
64
|
+
val map: MutableMap<String, Any> = mutableMapOf()
|
|
65
|
+
map["topStartReached"] = MapBuilder.of("registrationName", "onStartReached")
|
|
66
|
+
map["topEndReached"] = MapBuilder.of("registrationName", "onEndReached")
|
|
67
|
+
return map
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#include "ErrorHandlerAndroid.h"
|
|
2
|
+
|
|
3
|
+
#include <fbjni/fbjni.h>
|
|
4
|
+
#include <react/jni/JReactCxxErrorHandler.h>
|
|
5
|
+
|
|
6
|
+
namespace Wishlist {
|
|
7
|
+
|
|
8
|
+
using namespace facebook;
|
|
9
|
+
|
|
10
|
+
void ErrorHandlerAndroid::reportError(const std::string &message) {
|
|
11
|
+
// TODO: Our thread should have access to JVM by default.
|
|
12
|
+
jni::ThreadScope::WithClassLoader(
|
|
13
|
+
[&] { react::JReactCxxErrorHandler::handleError(message); });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
}; // namespace Wishlist
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <string>
|
|
4
|
+
#include "MGErrorHandler.h"
|
|
5
|
+
|
|
6
|
+
namespace Wishlist {
|
|
7
|
+
|
|
8
|
+
class ErrorHandlerAndroid final : public MGErrorHandler {
|
|
9
|
+
public:
|
|
10
|
+
void reportError(const std::string &message) override;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
} // namespace Wishlist
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#include "JNIStateRegistry.h"
|
|
2
|
+
|
|
3
|
+
namespace Wishlist {
|
|
4
|
+
|
|
5
|
+
JNIStateRegistry &JNIStateRegistry::getInstance() {
|
|
6
|
+
static JNIStateRegistry instance;
|
|
7
|
+
return instance;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
JNIStateRegistry::JNIStateRegistry() : idGenerator_(0) {}
|
|
11
|
+
|
|
12
|
+
void *JNIStateRegistry::getValue(int id) {
|
|
13
|
+
return values_[id];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
int JNIStateRegistry::addValue(void *value) {
|
|
17
|
+
int id = idGenerator_++;
|
|
18
|
+
values_[id] = value;
|
|
19
|
+
return id;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}; // namespace Wishlist
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <unordered_map>
|
|
4
|
+
|
|
5
|
+
namespace Wishlist {
|
|
6
|
+
|
|
7
|
+
class JNIStateRegistry {
|
|
8
|
+
public:
|
|
9
|
+
static JNIStateRegistry &getInstance();
|
|
10
|
+
|
|
11
|
+
void *getValue(int id);
|
|
12
|
+
int addValue(void *value);
|
|
13
|
+
|
|
14
|
+
private:
|
|
15
|
+
JNIStateRegistry();
|
|
16
|
+
JNIStateRegistry(const JNIStateRegistry &) = delete;
|
|
17
|
+
JNIStateRegistry &operator=(const JNIStateRegistry &) = delete;
|
|
18
|
+
|
|
19
|
+
std::unordered_map<int, void *> values_;
|
|
20
|
+
int idGenerator_;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
} // namespace Wishlist
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#include <fbjni/fbjni.h>
|
|
2
|
+
#include "Orchestrator.hpp"
|
|
3
|
+
#include "WishlistManagerModule.hpp"
|
|
4
|
+
|
|
5
|
+
using namespace Wishlist;
|
|
6
|
+
|
|
7
|
+
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
|
|
8
|
+
return facebook::jni::initialize(vm, [] {
|
|
9
|
+
WishlistManagerModule::registerNatives();
|
|
10
|
+
Orchestrator::registerNatives();
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
#include "Orchestrator.hpp"
|
|
2
|
+
|
|
3
|
+
#include <fbjni/fbjni.h>
|
|
4
|
+
#include "ErrorHandlerAndroid.h"
|
|
5
|
+
#include "JNIStateRegistry.h"
|
|
6
|
+
#include "MGDataBindingImpl.hpp"
|
|
7
|
+
#include "MGUIManagerHolder.h"
|
|
8
|
+
#include "MGViewportCarerImpl.h"
|
|
9
|
+
#include "UISchedulerAndroid.h"
|
|
10
|
+
#include "WishlistJsRuntime.h"
|
|
11
|
+
|
|
12
|
+
using namespace facebook;
|
|
13
|
+
|
|
14
|
+
namespace Wishlist {
|
|
15
|
+
|
|
16
|
+
static inline std::vector<std::string> jListToVector(
|
|
17
|
+
alias_ref<jni::JList<jni::JString>> jList) {
|
|
18
|
+
std::vector<std::string> res;
|
|
19
|
+
for (const auto &val : *jList) {
|
|
20
|
+
res.push_back(val->toStdString());
|
|
21
|
+
}
|
|
22
|
+
return res;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
jni::local_ref<Orchestrator::jhybriddata> Orchestrator::initHybrid(
|
|
26
|
+
jni::alias_ref<jhybridobject> jThis,
|
|
27
|
+
std::string wishlistId,
|
|
28
|
+
int viewportCarerRef) {
|
|
29
|
+
return makeCxxInstance(jThis, wishlistId, viewportCarerRef);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Orchestrator::Orchestrator(
|
|
33
|
+
jni::alias_ref<Orchestrator::javaobject> jThis,
|
|
34
|
+
const std::string &wishlistId,
|
|
35
|
+
int viewportCarerRef)
|
|
36
|
+
: javaPart_(jni::make_global(jThis)),
|
|
37
|
+
alreadyRendered_(false),
|
|
38
|
+
pendingScrollToItem_(-1) {
|
|
39
|
+
adapter_ = std::make_shared<Adapter>(
|
|
40
|
+
[this]() { handleVSync(); },
|
|
41
|
+
[this](std::vector<Item> items) { didPushChildren(std::move(items)); });
|
|
42
|
+
auto viewportCarer =
|
|
43
|
+
*reinterpret_cast<std::shared_ptr<MGViewportCarerImpl> *>(
|
|
44
|
+
JNIStateRegistry::getInstance().getValue(viewportCarerRef));
|
|
45
|
+
di_ = std::make_shared<MGDIImpl>();
|
|
46
|
+
di_->setViewportCarer(viewportCarer);
|
|
47
|
+
viewportCarer->setDI(di_);
|
|
48
|
+
viewportCarer->setListener(std::weak_ptr<Adapter>(adapter_));
|
|
49
|
+
di_->setDataBinding(
|
|
50
|
+
std::make_shared<MGDataBindingImpl>(wishlistId, di_->getWeak()));
|
|
51
|
+
di_->setVSyncRequester(adapter_);
|
|
52
|
+
di_->setUIScheduler(std::make_shared<UISchedulerAndroid>());
|
|
53
|
+
di_->setErrorHandler(std::make_shared<ErrorHandlerAndroid>());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
void Orchestrator::renderAsync(
|
|
57
|
+
float width,
|
|
58
|
+
float height,
|
|
59
|
+
float initialContentSize,
|
|
60
|
+
int originItem,
|
|
61
|
+
int templatesRef,
|
|
62
|
+
jni::alias_ref<jni::JList<jni::JString>> namesList,
|
|
63
|
+
std::string inflatorId) {
|
|
64
|
+
auto templates =
|
|
65
|
+
*reinterpret_cast<std::vector<std::shared_ptr<ShadowNode const>> *>(
|
|
66
|
+
JNIStateRegistry::getInstance().getValue(templatesRef));
|
|
67
|
+
if (!alreadyRendered_ && namesList->size() > 0 &&
|
|
68
|
+
namesList->size() == templates.size()) {
|
|
69
|
+
alreadyRendered_ = true;
|
|
70
|
+
width_ = width;
|
|
71
|
+
height_ = height;
|
|
72
|
+
inflatorId_ = inflatorId;
|
|
73
|
+
|
|
74
|
+
di_->getViewportCarer()->initialRenderAsync(
|
|
75
|
+
{width, height},
|
|
76
|
+
initialContentSize,
|
|
77
|
+
originItem,
|
|
78
|
+
templates,
|
|
79
|
+
jListToVector(namesList),
|
|
80
|
+
inflatorId);
|
|
81
|
+
} else {
|
|
82
|
+
width_ = width;
|
|
83
|
+
height_ = height;
|
|
84
|
+
inflatorId_ = inflatorId;
|
|
85
|
+
handleVSync();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
void Orchestrator::didScrollAsync(
|
|
90
|
+
float width,
|
|
91
|
+
float height,
|
|
92
|
+
float contentOffset,
|
|
93
|
+
std::string inflatorId) {
|
|
94
|
+
width_ = width;
|
|
95
|
+
height_ = height;
|
|
96
|
+
inflatorId_ = inflatorId;
|
|
97
|
+
di_->getViewportCarer()->didScrollAsync(
|
|
98
|
+
{width, height}, contentOffset, inflatorId);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
void Orchestrator::handleVSync() {
|
|
102
|
+
di_->getViewportCarer()->didScrollAsync(
|
|
103
|
+
{width_, height_}, MG_NO_OFFSET, inflatorId_);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
void Orchestrator::didUpdateContentOffset() {
|
|
107
|
+
di_->getViewportCarer()->didUpdateContentOffset();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
void Orchestrator::scrollToItem(int index) {
|
|
111
|
+
float offset = -1;
|
|
112
|
+
for (auto &item : items_) {
|
|
113
|
+
if (item.index == index) {
|
|
114
|
+
offset = item.offset;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static const auto scrollToOffset =
|
|
120
|
+
javaClassStatic()->getMethod<void(float)>("scrollToOffset");
|
|
121
|
+
|
|
122
|
+
if (offset == -1) {
|
|
123
|
+
pendingScrollToItem_ = index;
|
|
124
|
+
bool isBelow = items_.back().index < index;
|
|
125
|
+
// TODO: Implement proper animation for items outside the window.
|
|
126
|
+
if (isBelow) {
|
|
127
|
+
scrollToOffset(javaPart_, items_.back().offset + 1000);
|
|
128
|
+
} else {
|
|
129
|
+
scrollToOffset(javaPart_, items_.front().offset - 1000);
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
pendingScrollToItem_ = -1;
|
|
133
|
+
scrollToOffset(javaPart_, offset);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
void Orchestrator::didPushChildren(std::vector<Item> items) {
|
|
138
|
+
items_ = std::move(items);
|
|
139
|
+
if (pendingScrollToItem_ != -1) {
|
|
140
|
+
scrollToItem(pendingScrollToItem_);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
Orchestrator::Adapter::Adapter(
|
|
145
|
+
std::function<void()> onRequestVSync,
|
|
146
|
+
std::function<void(std::vector<Item> items)> didPushChildren)
|
|
147
|
+
: onRequestVSync_(onRequestVSync), didPushChildren_(didPushChildren) {}
|
|
148
|
+
|
|
149
|
+
void Orchestrator::Adapter::didPushChildren(std::vector<Item> newWindow) {
|
|
150
|
+
didPushChildren_(std::move(newWindow));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
void Orchestrator::Adapter::requestVSync() {
|
|
154
|
+
onRequestVSync_();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
void Orchestrator::registerNatives() {
|
|
158
|
+
registerHybrid(
|
|
159
|
+
{makeNativeMethod("initHybrid", Orchestrator::initHybrid),
|
|
160
|
+
makeNativeMethod("renderAsync", Orchestrator::renderAsync),
|
|
161
|
+
makeNativeMethod("didScrollAsync", Orchestrator::didScrollAsync),
|
|
162
|
+
makeNativeMethod(
|
|
163
|
+
"didUpdateContentOffset", Orchestrator::didUpdateContentOffset),
|
|
164
|
+
makeNativeMethod("scrollToItem", Orchestrator::scrollToItem)});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
} // namespace Wishlist
|