@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,138 @@
|
|
|
1
|
+
export type Item = {
|
|
2
|
+
key: string;
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
export type UpdateJob<T extends Item, ResT> = (datacopy: DataCopy<T>) => ResT;
|
|
6
|
+
|
|
7
|
+
export interface DataCopy<T extends Item> {
|
|
8
|
+
getIndex: (key: string) => number | undefined;
|
|
9
|
+
at: (index: number) => T | undefined;
|
|
10
|
+
length: number;
|
|
11
|
+
setItem: (key: string, value: T) => void;
|
|
12
|
+
getItem: (key: string) => T | undefined;
|
|
13
|
+
removeItem: (key: string) => void;
|
|
14
|
+
setAt: (index: number, value: T) => void;
|
|
15
|
+
push: (value: T) => void;
|
|
16
|
+
unshift: (value: T) => void;
|
|
17
|
+
setItems: (items: Array<T>) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface DataCopyInternal<T extends Item> extends DataCopy<T> {
|
|
21
|
+
__isTrackingChanges: boolean;
|
|
22
|
+
__dirtyIndexes: number[];
|
|
23
|
+
__deque: Array<T>;
|
|
24
|
+
__numberOfNegative: number;
|
|
25
|
+
__applyChanges: (pendingUpdates: Array<UpdateJob<T, any>>) => number[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function createItemsDataStructure<T extends Item>(
|
|
29
|
+
initialDeque: Array<T>,
|
|
30
|
+
) {
|
|
31
|
+
'worklet';
|
|
32
|
+
|
|
33
|
+
// RN worklets objects / arrays are proxies need to be deep cloned to
|
|
34
|
+
// work properly in some cases. Ideally this would not be needed.
|
|
35
|
+
function deepClone<ObjT>(x: ObjT): ObjT {
|
|
36
|
+
if (typeof x === 'object' && x !== null) {
|
|
37
|
+
// rn-worklet arrays are proxy and Array.isArray doesn't work.
|
|
38
|
+
if (typeof (x as any).map === 'function') {
|
|
39
|
+
return (x as any).map((ele: unknown) => deepClone(ele));
|
|
40
|
+
} else {
|
|
41
|
+
const res: any = {};
|
|
42
|
+
for (let key of Object.keys(x as any)) {
|
|
43
|
+
res[key] = deepClone((x as any)[key]);
|
|
44
|
+
}
|
|
45
|
+
return res;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return x;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// classes doesn't work :(
|
|
52
|
+
// TODO it can be implemented so that all ops are O(log n)
|
|
53
|
+
const thiz: DataCopyInternal<T> = {
|
|
54
|
+
getIndex: function getIndex(key: string) {
|
|
55
|
+
// That's linear but can be log n (only for testing)
|
|
56
|
+
for (let i = 0; i < this.__deque.length; ++i) {
|
|
57
|
+
if (this.__deque[i].key === key) {
|
|
58
|
+
return i - this.__numberOfNegative;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
},
|
|
63
|
+
at: function at(indexInput: number) {
|
|
64
|
+
const index = indexInput + this.__numberOfNegative;
|
|
65
|
+
if (index == null || index >= this.length || index < 0) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return this.__deque[index];
|
|
70
|
+
},
|
|
71
|
+
get length() {
|
|
72
|
+
return this.__deque.length;
|
|
73
|
+
},
|
|
74
|
+
getItem: function get(key: string) {
|
|
75
|
+
const index = this.getIndex(key);
|
|
76
|
+
if (index == null) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
return this.at(index);
|
|
80
|
+
},
|
|
81
|
+
setItem: function setItem(key: string, value: T) {
|
|
82
|
+
const index = this.getIndex(key);
|
|
83
|
+
if (index == null) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.setAt(index, value);
|
|
87
|
+
},
|
|
88
|
+
removeItem: function removeItem(key: string) {
|
|
89
|
+
const index = this.getIndex(key);
|
|
90
|
+
if (index == null) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.__deque.splice(index + this.__numberOfNegative, 1);
|
|
94
|
+
if (index < 0) {
|
|
95
|
+
this.__numberOfNegative--;
|
|
96
|
+
}
|
|
97
|
+
if (this.__isTrackingChanges) {
|
|
98
|
+
this.__dirtyIndexes.push(index);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
setAt: function setAt(index: number, value: T) {
|
|
102
|
+
this.__deque[index + this.__numberOfNegative] = deepClone(value);
|
|
103
|
+
if (this.__isTrackingChanges) {
|
|
104
|
+
this.__dirtyIndexes.push(index);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
push: function push(value: T) {
|
|
108
|
+
this.__deque.push(deepClone(value));
|
|
109
|
+
},
|
|
110
|
+
unshift: function unshift(value: T) {
|
|
111
|
+
this.__deque.unshift(deepClone(value));
|
|
112
|
+
this.__numberOfNegative++;
|
|
113
|
+
},
|
|
114
|
+
setItems: function reset(items: Array<T>) {
|
|
115
|
+
if (this.__isTrackingChanges) {
|
|
116
|
+
this.__deque.forEach((_item, i) => this.__dirtyIndexes.push(i));
|
|
117
|
+
}
|
|
118
|
+
this.__deque = deepClone(items);
|
|
119
|
+
this.__numberOfNegative = 0;
|
|
120
|
+
},
|
|
121
|
+
__applyChanges: function __applyChanges(pendingUpdates) {
|
|
122
|
+
this.__isTrackingChanges = true;
|
|
123
|
+
for (let updateJob of pendingUpdates) {
|
|
124
|
+
updateJob(this);
|
|
125
|
+
}
|
|
126
|
+
this.__isTrackingChanges = false;
|
|
127
|
+
const res = this.__dirtyIndexes.map((i) => i);
|
|
128
|
+
this.__dirtyIndexes = [];
|
|
129
|
+
return res;
|
|
130
|
+
},
|
|
131
|
+
__deque: deepClone(initialDeque),
|
|
132
|
+
__numberOfNegative: 0, // allow negative indexes so that indices are constant
|
|
133
|
+
__dirtyIndexes: [],
|
|
134
|
+
__isTrackingChanges: false,
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
return thiz;
|
|
138
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Android currently uses the React Native runtime directly for Wishlist native
|
|
2
|
+
// work. Keep this module free of `react-native-worklets-core`, whose Android
|
|
3
|
+
// package is not registered by RN 0.83's bridgeless package delegate.
|
|
4
|
+
export function bindNativeWishlistContext() {
|
|
5
|
+
// iOS binds a worklets-core context into native. Android initializes native
|
|
6
|
+
// with the RN runtime in `WishlistManagerModule.nativeInstall`.
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function createRunInWishlistFn<
|
|
10
|
+
T,
|
|
11
|
+
A extends unknown[] = [],
|
|
12
|
+
>(fn: (...args: A) => T): (...args: A) => Promise<T> {
|
|
13
|
+
return (...args: A) => Promise.resolve().then(() => fn(...args));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function createRunInJsFn<A extends unknown[], T>(
|
|
17
|
+
fn: (...args: A) => T,
|
|
18
|
+
): (...args: A) => T {
|
|
19
|
+
return (...args: A) => fn(...args);
|
|
20
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import type {
|
|
3
|
+
IWorkletContext,
|
|
4
|
+
IWorkletNativeApi,
|
|
5
|
+
} from 'react-native-worklets-core';
|
|
6
|
+
|
|
7
|
+
declare const require: (
|
|
8
|
+
moduleName: 'react-native-worklets-core',
|
|
9
|
+
) => { Worklets: IWorkletNativeApi };
|
|
10
|
+
|
|
11
|
+
const Worklets =
|
|
12
|
+
Platform.OS === 'android'
|
|
13
|
+
? undefined
|
|
14
|
+
: require('react-native-worklets-core').Worklets;
|
|
15
|
+
|
|
16
|
+
const runOnCurrentRuntime = <T, A extends unknown[]>(
|
|
17
|
+
fn: (...args: A) => T,
|
|
18
|
+
): ((...args: A) => Promise<T>) => {
|
|
19
|
+
return (...args: A) => Promise.resolve().then(() => fn(...args));
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Dedicated worklet runtime for wishlist. Native code (`WishlistJsRuntime`)
|
|
23
|
+
// gets a pointer to this runtime via `__mgWishlistSetContext` (installed by
|
|
24
|
+
// `MGWishlistManager.installWishlistRuntime`), so JS-side worklets and the
|
|
25
|
+
// library's native side share state.
|
|
26
|
+
export const wishlistContext: IWorkletContext | undefined =
|
|
27
|
+
Worklets?.createContext('wishlist');
|
|
28
|
+
|
|
29
|
+
export function bindNativeWishlistContext() {
|
|
30
|
+
if (!wishlistContext) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const setNativeContext = (global as any).__mgWishlistSetContext;
|
|
35
|
+
if (typeof setNativeContext === 'function') {
|
|
36
|
+
setNativeContext(wishlistContext);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function createRunInWishlistFn<
|
|
41
|
+
T,
|
|
42
|
+
A extends unknown[] = [],
|
|
43
|
+
>(fn: (...args: A) => T): (...args: A) => Promise<T> {
|
|
44
|
+
if (!wishlistContext) {
|
|
45
|
+
return runOnCurrentRuntime(fn);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return wishlistContext.createRunAsync(fn) as (...args: A) => Promise<T>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function createRunInJsFn<A extends unknown[], T>(
|
|
52
|
+
fn: (...args: A) => T,
|
|
53
|
+
): (...args: A) => Promise<T> {
|
|
54
|
+
if (!Worklets) {
|
|
55
|
+
return runOnCurrentRuntime(fn);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return Worklets.createRunOnJS(fn);
|
|
59
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import React, { forwardRef, useMemo } from 'react';
|
|
2
|
+
import { StyleSheet, Text } from 'react-native';
|
|
3
|
+
import { TemplateCallback, TemplateCallbackWorklet } from './EventHandler';
|
|
4
|
+
import { ForEachBase } from './Components/ForEachBase';
|
|
5
|
+
import InflatorRepository, {
|
|
6
|
+
getUIInflatorRegistry,
|
|
7
|
+
} from './InflatorRepository';
|
|
8
|
+
import { CaseBase } from './Components/Switch';
|
|
9
|
+
import { useTemplateContext } from './TemplateContext';
|
|
10
|
+
import {
|
|
11
|
+
createTemplateValue,
|
|
12
|
+
isTemplateValue,
|
|
13
|
+
TemplateValue,
|
|
14
|
+
TemplateValueInternal,
|
|
15
|
+
} from './TemplateValue';
|
|
16
|
+
import { generateId } from './Utils';
|
|
17
|
+
import { useWishlistContext } from './WishlistContext';
|
|
18
|
+
import { TemplateItem } from './TemplateItem';
|
|
19
|
+
import { ComponentPool } from './ComponentPool';
|
|
20
|
+
|
|
21
|
+
// This is based on types from @types/react-native createAnimatedComponent.
|
|
22
|
+
|
|
23
|
+
type Nullable = undefined | null;
|
|
24
|
+
type Primitive = string | number | boolean | symbol;
|
|
25
|
+
type Builtin = Function | Date | Error | RegExp;
|
|
26
|
+
|
|
27
|
+
interface WithTemplateArray<P> extends Array<WithTemplateValue<P>> {}
|
|
28
|
+
type WithTemplateObject<T> = {
|
|
29
|
+
[K in keyof T]: WithTemplateValue<T[K]>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type WithTemplateValue<T> = T extends Builtin | Nullable
|
|
33
|
+
? T
|
|
34
|
+
: T extends Primitive
|
|
35
|
+
? T | TemplateValue<T>
|
|
36
|
+
: T extends Array<infer P>
|
|
37
|
+
? WithTemplateArray<P>
|
|
38
|
+
: T extends {}
|
|
39
|
+
? WithTemplateObject<T>
|
|
40
|
+
: T;
|
|
41
|
+
|
|
42
|
+
type NonTemplateProps = 'key' | 'ref';
|
|
43
|
+
|
|
44
|
+
export type TemplateProps<T> = {
|
|
45
|
+
[key in keyof T]: key extends NonTemplateProps
|
|
46
|
+
? T[key]
|
|
47
|
+
: WithTemplateValue<T[key]>;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export interface TemplateComponent<T extends React.ComponentType<any>>
|
|
51
|
+
extends React.FC<TemplateProps<React.ComponentPropsWithRef<T>>> {}
|
|
52
|
+
|
|
53
|
+
function setInObject(obj: any, path: string[], value: any) {
|
|
54
|
+
'worklet';
|
|
55
|
+
|
|
56
|
+
let current = obj;
|
|
57
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
58
|
+
current[path[i]] = current[path[i]] ?? {};
|
|
59
|
+
current = current[path[i]];
|
|
60
|
+
}
|
|
61
|
+
current[path[path.length - 1]] = value;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function traverseObject(
|
|
65
|
+
obj: any,
|
|
66
|
+
callback: (path: string[], value: any) => void,
|
|
67
|
+
) {
|
|
68
|
+
const stack: { path: string[]; value: any }[] = [{ path: [], value: obj }];
|
|
69
|
+
while (stack.length > 0) {
|
|
70
|
+
const { path, value } = stack.pop()!;
|
|
71
|
+
|
|
72
|
+
if (
|
|
73
|
+
value &&
|
|
74
|
+
typeof value === 'object' &&
|
|
75
|
+
!isTemplateValue(value) &&
|
|
76
|
+
!(value instanceof TemplateCallback) &&
|
|
77
|
+
(path.length === 0 || path[path.length - 1] !== 'children')
|
|
78
|
+
) {
|
|
79
|
+
Object.keys(value).forEach((key) => {
|
|
80
|
+
stack.push({ path: [...path, key], value: value[key] });
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
callback(path, value);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function convertToTemplateValue(value: unknown, path: string[]) {
|
|
89
|
+
let curTemplateType = value;
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
// TODO(janic): Need to call remove for template values created here.
|
|
93
|
+
templateValue: createTemplateValue(() => {
|
|
94
|
+
'worklet';
|
|
95
|
+
return curTemplateType;
|
|
96
|
+
}),
|
|
97
|
+
targetPath: path,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
type CreateTemplateComponentOptions = {
|
|
102
|
+
/**
|
|
103
|
+
* Worklet that will be called when items are inflated.
|
|
104
|
+
* This can be used to map props differently than the
|
|
105
|
+
* default implementation.
|
|
106
|
+
*/
|
|
107
|
+
addProps?: (
|
|
108
|
+
templateItem: TemplateItem,
|
|
109
|
+
props: any,
|
|
110
|
+
inflatorId: string,
|
|
111
|
+
pool: ComponentPool,
|
|
112
|
+
rootValue: any,
|
|
113
|
+
) => void;
|
|
114
|
+
/**
|
|
115
|
+
* Additional non-template props that should be passed to
|
|
116
|
+
* the inflator. Can use dot syntax to access nested props.
|
|
117
|
+
*/
|
|
118
|
+
additionalTemplateProps?: string[];
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export function createTemplateComponent<T extends React.ComponentType<any>>(
|
|
122
|
+
Component: T,
|
|
123
|
+
{ addProps, additionalTemplateProps }: CreateTemplateComponentOptions = {},
|
|
124
|
+
): TemplateComponent<T> {
|
|
125
|
+
const parsedAdditionalTemplateProps =
|
|
126
|
+
additionalTemplateProps?.map((prop) => prop.split('.')) ?? [];
|
|
127
|
+
|
|
128
|
+
const WishListComponent = forwardRef<any, any>(({ style, ...props }, ref) => {
|
|
129
|
+
const { inflatorId } = useWishlistContext();
|
|
130
|
+
const { templateType } = useTemplateContext();
|
|
131
|
+
|
|
132
|
+
const nativeId = useMemo(generateId, []);
|
|
133
|
+
|
|
134
|
+
const otherPropsMemoized = useMemo(() => {
|
|
135
|
+
const resolvedStyle = StyleSheet.flatten(style);
|
|
136
|
+
|
|
137
|
+
const templateValues: {
|
|
138
|
+
templateValue: TemplateValueInternal<any>;
|
|
139
|
+
targetPath: string[];
|
|
140
|
+
}[] = [];
|
|
141
|
+
|
|
142
|
+
const templateCallbacks: {
|
|
143
|
+
worklet: TemplateCallbackWorklet;
|
|
144
|
+
eventName: string;
|
|
145
|
+
}[] = [];
|
|
146
|
+
|
|
147
|
+
const additionalProps: { targetPath: string[]; value: any }[] = [];
|
|
148
|
+
|
|
149
|
+
const otherProps = {};
|
|
150
|
+
traverseObject({ ...props, style: resolvedStyle }, (path, value) => {
|
|
151
|
+
const applyHacks = () => {
|
|
152
|
+
// Text component needs to receive a string child to work properly.
|
|
153
|
+
// @ts-expect-error TODO: fix this.
|
|
154
|
+
if (path[0] === 'children' && Component === Text) {
|
|
155
|
+
setInObject(otherProps, path, ' ');
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
if (isTemplateValue(value)) {
|
|
160
|
+
templateValues.push({ templateValue: value, targetPath: path });
|
|
161
|
+
|
|
162
|
+
applyHacks();
|
|
163
|
+
} else if (value instanceof TemplateCallback) {
|
|
164
|
+
templateCallbacks.push({
|
|
165
|
+
worklet: value.worklet,
|
|
166
|
+
// Callbacks should never be in objects.
|
|
167
|
+
eventName: value.eventName ?? path[0].replace(/^on/, 'top'),
|
|
168
|
+
});
|
|
169
|
+
// Events have a boolean prop associated to know whether the
|
|
170
|
+
// function is set or not, so we still want to pass the prop.
|
|
171
|
+
setInObject(otherProps, path, () => {});
|
|
172
|
+
} else {
|
|
173
|
+
// @ts-expect-error TODO: fix this.
|
|
174
|
+
if (Component === ForEachBase && path[0] === 'template') {
|
|
175
|
+
templateValues.push(convertToTemplateValue(value, path));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (
|
|
179
|
+
// @ts-expect-error TODO: fix this.
|
|
180
|
+
Component === CaseBase &&
|
|
181
|
+
path[0] === 'value' &&
|
|
182
|
+
!isTemplateValue(value)
|
|
183
|
+
) {
|
|
184
|
+
templateValues.push(convertToTemplateValue(value, path));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (
|
|
188
|
+
// @ts-expect-error TODO: fix this.
|
|
189
|
+
Component === Text &&
|
|
190
|
+
path[0] === 'children' &&
|
|
191
|
+
!isTemplateValue(value)
|
|
192
|
+
) {
|
|
193
|
+
templateValues.push(convertToTemplateValue(value, path));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
parsedAdditionalTemplateProps.forEach((additionalPath) => {
|
|
197
|
+
if (
|
|
198
|
+
additionalPath.length === path.length &&
|
|
199
|
+
additionalPath.every((p, i) => p === path[i])
|
|
200
|
+
) {
|
|
201
|
+
additionalProps.push({ targetPath: path, value });
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
setInObject(otherProps, path, value);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
InflatorRepository.registerMapping(
|
|
209
|
+
inflatorId,
|
|
210
|
+
nativeId,
|
|
211
|
+
templateType,
|
|
212
|
+
(value, templateItem, pool, rootValue) => {
|
|
213
|
+
'worklet';
|
|
214
|
+
|
|
215
|
+
const propsToSet: any = {};
|
|
216
|
+
additionalProps.forEach(({ targetPath, value: v }) => {
|
|
217
|
+
setInObject(propsToSet, targetPath, v);
|
|
218
|
+
});
|
|
219
|
+
templateValues.forEach(({ templateValue, targetPath }) => {
|
|
220
|
+
setInObject(propsToSet, targetPath, templateValue.value());
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
templateCallbacks.forEach(({ eventName, worklet }) => {
|
|
224
|
+
templateItem.setCallback(eventName, (ev) => {
|
|
225
|
+
getUIInflatorRegistry().withCurrentValues(
|
|
226
|
+
value,
|
|
227
|
+
rootValue,
|
|
228
|
+
() => {
|
|
229
|
+
worklet(ev, value, rootValue);
|
|
230
|
+
},
|
|
231
|
+
);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// Styles need to be passed as props.
|
|
236
|
+
const { style: styleForProps, ...otherPropsToSet } = propsToSet;
|
|
237
|
+
const finalPropsToSet = { ...otherPropsToSet, ...styleForProps };
|
|
238
|
+
if (addProps) {
|
|
239
|
+
addProps(
|
|
240
|
+
templateItem,
|
|
241
|
+
finalPropsToSet,
|
|
242
|
+
inflatorId,
|
|
243
|
+
pool,
|
|
244
|
+
rootValue,
|
|
245
|
+
);
|
|
246
|
+
} else {
|
|
247
|
+
templateItem.addProps(finalPropsToSet);
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
);
|
|
251
|
+
return otherProps;
|
|
252
|
+
// TODO: This will change on every render, if we want this memo to work properly we need
|
|
253
|
+
// to shallow compare the props object.
|
|
254
|
+
}, [inflatorId, nativeId, props, style, templateType]);
|
|
255
|
+
|
|
256
|
+
// @ts-expect-error: this is ok.
|
|
257
|
+
return <Component {...otherPropsMemoized} ref={ref} nativeID={nativeId} />;
|
|
258
|
+
}) as unknown as TemplateComponent<T>;
|
|
259
|
+
|
|
260
|
+
WishListComponent.displayName = `WishList(${Component.displayName})`;
|
|
261
|
+
|
|
262
|
+
return WishListComponent;
|
|
263
|
+
}
|
package/src/global.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare var global: any;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import './EventHandler';
|
|
2
|
+
import WishListManager from './Specs/NativeWishlistManager';
|
|
3
|
+
import { bindNativeWishlistContext } from './WishlistJsRuntime';
|
|
4
|
+
|
|
5
|
+
WishListManager.install();
|
|
6
|
+
bindNativeWishlistContext();
|
|
7
|
+
|
|
8
|
+
export { useTemplateValue, TemplateValue } from './TemplateValue';
|
|
9
|
+
export { createTemplateComponent } from './createTemplateComponent';
|
|
10
|
+
export { Wishlist, WishListInstance } from './Wishlist';
|
|
11
|
+
export {
|
|
12
|
+
useWishlistData,
|
|
13
|
+
useWishlistContextData,
|
|
14
|
+
WishlistData,
|
|
15
|
+
} from './WishlistData';
|
|
16
|
+
export { createRunInJsFn, createRunInWishlistFn } from './WishlistJsRuntime';
|
|
17
|
+
export { renderTemplate } from './renderTemplate';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ComponentPool } from './ComponentPool';
|
|
2
|
+
import { getUIInflatorRegistry } from './InflatorRepository';
|
|
3
|
+
|
|
4
|
+
export function renderTemplate(
|
|
5
|
+
template: string,
|
|
6
|
+
value: any,
|
|
7
|
+
rootValue: any,
|
|
8
|
+
inflatorId: string,
|
|
9
|
+
pool: ComponentPool,
|
|
10
|
+
) {
|
|
11
|
+
'worklet';
|
|
12
|
+
|
|
13
|
+
const item = pool.getComponent(template)!;
|
|
14
|
+
return getUIInflatorRegistry().useMappings(
|
|
15
|
+
item,
|
|
16
|
+
value,
|
|
17
|
+
template,
|
|
18
|
+
inflatorId,
|
|
19
|
+
pool,
|
|
20
|
+
rootValue,
|
|
21
|
+
);
|
|
22
|
+
}
|