@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,49 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { View, ViewStyle } from 'react-native';
|
|
3
|
+
import { createTemplateComponent } from '../createTemplateComponent';
|
|
4
|
+
import type { TemplateValue } from '../TemplateValue';
|
|
5
|
+
|
|
6
|
+
const SwitchTemplateComponent = createTemplateComponent(View);
|
|
7
|
+
|
|
8
|
+
type SwitchProps = {
|
|
9
|
+
value: TemplateValue<unknown>;
|
|
10
|
+
children: React.ReactElement<typeof Case>[];
|
|
11
|
+
style?: ViewStyle;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function Switch(props: SwitchProps) {
|
|
15
|
+
const children = React.Children.map(props.children, (item) =>
|
|
16
|
+
React.cloneElement(item, {
|
|
17
|
+
...item.props,
|
|
18
|
+
// @ts-expect-error this is hidden property
|
|
19
|
+
switchValue: props.value,
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return <SwitchTemplateComponent {...props} children={children} />;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const CaseBase = forwardRef<any, any>((props, ref) => {
|
|
27
|
+
return <View {...props} ref={ref} />;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const CaseTemplateComponent = createTemplateComponent(CaseBase, {
|
|
31
|
+
addProps: (item, props) => {
|
|
32
|
+
'worklet';
|
|
33
|
+
|
|
34
|
+
if (props.switchValue === props.value) {
|
|
35
|
+
item.addProps({ display: 'flex' });
|
|
36
|
+
} else {
|
|
37
|
+
item.addProps({ display: 'none' });
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
type CaseProps = React.PropsWithChildren<{
|
|
43
|
+
value: TemplateValue<unknown> | string | boolean | number;
|
|
44
|
+
style?: ViewStyle;
|
|
45
|
+
}>;
|
|
46
|
+
|
|
47
|
+
export function Case(props: CaseProps) {
|
|
48
|
+
return <CaseTemplateComponent {...props} />;
|
|
49
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Image, Platform } from 'react-native';
|
|
2
|
+
import { createTemplateComponent } from '../createTemplateComponent';
|
|
3
|
+
|
|
4
|
+
export const WishlistImage = createTemplateComponent(Image, {
|
|
5
|
+
addProps: (item, props) => {
|
|
6
|
+
'worklet';
|
|
7
|
+
if (Platform.OS === 'android') {
|
|
8
|
+
const { source, ...rest } = props;
|
|
9
|
+
const src = source != null && !Array.isArray(source) ? [source] : source;
|
|
10
|
+
item.addProps({
|
|
11
|
+
src,
|
|
12
|
+
...rest,
|
|
13
|
+
});
|
|
14
|
+
} else {
|
|
15
|
+
item.addProps(props);
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
additionalTemplateProps: [
|
|
19
|
+
'style.borderRadius',
|
|
20
|
+
'style.borderTopLeftRadius',
|
|
21
|
+
'style.borderTopRightRadius',
|
|
22
|
+
'style.borderBottomLeftRadius',
|
|
23
|
+
'style.borderBottomRightRadius',
|
|
24
|
+
],
|
|
25
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Text } from 'react-native';
|
|
2
|
+
import { createTemplateComponent } from '../createTemplateComponent';
|
|
3
|
+
|
|
4
|
+
export const WishlistText = createTemplateComponent(Text, {
|
|
5
|
+
addProps: (item, props) => {
|
|
6
|
+
'worklet';
|
|
7
|
+
|
|
8
|
+
const { children, ...other } = props;
|
|
9
|
+
const value =
|
|
10
|
+
typeof children === 'string' ? children : children?.toString();
|
|
11
|
+
item.RawText?.addProps({ text: value });
|
|
12
|
+
item.addProps(other);
|
|
13
|
+
},
|
|
14
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { createRunInWishlistFn } from './WishlistJsRuntime';
|
|
3
|
+
|
|
4
|
+
// Older React Native versions exposed `global.global`. Newer versions only
|
|
5
|
+
// set `global.window` and `global.self`, so the wishlist native code, which
|
|
6
|
+
// reads `global.global.handlers` / `global.global.handleEvent`, needs the
|
|
7
|
+
// alias re-established before any events fire. This must run at module load
|
|
8
|
+
// because the native event observer is registered as soon as the TurboModule
|
|
9
|
+
// loads — before any Wishlist component renders.
|
|
10
|
+
const setupRuntimeGlobals = () => {
|
|
11
|
+
if (global.global === undefined) {
|
|
12
|
+
global.global = global;
|
|
13
|
+
}
|
|
14
|
+
global.handlers = global.handlers ?? {};
|
|
15
|
+
global.handleEvent = (type: string, tag: number, event: any) => {
|
|
16
|
+
const key = tag.toString() + type.replace(/^topOn/, 'on');
|
|
17
|
+
const callback = global.handlers[key];
|
|
18
|
+
if (callback) {
|
|
19
|
+
callback(event);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
setupRuntimeGlobals();
|
|
25
|
+
|
|
26
|
+
let done = false;
|
|
27
|
+
const maybeInit = () => {
|
|
28
|
+
if (!done) {
|
|
29
|
+
done = true;
|
|
30
|
+
// Mirror the same setup on the worklets UI runtime — that's where
|
|
31
|
+
// `WishlistJsRuntime` lives natively, so its `handleEvent` lookup happens
|
|
32
|
+
// there.
|
|
33
|
+
createRunInWishlistFn(() => {
|
|
34
|
+
'worklet';
|
|
35
|
+
if (global.global === undefined) {
|
|
36
|
+
global.global = global;
|
|
37
|
+
}
|
|
38
|
+
global.handlers = global.handlers ?? {};
|
|
39
|
+
global.handleEvent = (type: string, tag: number, event: any) => {
|
|
40
|
+
'worklet';
|
|
41
|
+
const key = tag.toString() + type.replace(/^topOn/, 'on');
|
|
42
|
+
const callback = global.handlers[key];
|
|
43
|
+
if (callback) {
|
|
44
|
+
callback(event);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
})();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type TemplateCallbackWorklet = (
|
|
52
|
+
nativeEvent: any,
|
|
53
|
+
value: any,
|
|
54
|
+
rootValue: any,
|
|
55
|
+
) => unknown;
|
|
56
|
+
|
|
57
|
+
export class TemplateCallback {
|
|
58
|
+
worklet: TemplateCallbackWorklet;
|
|
59
|
+
eventName: string | undefined;
|
|
60
|
+
|
|
61
|
+
constructor(worklet: TemplateCallbackWorklet, eventName?: string) {
|
|
62
|
+
this.worklet = worklet;
|
|
63
|
+
this.eventName = eventName;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function useTemplateCallback(
|
|
68
|
+
worklet: (nativeEvent: any, value: any, rootValue: any) => unknown,
|
|
69
|
+
eventName?: string,
|
|
70
|
+
) {
|
|
71
|
+
return useMemo(() => {
|
|
72
|
+
return new TemplateCallback(worklet, eventName);
|
|
73
|
+
}, [worklet, eventName]);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function initEventHandler() {
|
|
77
|
+
maybeInit();
|
|
78
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { getColorsUIModule } from './Colors';
|
|
2
|
+
import {
|
|
3
|
+
ComponentPool,
|
|
4
|
+
NativeComponentPool,
|
|
5
|
+
wrapComponentPool,
|
|
6
|
+
} from './ComponentPool';
|
|
7
|
+
import { TemplateItem } from './TemplateItem';
|
|
8
|
+
import type { TemplateValueUIState } from './TemplateValue';
|
|
9
|
+
import { createRunInWishlistFn } from './WishlistJsRuntime';
|
|
10
|
+
|
|
11
|
+
export type InflateMethod = (
|
|
12
|
+
index: number,
|
|
13
|
+
pool: ComponentPool,
|
|
14
|
+
previousItem: TemplateItem | null,
|
|
15
|
+
) => [TemplateItem, any] | undefined;
|
|
16
|
+
|
|
17
|
+
export type MappingInflateMethod = (
|
|
18
|
+
value: unknown,
|
|
19
|
+
templateItem: TemplateItem,
|
|
20
|
+
pool: ComponentPool,
|
|
21
|
+
rootValue: unknown,
|
|
22
|
+
) => void;
|
|
23
|
+
|
|
24
|
+
export type UIInflatorRegistry = {
|
|
25
|
+
inflateItem: (
|
|
26
|
+
id: string,
|
|
27
|
+
index: number,
|
|
28
|
+
pool: NativeComponentPool,
|
|
29
|
+
prevItem: TemplateItem | null,
|
|
30
|
+
) => TemplateItem | undefined;
|
|
31
|
+
registerInflator: (id: string, inflateMethod: InflateMethod) => void;
|
|
32
|
+
unregisterInflator: (id: string) => void;
|
|
33
|
+
registerMapping: (
|
|
34
|
+
inflatorId: string,
|
|
35
|
+
nativeId: string,
|
|
36
|
+
templateType: string,
|
|
37
|
+
inflateMethod: MappingInflateMethod,
|
|
38
|
+
) => void;
|
|
39
|
+
useMappings: (
|
|
40
|
+
item: TemplateItem,
|
|
41
|
+
value: unknown,
|
|
42
|
+
templateType: string,
|
|
43
|
+
id: string,
|
|
44
|
+
pool: ComponentPool,
|
|
45
|
+
rootValue: unknown,
|
|
46
|
+
) => TemplateItem;
|
|
47
|
+
getTemplateValueState: (id: string) => TemplateValueUIState | undefined;
|
|
48
|
+
setTemplateValueState: (id: string, state: TemplateValueUIState) => void;
|
|
49
|
+
deleteTemplateValueState: (id: string) => void;
|
|
50
|
+
getCurrentValue: () => unknown;
|
|
51
|
+
getCurrentRootValue: () => unknown;
|
|
52
|
+
withCurrentValues: (
|
|
53
|
+
value: unknown,
|
|
54
|
+
rootValue: unknown,
|
|
55
|
+
callback: () => void,
|
|
56
|
+
) => void;
|
|
57
|
+
didPushChildren: () => void;
|
|
58
|
+
addPushChildrenCallback: (callback: () => void) => void;
|
|
59
|
+
processProps: (props: any) => any;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
let done = false;
|
|
63
|
+
const maybeInit = () => {
|
|
64
|
+
if (!done) {
|
|
65
|
+
done = true;
|
|
66
|
+
createRunInWishlistFn(() => {
|
|
67
|
+
'worklet';
|
|
68
|
+
|
|
69
|
+
const registry = new Map<string, InflateMethod>();
|
|
70
|
+
const mappings = new Map<
|
|
71
|
+
string,
|
|
72
|
+
Map<string, Map<string, MappingInflateMethod>>
|
|
73
|
+
>();
|
|
74
|
+
const templateValueStates = new Map<string, TemplateValueUIState>();
|
|
75
|
+
let pushChildrenCallbacks: (() => void)[] = [];
|
|
76
|
+
let currentValue: unknown;
|
|
77
|
+
let currentRootValue: unknown;
|
|
78
|
+
|
|
79
|
+
const inflatorRegistry: UIInflatorRegistry = {
|
|
80
|
+
inflateItem: (id, index, nativePool, prevItem) => {
|
|
81
|
+
const pool = wrapComponentPool(nativePool);
|
|
82
|
+
const inflator = registry.get(id);
|
|
83
|
+
if (inflator) {
|
|
84
|
+
const result = inflator(index, pool, prevItem);
|
|
85
|
+
if (!result) {
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
const [item, value] = result;
|
|
89
|
+
|
|
90
|
+
return inflatorRegistry.useMappings(
|
|
91
|
+
item,
|
|
92
|
+
value,
|
|
93
|
+
value.type,
|
|
94
|
+
id,
|
|
95
|
+
pool,
|
|
96
|
+
value, // rootValue
|
|
97
|
+
);
|
|
98
|
+
} else {
|
|
99
|
+
console.log('Inflator not found for id: ' + id);
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
useMappings: (item, value, templateType, id, pool, rootValue) => {
|
|
104
|
+
// We need to save and restore current values to support things like ForEach
|
|
105
|
+
// where current value can change.
|
|
106
|
+
inflatorRegistry.withCurrentValues(value, rootValue, () => {
|
|
107
|
+
const mapping = mappings.get(id)?.get(templateType);
|
|
108
|
+
if (mapping) {
|
|
109
|
+
for (const [nativeId, inflate] of mapping.entries()) {
|
|
110
|
+
const templateItem = item.getByWishId(nativeId);
|
|
111
|
+
if (templateItem) {
|
|
112
|
+
templateValueStates.clear();
|
|
113
|
+
inflate(value, templateItem, pool, rootValue);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
return item;
|
|
119
|
+
},
|
|
120
|
+
registerInflator: (id, inflateMethod) => {
|
|
121
|
+
registry.set(id, inflateMethod);
|
|
122
|
+
},
|
|
123
|
+
unregisterInflator: (id) => {
|
|
124
|
+
// TODO(Szymon) It should be done on UI Thread as it may be still in use
|
|
125
|
+
registry.delete(id);
|
|
126
|
+
mappings.delete(id);
|
|
127
|
+
},
|
|
128
|
+
registerMapping: (
|
|
129
|
+
inflatorId: string,
|
|
130
|
+
nativeId: string,
|
|
131
|
+
templateType: string,
|
|
132
|
+
inflateMethod: MappingInflateMethod,
|
|
133
|
+
) => {
|
|
134
|
+
const mapping = mappings.get(inflatorId) ?? new Map();
|
|
135
|
+
const innerMapping = mapping.get(templateType) ?? new Map();
|
|
136
|
+
innerMapping.set(nativeId, inflateMethod);
|
|
137
|
+
mapping.set(templateType, innerMapping);
|
|
138
|
+
mappings.set(inflatorId, mapping);
|
|
139
|
+
},
|
|
140
|
+
getTemplateValueState: (id) => {
|
|
141
|
+
return templateValueStates.get(id);
|
|
142
|
+
},
|
|
143
|
+
setTemplateValueState: (id, state) => {
|
|
144
|
+
templateValueStates.set(id, state);
|
|
145
|
+
},
|
|
146
|
+
deleteTemplateValueState: (id) => {
|
|
147
|
+
templateValueStates.delete(id);
|
|
148
|
+
},
|
|
149
|
+
withCurrentValues: (value, rootValue, callback) => {
|
|
150
|
+
templateValueStates.clear();
|
|
151
|
+
const previousValue = currentValue;
|
|
152
|
+
const previousRootValue = currentRootValue;
|
|
153
|
+
currentValue = value;
|
|
154
|
+
currentRootValue = rootValue;
|
|
155
|
+
callback();
|
|
156
|
+
currentValue = previousValue;
|
|
157
|
+
currentRootValue = previousRootValue;
|
|
158
|
+
},
|
|
159
|
+
getCurrentValue: () => {
|
|
160
|
+
return currentValue;
|
|
161
|
+
},
|
|
162
|
+
getCurrentRootValue: () => {
|
|
163
|
+
return currentRootValue;
|
|
164
|
+
},
|
|
165
|
+
// TODO: Scope this by wishlist
|
|
166
|
+
didPushChildren: () => {
|
|
167
|
+
pushChildrenCallbacks.forEach((cb) => cb());
|
|
168
|
+
pushChildrenCallbacks = [];
|
|
169
|
+
},
|
|
170
|
+
addPushChildrenCallback: (callback) => {
|
|
171
|
+
pushChildrenCallbacks.push(callback);
|
|
172
|
+
},
|
|
173
|
+
processProps: (props) => {
|
|
174
|
+
const colors = getColorsUIModule();
|
|
175
|
+
const result: any = {};
|
|
176
|
+
for (const [key, value] of Object.entries(props)) {
|
|
177
|
+
if (colors.colorProps.includes(key)) {
|
|
178
|
+
result[key] = colors.processColor(value);
|
|
179
|
+
} else {
|
|
180
|
+
result[key] = value;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
global.__wishlistInflatorRegistry = inflatorRegistry;
|
|
187
|
+
})();
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export function getUIInflatorRegistry(): UIInflatorRegistry {
|
|
192
|
+
'worklet';
|
|
193
|
+
|
|
194
|
+
return global.__wishlistInflatorRegistry;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export default class InflatorRepository {
|
|
198
|
+
static register(id: string, inflateMethod: InflateMethod) {
|
|
199
|
+
maybeInit();
|
|
200
|
+
createRunInWishlistFn(() => {
|
|
201
|
+
'worklet';
|
|
202
|
+
getUIInflatorRegistry().registerInflator(id, inflateMethod);
|
|
203
|
+
})();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
static unregister(id: string) {
|
|
207
|
+
maybeInit();
|
|
208
|
+
createRunInWishlistFn(() => {
|
|
209
|
+
'worklet';
|
|
210
|
+
getUIInflatorRegistry().unregisterInflator(id);
|
|
211
|
+
})();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
static registerMapping(
|
|
215
|
+
inflatorId: string,
|
|
216
|
+
nativeId: string,
|
|
217
|
+
templateType: string,
|
|
218
|
+
inflateMethod: MappingInflateMethod,
|
|
219
|
+
) {
|
|
220
|
+
maybeInit();
|
|
221
|
+
createRunInWishlistFn(() => {
|
|
222
|
+
'worklet';
|
|
223
|
+
getUIInflatorRegistry().registerMapping(
|
|
224
|
+
inflatorId,
|
|
225
|
+
nativeId,
|
|
226
|
+
templateType,
|
|
227
|
+
inflateMethod,
|
|
228
|
+
);
|
|
229
|
+
})();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface VisibleItem {
|
|
2
|
+
index: number;
|
|
3
|
+
key: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ViewportObserver {
|
|
6
|
+
markItemsDirty: (indices: Array<number>) => void;
|
|
7
|
+
markAllItemsDirty: () => void;
|
|
8
|
+
getAllVisibleItems: () => Array<VisibleItem>;
|
|
9
|
+
updateIndices: (newIndex: number) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function scheduleSyncUp(wishlistId: string) {
|
|
13
|
+
'worklet';
|
|
14
|
+
global.wishlists[wishlistId].scheduleSyncUp();
|
|
15
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ViewProps } from 'react-native';
|
|
2
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
3
|
+
|
|
4
|
+
export interface NativeContentContainerProps extends ViewProps {}
|
|
5
|
+
|
|
6
|
+
export default codegenNativeComponent<NativeContentContainerProps>(
|
|
7
|
+
'MGContentContainer',
|
|
8
|
+
{ interfaceOnly: true },
|
|
9
|
+
);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ViewProps } from 'react-native';
|
|
2
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
3
|
+
|
|
4
|
+
export interface NativeTemplateContainerProps extends ViewProps {
|
|
5
|
+
inflatorId: string;
|
|
6
|
+
wishlistId: string;
|
|
7
|
+
names: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default codegenNativeComponent<NativeTemplateContainerProps>(
|
|
11
|
+
'MGTemplateContainer',
|
|
12
|
+
{ interfaceOnly: true },
|
|
13
|
+
);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ViewProps } from 'react-native';
|
|
2
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
3
|
+
|
|
4
|
+
export interface NativeTemplateInterceptorProps extends ViewProps {}
|
|
5
|
+
|
|
6
|
+
export default codegenNativeComponent<NativeTemplateInterceptorProps>(
|
|
7
|
+
'MGTemplateInterceptor',
|
|
8
|
+
);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { ViewProps } from 'react-native';
|
|
3
|
+
import type {
|
|
4
|
+
DirectEventHandler,
|
|
5
|
+
Double,
|
|
6
|
+
Int32,
|
|
7
|
+
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
8
|
+
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
|
|
9
|
+
import codegenNativeComponent, {
|
|
10
|
+
NativeComponentType,
|
|
11
|
+
} from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
12
|
+
|
|
13
|
+
export type EventInFile = Readonly<{
|
|
14
|
+
value: Double;
|
|
15
|
+
}>;
|
|
16
|
+
|
|
17
|
+
export interface WishlistProps extends ViewProps {
|
|
18
|
+
inflatorId: string;
|
|
19
|
+
initialIndex: Int32;
|
|
20
|
+
onStartReached?: DirectEventHandler<Readonly<{}>>;
|
|
21
|
+
onEndReached?: DirectEventHandler<Readonly<{}>>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type NativeType = NativeComponentType<WishlistProps>;
|
|
25
|
+
|
|
26
|
+
export type ScrollToItem = (
|
|
27
|
+
viewRef: React.ElementRef<NativeType>,
|
|
28
|
+
index: Int32,
|
|
29
|
+
animated: boolean,
|
|
30
|
+
) => void;
|
|
31
|
+
|
|
32
|
+
interface NativeCommands {
|
|
33
|
+
readonly scrollToItem: ScrollToItem;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const Commands = codegenNativeCommands<NativeCommands>({
|
|
37
|
+
supportedCommands: ['scrollToItem'],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export default codegenNativeComponent<WishlistProps>('MGWishlist', {
|
|
41
|
+
interfaceOnly: true,
|
|
42
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
export const TemplateContext = createContext<{
|
|
4
|
+
templateType: string;
|
|
5
|
+
renderChildren?: boolean;
|
|
6
|
+
} | null>(null);
|
|
7
|
+
|
|
8
|
+
export function useTemplateContext() {
|
|
9
|
+
const context = useContext(TemplateContext);
|
|
10
|
+
if (!context) {
|
|
11
|
+
throw Error('Must be rendered inside a Template component.');
|
|
12
|
+
}
|
|
13
|
+
return context;
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type TemplateItem = {
|
|
2
|
+
[key: string]: TemplateItem | undefined;
|
|
3
|
+
} & {
|
|
4
|
+
key: string;
|
|
5
|
+
type: string;
|
|
6
|
+
getByWishId: (id: string) => TemplateItem | undefined;
|
|
7
|
+
addProps: (props: any) => void;
|
|
8
|
+
setCallback: (
|
|
9
|
+
eventName: string,
|
|
10
|
+
callback: (nativeEvent: any) => void,
|
|
11
|
+
) => void;
|
|
12
|
+
describe: () => string;
|
|
13
|
+
setChildren: (children: TemplateItem[]) => void;
|
|
14
|
+
getTag: () => number;
|
|
15
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { useEffect, useMemo } from 'react';
|
|
2
|
+
import { getUIInflatorRegistry } from './InflatorRepository';
|
|
3
|
+
import { generateId } from './Utils';
|
|
4
|
+
import { createRunInWishlistFn } from './WishlistJsRuntime';
|
|
5
|
+
|
|
6
|
+
export type TemplateValueMapper<ItemT, ValueT> = (
|
|
7
|
+
item: ItemT,
|
|
8
|
+
rootValue: any,
|
|
9
|
+
) => ValueT;
|
|
10
|
+
|
|
11
|
+
// Object cloned by reanimated are feezed so we store mutation state in a
|
|
12
|
+
// side map.
|
|
13
|
+
export type TemplateValueUIState = {
|
|
14
|
+
current: any;
|
|
15
|
+
dirty: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type TemplateValue<ValueT> = {
|
|
19
|
+
value: () => ValueT;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type TemplateValueInternal<ValueT> = TemplateValue<ValueT> & {
|
|
23
|
+
__isTemplateValue: boolean;
|
|
24
|
+
__remove: () => void;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export function createTemplateValue<ValueT>(
|
|
28
|
+
mapper: TemplateValueMapper<any, ValueT>,
|
|
29
|
+
): TemplateValueInternal<ValueT> {
|
|
30
|
+
const id = generateId();
|
|
31
|
+
|
|
32
|
+
function getOrCreateUIState() {
|
|
33
|
+
'worklet';
|
|
34
|
+
|
|
35
|
+
const registry = getUIInflatorRegistry();
|
|
36
|
+
let state = registry.getTemplateValueState(id);
|
|
37
|
+
if (!state) {
|
|
38
|
+
state = {
|
|
39
|
+
dirty: true,
|
|
40
|
+
current: undefined,
|
|
41
|
+
};
|
|
42
|
+
registry.setTemplateValueState(id, state);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return state;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function value() {
|
|
49
|
+
'worklet';
|
|
50
|
+
|
|
51
|
+
const registry = getUIInflatorRegistry();
|
|
52
|
+
const state = getOrCreateUIState();
|
|
53
|
+
if (state.dirty) {
|
|
54
|
+
state.current = mapper(
|
|
55
|
+
registry.getCurrentValue(),
|
|
56
|
+
registry.getCurrentRootValue(),
|
|
57
|
+
);
|
|
58
|
+
state.dirty = false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return state.current;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function remove() {
|
|
65
|
+
createRunInWishlistFn(() => {
|
|
66
|
+
'worklet';
|
|
67
|
+
|
|
68
|
+
getUIInflatorRegistry().deleteTemplateValueState(id);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
__isTemplateValue: true,
|
|
74
|
+
__remove: remove,
|
|
75
|
+
value,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function isTemplateValue(
|
|
80
|
+
value: unknown,
|
|
81
|
+
): value is TemplateValueInternal<any> {
|
|
82
|
+
return (
|
|
83
|
+
value !== null &&
|
|
84
|
+
typeof value === 'object' &&
|
|
85
|
+
(value as any).__isTemplateValue === true
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function useTemplateValue<ItemT, ValueT>(
|
|
90
|
+
mapper: TemplateValueMapper<ItemT, ValueT>,
|
|
91
|
+
): TemplateValue<ValueT> {
|
|
92
|
+
const value = useMemo(() => {
|
|
93
|
+
return createTemplateValue(mapper);
|
|
94
|
+
}, [mapper]);
|
|
95
|
+
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
return () => value.__remove();
|
|
98
|
+
}, [value]);
|
|
99
|
+
|
|
100
|
+
return value;
|
|
101
|
+
}
|
package/src/Utils.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
let idGenerator = 0;
|
|
4
|
+
|
|
5
|
+
export function generateId(): string {
|
|
6
|
+
return `id_${idGenerator++}`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function useGeneratedId(): string {
|
|
10
|
+
const ref = useRef<string | null>(null);
|
|
11
|
+
if (ref.current === null) {
|
|
12
|
+
ref.current = generateId();
|
|
13
|
+
}
|
|
14
|
+
return ref.current;
|
|
15
|
+
}
|