@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
package/src/Colors.ts
ADDED
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
/* eslint-disable no-bitwise */
|
|
2
|
+
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
|
|
5
|
+
const IS_ANDROID = Platform.OS === 'android';
|
|
6
|
+
|
|
7
|
+
interface ColorsUIModule {
|
|
8
|
+
colorProps: string[];
|
|
9
|
+
processColor(color: unknown): number | null | undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function createColorsUIModule(): ColorsUIModule {
|
|
13
|
+
'worklet';
|
|
14
|
+
|
|
15
|
+
// copied from react-native/Libraries/Components/View/ReactNativeStyleAttributes
|
|
16
|
+
const colorProps = [
|
|
17
|
+
'backgroundColor',
|
|
18
|
+
'borderBottomColor',
|
|
19
|
+
'borderColor',
|
|
20
|
+
'borderLeftColor',
|
|
21
|
+
'borderRightColor',
|
|
22
|
+
'borderTopColor',
|
|
23
|
+
'borderStartColor',
|
|
24
|
+
'borderEndColor',
|
|
25
|
+
'color',
|
|
26
|
+
'shadowColor',
|
|
27
|
+
'textDecorationColor',
|
|
28
|
+
'tintColor',
|
|
29
|
+
'textShadowColor',
|
|
30
|
+
'overlayColor',
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Copied from:
|
|
35
|
+
* https://github.com/software-mansion/react-native-reanimated/blob/main/src/reanimated2/Colors.ts
|
|
36
|
+
* react-native/Libraries/StyleSheet/normalizeColor.js
|
|
37
|
+
* react-native/Libraries/StyleSheet/processColor.js
|
|
38
|
+
* https://github.com/wcandillon/react-native-redash/blob/master/src/Colors.ts
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
const NUMBER = '[-+]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)';
|
|
42
|
+
const PERCENTAGE = NUMBER + '%';
|
|
43
|
+
|
|
44
|
+
function call(...args: unknown[]): string {
|
|
45
|
+
return '\\(\\s*(' + args.join(')\\s*,\\s*(') + ')\\s*\\)';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const cachedMatchers: Matchers = {};
|
|
49
|
+
type Matchers = {
|
|
50
|
+
rgb?: RegExp;
|
|
51
|
+
rgba?: RegExp;
|
|
52
|
+
hsl?: RegExp;
|
|
53
|
+
hsla?: RegExp;
|
|
54
|
+
hex3?: RegExp;
|
|
55
|
+
hex4?: RegExp;
|
|
56
|
+
hex5?: RegExp;
|
|
57
|
+
hex6?: RegExp;
|
|
58
|
+
hex8?: RegExp;
|
|
59
|
+
};
|
|
60
|
+
function getMatchers(): Matchers {
|
|
61
|
+
if (cachedMatchers.rgb === undefined) {
|
|
62
|
+
cachedMatchers.rgb = new RegExp('rgb' + call(NUMBER, NUMBER, NUMBER));
|
|
63
|
+
cachedMatchers.rgba = new RegExp(
|
|
64
|
+
'rgba' + call(NUMBER, NUMBER, NUMBER, NUMBER),
|
|
65
|
+
);
|
|
66
|
+
cachedMatchers.hsl = new RegExp(
|
|
67
|
+
'hsl' + call(NUMBER, PERCENTAGE, PERCENTAGE),
|
|
68
|
+
);
|
|
69
|
+
cachedMatchers.hsla = new RegExp(
|
|
70
|
+
'hsla' + call(NUMBER, PERCENTAGE, PERCENTAGE, NUMBER),
|
|
71
|
+
);
|
|
72
|
+
cachedMatchers.hex3 =
|
|
73
|
+
/^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
|
|
74
|
+
cachedMatchers.hex4 =
|
|
75
|
+
/^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
|
|
76
|
+
cachedMatchers.hex6 = /^#([0-9a-fA-F]{6})$/;
|
|
77
|
+
cachedMatchers.hex8 = /^#([0-9a-fA-F]{8})$/;
|
|
78
|
+
}
|
|
79
|
+
return cachedMatchers;
|
|
80
|
+
}
|
|
81
|
+
// cachedMatchers is lazy loaded and it is frozen when worklet is being created,
|
|
82
|
+
// it is possible to call getMatchers() when the object is frozen, then cachedMatchers
|
|
83
|
+
// has no assigned regexes
|
|
84
|
+
getMatchers();
|
|
85
|
+
|
|
86
|
+
function hue2rgb(p: number, q: number, t: number): number {
|
|
87
|
+
if (t < 0) {
|
|
88
|
+
t += 1;
|
|
89
|
+
}
|
|
90
|
+
if (t > 1) {
|
|
91
|
+
t -= 1;
|
|
92
|
+
}
|
|
93
|
+
if (t < 1 / 6) {
|
|
94
|
+
return p + (q - p) * 6 * t;
|
|
95
|
+
}
|
|
96
|
+
if (t < 1 / 2) {
|
|
97
|
+
return q;
|
|
98
|
+
}
|
|
99
|
+
if (t < 2 / 3) {
|
|
100
|
+
return p + (q - p) * (2 / 3 - t) * 6;
|
|
101
|
+
}
|
|
102
|
+
return p;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function hslToRgb(h: number, s: number, l: number): number {
|
|
106
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
107
|
+
const p = 2 * l - q;
|
|
108
|
+
const r = hue2rgb(p, q, h + 1 / 3);
|
|
109
|
+
const g = hue2rgb(p, q, h);
|
|
110
|
+
const b = hue2rgb(p, q, h - 1 / 3);
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
(Math.round(r * 255) << 24) |
|
|
114
|
+
(Math.round(g * 255) << 16) |
|
|
115
|
+
(Math.round(b * 255) << 8)
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function parse255(str: string): number {
|
|
120
|
+
const int = Number.parseInt(str, 10);
|
|
121
|
+
if (int < 0) {
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
if (int > 255) {
|
|
125
|
+
return 255;
|
|
126
|
+
}
|
|
127
|
+
return int;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function parse360(str: string): number {
|
|
131
|
+
const int = Number.parseFloat(str);
|
|
132
|
+
return (((int % 360) + 360) % 360) / 360;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function parse1(str: string): number {
|
|
136
|
+
const num = Number.parseFloat(str);
|
|
137
|
+
if (num < 0) {
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
if (num > 1) {
|
|
141
|
+
return 255;
|
|
142
|
+
}
|
|
143
|
+
return Math.round(num * 255);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function parsePercentage(str: string): number {
|
|
147
|
+
// parseFloat conveniently ignores the final %
|
|
148
|
+
const int = Number.parseFloat(str);
|
|
149
|
+
if (int < 0) {
|
|
150
|
+
return 0;
|
|
151
|
+
}
|
|
152
|
+
if (int > 100) {
|
|
153
|
+
return 1;
|
|
154
|
+
}
|
|
155
|
+
return int / 100;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const names: any = {
|
|
159
|
+
transparent: 0x00000000,
|
|
160
|
+
|
|
161
|
+
// http://www.w3.org/TR/css3-color/#svg-color
|
|
162
|
+
aliceblue: 0xf0f8ffff,
|
|
163
|
+
antiquewhite: 0xfaebd7ff,
|
|
164
|
+
aqua: 0x00ffffff,
|
|
165
|
+
aquamarine: 0x7fffd4ff,
|
|
166
|
+
azure: 0xf0ffffff,
|
|
167
|
+
beige: 0xf5f5dcff,
|
|
168
|
+
bisque: 0xffe4c4ff,
|
|
169
|
+
black: 0x000000ff,
|
|
170
|
+
blanchedalmond: 0xffebcdff,
|
|
171
|
+
blue: 0x0000ffff,
|
|
172
|
+
blueviolet: 0x8a2be2ff,
|
|
173
|
+
brown: 0xa52a2aff,
|
|
174
|
+
burlywood: 0xdeb887ff,
|
|
175
|
+
burntsienna: 0xea7e5dff,
|
|
176
|
+
cadetblue: 0x5f9ea0ff,
|
|
177
|
+
chartreuse: 0x7fff00ff,
|
|
178
|
+
chocolate: 0xd2691eff,
|
|
179
|
+
coral: 0xff7f50ff,
|
|
180
|
+
cornflowerblue: 0x6495edff,
|
|
181
|
+
cornsilk: 0xfff8dcff,
|
|
182
|
+
crimson: 0xdc143cff,
|
|
183
|
+
cyan: 0x00ffffff,
|
|
184
|
+
darkblue: 0x00008bff,
|
|
185
|
+
darkcyan: 0x008b8bff,
|
|
186
|
+
darkgoldenrod: 0xb8860bff,
|
|
187
|
+
darkgray: 0xa9a9a9ff,
|
|
188
|
+
darkgreen: 0x006400ff,
|
|
189
|
+
darkgrey: 0xa9a9a9ff,
|
|
190
|
+
darkkhaki: 0xbdb76bff,
|
|
191
|
+
darkmagenta: 0x8b008bff,
|
|
192
|
+
darkolivegreen: 0x556b2fff,
|
|
193
|
+
darkorange: 0xff8c00ff,
|
|
194
|
+
darkorchid: 0x9932ccff,
|
|
195
|
+
darkred: 0x8b0000ff,
|
|
196
|
+
darksalmon: 0xe9967aff,
|
|
197
|
+
darkseagreen: 0x8fbc8fff,
|
|
198
|
+
darkslateblue: 0x483d8bff,
|
|
199
|
+
darkslategray: 0x2f4f4fff,
|
|
200
|
+
darkslategrey: 0x2f4f4fff,
|
|
201
|
+
darkturquoise: 0x00ced1ff,
|
|
202
|
+
darkviolet: 0x9400d3ff,
|
|
203
|
+
deeppink: 0xff1493ff,
|
|
204
|
+
deepskyblue: 0x00bfffff,
|
|
205
|
+
dimgray: 0x696969ff,
|
|
206
|
+
dimgrey: 0x696969ff,
|
|
207
|
+
dodgerblue: 0x1e90ffff,
|
|
208
|
+
firebrick: 0xb22222ff,
|
|
209
|
+
floralwhite: 0xfffaf0ff,
|
|
210
|
+
forestgreen: 0x228b22ff,
|
|
211
|
+
fuchsia: 0xff00ffff,
|
|
212
|
+
gainsboro: 0xdcdcdcff,
|
|
213
|
+
ghostwhite: 0xf8f8ffff,
|
|
214
|
+
gold: 0xffd700ff,
|
|
215
|
+
goldenrod: 0xdaa520ff,
|
|
216
|
+
gray: 0x808080ff,
|
|
217
|
+
green: 0x008000ff,
|
|
218
|
+
greenyellow: 0xadff2fff,
|
|
219
|
+
grey: 0x808080ff,
|
|
220
|
+
honeydew: 0xf0fff0ff,
|
|
221
|
+
hotpink: 0xff69b4ff,
|
|
222
|
+
indianred: 0xcd5c5cff,
|
|
223
|
+
indigo: 0x4b0082ff,
|
|
224
|
+
ivory: 0xfffff0ff,
|
|
225
|
+
khaki: 0xf0e68cff,
|
|
226
|
+
lavender: 0xe6e6faff,
|
|
227
|
+
lavenderblush: 0xfff0f5ff,
|
|
228
|
+
lawngreen: 0x7cfc00ff,
|
|
229
|
+
lemonchiffon: 0xfffacdff,
|
|
230
|
+
lightblue: 0xadd8e6ff,
|
|
231
|
+
lightcoral: 0xf08080ff,
|
|
232
|
+
lightcyan: 0xe0ffffff,
|
|
233
|
+
lightgoldenrodyellow: 0xfafad2ff,
|
|
234
|
+
lightgray: 0xd3d3d3ff,
|
|
235
|
+
lightgreen: 0x90ee90ff,
|
|
236
|
+
lightgrey: 0xd3d3d3ff,
|
|
237
|
+
lightpink: 0xffb6c1ff,
|
|
238
|
+
lightsalmon: 0xffa07aff,
|
|
239
|
+
lightseagreen: 0x20b2aaff,
|
|
240
|
+
lightskyblue: 0x87cefaff,
|
|
241
|
+
lightslategray: 0x778899ff,
|
|
242
|
+
lightslategrey: 0x778899ff,
|
|
243
|
+
lightsteelblue: 0xb0c4deff,
|
|
244
|
+
lightyellow: 0xffffe0ff,
|
|
245
|
+
lime: 0x00ff00ff,
|
|
246
|
+
limegreen: 0x32cd32ff,
|
|
247
|
+
linen: 0xfaf0e6ff,
|
|
248
|
+
magenta: 0xff00ffff,
|
|
249
|
+
maroon: 0x800000ff,
|
|
250
|
+
mediumaquamarine: 0x66cdaaff,
|
|
251
|
+
mediumblue: 0x0000cdff,
|
|
252
|
+
mediumorchid: 0xba55d3ff,
|
|
253
|
+
mediumpurple: 0x9370dbff,
|
|
254
|
+
mediumseagreen: 0x3cb371ff,
|
|
255
|
+
mediumslateblue: 0x7b68eeff,
|
|
256
|
+
mediumspringgreen: 0x00fa9aff,
|
|
257
|
+
mediumturquoise: 0x48d1ccff,
|
|
258
|
+
mediumvioletred: 0xc71585ff,
|
|
259
|
+
midnightblue: 0x191970ff,
|
|
260
|
+
mintcream: 0xf5fffaff,
|
|
261
|
+
mistyrose: 0xffe4e1ff,
|
|
262
|
+
moccasin: 0xffe4b5ff,
|
|
263
|
+
navajowhite: 0xffdeadff,
|
|
264
|
+
navy: 0x000080ff,
|
|
265
|
+
oldlace: 0xfdf5e6ff,
|
|
266
|
+
olive: 0x808000ff,
|
|
267
|
+
olivedrab: 0x6b8e23ff,
|
|
268
|
+
orange: 0xffa500ff,
|
|
269
|
+
orangered: 0xff4500ff,
|
|
270
|
+
orchid: 0xda70d6ff,
|
|
271
|
+
palegoldenrod: 0xeee8aaff,
|
|
272
|
+
palegreen: 0x98fb98ff,
|
|
273
|
+
paleturquoise: 0xafeeeeff,
|
|
274
|
+
palevioletred: 0xdb7093ff,
|
|
275
|
+
papayawhip: 0xffefd5ff,
|
|
276
|
+
peachpuff: 0xffdab9ff,
|
|
277
|
+
peru: 0xcd853fff,
|
|
278
|
+
pink: 0xffc0cbff,
|
|
279
|
+
plum: 0xdda0ddff,
|
|
280
|
+
powderblue: 0xb0e0e6ff,
|
|
281
|
+
purple: 0x800080ff,
|
|
282
|
+
rebeccapurple: 0x663399ff,
|
|
283
|
+
red: 0xff0000ff,
|
|
284
|
+
rosybrown: 0xbc8f8fff,
|
|
285
|
+
royalblue: 0x4169e1ff,
|
|
286
|
+
saddlebrown: 0x8b4513ff,
|
|
287
|
+
salmon: 0xfa8072ff,
|
|
288
|
+
sandybrown: 0xf4a460ff,
|
|
289
|
+
seagreen: 0x2e8b57ff,
|
|
290
|
+
seashell: 0xfff5eeff,
|
|
291
|
+
sienna: 0xa0522dff,
|
|
292
|
+
silver: 0xc0c0c0ff,
|
|
293
|
+
skyblue: 0x87ceebff,
|
|
294
|
+
slateblue: 0x6a5acdff,
|
|
295
|
+
slategray: 0x708090ff,
|
|
296
|
+
slategrey: 0x708090ff,
|
|
297
|
+
snow: 0xfffafaff,
|
|
298
|
+
springgreen: 0x00ff7fff,
|
|
299
|
+
steelblue: 0x4682b4ff,
|
|
300
|
+
tan: 0xd2b48cff,
|
|
301
|
+
teal: 0x008080ff,
|
|
302
|
+
thistle: 0xd8bfd8ff,
|
|
303
|
+
tomato: 0xff6347ff,
|
|
304
|
+
turquoise: 0x40e0d0ff,
|
|
305
|
+
violet: 0xee82eeff,
|
|
306
|
+
wheat: 0xf5deb3ff,
|
|
307
|
+
white: 0xffffffff,
|
|
308
|
+
whitesmoke: 0xf5f5f5ff,
|
|
309
|
+
yellow: 0xffff00ff,
|
|
310
|
+
yellowgreen: 0x9acd32ff,
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
function normalizeColor(color: unknown): number | null {
|
|
314
|
+
if (typeof color === 'number') {
|
|
315
|
+
if (color >>> 0 === color && color >= 0 && color <= 0xffffffff) {
|
|
316
|
+
return color;
|
|
317
|
+
}
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (typeof color !== 'string') {
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const matchers = getMatchers();
|
|
326
|
+
|
|
327
|
+
let match: RegExpExecArray | null | undefined;
|
|
328
|
+
|
|
329
|
+
// Ordered based on occurrences on Facebook codebase
|
|
330
|
+
if ((match = matchers?.hex6?.exec(color))) {
|
|
331
|
+
return Number.parseInt(match[1] + 'ff', 16) >>> 0;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (names[color] !== undefined) {
|
|
335
|
+
return names[color];
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if ((match = matchers?.rgb?.exec(color))) {
|
|
339
|
+
return (
|
|
340
|
+
// b
|
|
341
|
+
((parse255(match[1]) << 24) | // r
|
|
342
|
+
(parse255(match[2]) << 16) | // g
|
|
343
|
+
(parse255(match[3]) << 8) |
|
|
344
|
+
0x000000ff) >>> // a
|
|
345
|
+
0
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if ((match = matchers?.rgba?.exec(color))) {
|
|
350
|
+
return (
|
|
351
|
+
// b
|
|
352
|
+
((parse255(match[1]) << 24) | // r
|
|
353
|
+
(parse255(match[2]) << 16) | // g
|
|
354
|
+
(parse255(match[3]) << 8) |
|
|
355
|
+
parse1(match[4])) >>> // a
|
|
356
|
+
0
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if ((match = matchers?.hex3?.exec(color))) {
|
|
361
|
+
return (
|
|
362
|
+
Number.parseInt(
|
|
363
|
+
match[1] +
|
|
364
|
+
match[1] + // r
|
|
365
|
+
match[2] +
|
|
366
|
+
match[2] + // g
|
|
367
|
+
match[3] +
|
|
368
|
+
match[3] + // b
|
|
369
|
+
'ff', // a
|
|
370
|
+
16,
|
|
371
|
+
) >>> 0
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// https://drafts.csswg.org/css-color-4/#hex-notation
|
|
376
|
+
if ((match = matchers?.hex8?.exec(color))) {
|
|
377
|
+
return Number.parseInt(match[1], 16) >>> 0;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if ((match = matchers?.hex4?.exec(color))) {
|
|
381
|
+
return (
|
|
382
|
+
Number.parseInt(
|
|
383
|
+
match[1] +
|
|
384
|
+
match[1] + // r
|
|
385
|
+
match[2] +
|
|
386
|
+
match[2] + // g
|
|
387
|
+
match[3] +
|
|
388
|
+
match[3] + // b
|
|
389
|
+
match[4] +
|
|
390
|
+
match[4], // a
|
|
391
|
+
16,
|
|
392
|
+
) >>> 0
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if ((match = matchers?.hsl?.exec(color))) {
|
|
397
|
+
return (
|
|
398
|
+
(hslToRgb(
|
|
399
|
+
parse360(match[1]), // h
|
|
400
|
+
parsePercentage(match[2]), // s
|
|
401
|
+
parsePercentage(match[3]), // l
|
|
402
|
+
) |
|
|
403
|
+
0x000000ff) >>> // a
|
|
404
|
+
0
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if ((match = matchers?.hsla?.exec(color))) {
|
|
409
|
+
return (
|
|
410
|
+
(hslToRgb(
|
|
411
|
+
parse360(match[1]), // h
|
|
412
|
+
parsePercentage(match[2]), // s
|
|
413
|
+
parsePercentage(match[3]), // l
|
|
414
|
+
) |
|
|
415
|
+
parse1(match[4])) >>> // a
|
|
416
|
+
0
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return null;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function processColorInitially(color: unknown): number | null | undefined {
|
|
424
|
+
if (color === null || color === undefined || typeof color === 'number') {
|
|
425
|
+
return color;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
let normalizedColor = normalizeColor(color);
|
|
429
|
+
|
|
430
|
+
if (normalizedColor === null || normalizedColor === undefined) {
|
|
431
|
+
return undefined;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (typeof normalizedColor !== 'number') {
|
|
435
|
+
return null;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
normalizedColor = ((normalizedColor << 24) | (normalizedColor >>> 8)) >>> 0; // argb
|
|
439
|
+
return normalizedColor;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function processColor(color: unknown): number | null | undefined {
|
|
443
|
+
let normalizedColor = processColorInitially(color);
|
|
444
|
+
if (normalizedColor === null || normalizedColor === undefined) {
|
|
445
|
+
return undefined;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
if (typeof normalizedColor !== 'number') {
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
if (IS_ANDROID) {
|
|
453
|
+
// Android use 32 bit *signed* integer to represent the color
|
|
454
|
+
// We utilize the fact that bitwise operations in JS also operates on
|
|
455
|
+
// signed 32 bit integers, so that we can use those to convert from
|
|
456
|
+
// *unsigned* to *signed* 32bit int that way.
|
|
457
|
+
normalizedColor = normalizedColor | 0x0;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
return normalizedColor;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return { processColor, colorProps };
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export function getColorsUIModule(): ColorsUIModule {
|
|
467
|
+
'worklet';
|
|
468
|
+
|
|
469
|
+
if (!global.__wishlistColors) {
|
|
470
|
+
global.__wishlistColors = createColorsUIModule();
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
return global.__wishlistColors;
|
|
474
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { TemplateItem } from './TemplateItem';
|
|
2
|
+
|
|
3
|
+
export type NodeType = 'View' | 'Text' | 'Paragraph' | 'RawText';
|
|
4
|
+
|
|
5
|
+
export type NativeComponentPool = {
|
|
6
|
+
getComponent: (id: string) => TemplateItem | undefined;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type ComponentPool = NativeComponentPool & {
|
|
10
|
+
createNode(type: NodeType): TemplateItem;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function wrapComponentPool(pool: NativeComponentPool): ComponentPool {
|
|
14
|
+
'worklet';
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
getComponent: pool.getComponent,
|
|
18
|
+
createNode(type) {
|
|
19
|
+
switch (type) {
|
|
20
|
+
case 'Paragraph':
|
|
21
|
+
return pool.getComponent('__paragraphComponent')!.Paragraph!;
|
|
22
|
+
case 'Text':
|
|
23
|
+
return pool.getComponent('__textComponent')!.Paragraph!.Text!;
|
|
24
|
+
case 'RawText':
|
|
25
|
+
return pool.getComponent('__paragraphComponent')!.Paragraph!.RawText!;
|
|
26
|
+
case 'View':
|
|
27
|
+
return pool.getComponent('__viewComponent')!;
|
|
28
|
+
default:
|
|
29
|
+
throw new Error(`Unknown node type ${type}`);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { renderTemplate } from '../renderTemplate';
|
|
2
|
+
import { createTemplateComponent } from '../createTemplateComponent';
|
|
3
|
+
import { ForEachBase } from './ForEachBase';
|
|
4
|
+
|
|
5
|
+
export const ForEach = createTemplateComponent(ForEachBase, {
|
|
6
|
+
addProps: (item, props, inflatorId, pool, rootValue) => {
|
|
7
|
+
'worklet';
|
|
8
|
+
|
|
9
|
+
const subItems: unknown[] = props.items;
|
|
10
|
+
const items = subItems.map((subItem) => {
|
|
11
|
+
return renderTemplate(
|
|
12
|
+
props.template,
|
|
13
|
+
subItem,
|
|
14
|
+
rootValue,
|
|
15
|
+
inflatorId,
|
|
16
|
+
pool,
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
item.setChildren(items);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { createTemplateComponent } from '../createTemplateComponent';
|
|
4
|
+
|
|
5
|
+
const IFTemplateComponent = createTemplateComponent(View, {
|
|
6
|
+
addProps: (item, props) => {
|
|
7
|
+
'worklet';
|
|
8
|
+
|
|
9
|
+
if (props.condition) {
|
|
10
|
+
item.addProps({ display: 'flex' });
|
|
11
|
+
} else {
|
|
12
|
+
item.addProps({ display: 'none' });
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// TODO(terry): Fix IF props type
|
|
18
|
+
export function IF(props: any) {
|
|
19
|
+
return <IFTemplateComponent {...props} />;
|
|
20
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { NativeModules, View, ViewProps } from 'react-native';
|
|
3
|
+
import { createTemplateComponent } from '../createTemplateComponent';
|
|
4
|
+
import { useTemplateCallback } from '../EventHandler';
|
|
5
|
+
import { getUIInflatorRegistry } from '../InflatorRepository';
|
|
6
|
+
import { createRunInJsFn } from '../WishlistJsRuntime';
|
|
7
|
+
|
|
8
|
+
// TODO(janic): Figure out why those cannot be imported directly from RNGH in the example app.
|
|
9
|
+
const ActionType = {
|
|
10
|
+
REANIMATED_WORKLET: 1,
|
|
11
|
+
NATIVE_ANIMATED_EVENT: 2,
|
|
12
|
+
JS_FUNCTION_OLD_API: 3,
|
|
13
|
+
JS_FUNCTION_NEW_API: 4,
|
|
14
|
+
DIRECT_EVENT: 5,
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
type ActionTypeT = (typeof ActionType)[keyof typeof ActionType];
|
|
18
|
+
|
|
19
|
+
type RNGestureHandlerModuleProps = {
|
|
20
|
+
handleSetJSResponder: (tag: number, blockNativeResponder: boolean) => void;
|
|
21
|
+
handleClearJSResponder: () => void;
|
|
22
|
+
createGestureHandler: (
|
|
23
|
+
handlerName: string,
|
|
24
|
+
handlerTag: number,
|
|
25
|
+
config: Readonly<Record<string, unknown>>,
|
|
26
|
+
) => void;
|
|
27
|
+
attachGestureHandler: (
|
|
28
|
+
handlerTag: number,
|
|
29
|
+
newView: number,
|
|
30
|
+
actionType: ActionTypeT,
|
|
31
|
+
) => void;
|
|
32
|
+
updateGestureHandler: (
|
|
33
|
+
handlerTag: number,
|
|
34
|
+
newConfig: Readonly<Record<string, unknown>>,
|
|
35
|
+
) => void;
|
|
36
|
+
dropGestureHandler: (handlerTag: number) => void;
|
|
37
|
+
install: () => void;
|
|
38
|
+
flushOperations: () => void;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
let _handlerTag = 1000;
|
|
42
|
+
|
|
43
|
+
export function getNextHandlerTag(): number {
|
|
44
|
+
return _handlerTag++;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const RNGestureHandlerModule: RNGestureHandlerModuleProps =
|
|
48
|
+
NativeModules.RNGestureHandlerModule;
|
|
49
|
+
|
|
50
|
+
export const State = {
|
|
51
|
+
UNDETERMINED: 0,
|
|
52
|
+
FAILED: 1,
|
|
53
|
+
BEGAN: 2,
|
|
54
|
+
CANCELLED: 3,
|
|
55
|
+
ACTIVE: 4,
|
|
56
|
+
END: 5,
|
|
57
|
+
} as const;
|
|
58
|
+
|
|
59
|
+
type PressableProps = ViewProps & {
|
|
60
|
+
onPress?: ((item: any, rootItem: any) => void) | null;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const attachGestureHandler = createRunInJsFn((tag: number) => {
|
|
64
|
+
// TODO: Do we need to detach handlers?
|
|
65
|
+
const handlerTag = getNextHandlerTag();
|
|
66
|
+
RNGestureHandlerModule.createGestureHandler(
|
|
67
|
+
'TapGestureHandler',
|
|
68
|
+
handlerTag,
|
|
69
|
+
{},
|
|
70
|
+
);
|
|
71
|
+
RNGestureHandlerModule.attachGestureHandler(
|
|
72
|
+
handlerTag,
|
|
73
|
+
tag,
|
|
74
|
+
ActionType.DIRECT_EVENT,
|
|
75
|
+
);
|
|
76
|
+
RNGestureHandlerModule.flushOperations();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const PressableView = createTemplateComponent(View, {
|
|
80
|
+
addProps: (item, props) => {
|
|
81
|
+
'worklet';
|
|
82
|
+
|
|
83
|
+
const tag = item.getTag();
|
|
84
|
+
item.addProps(props);
|
|
85
|
+
|
|
86
|
+
getUIInflatorRegistry().addPushChildrenCallback(() => {
|
|
87
|
+
attachGestureHandler(tag);
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export const Pressable = forwardRef<any, PressableProps>(
|
|
93
|
+
({ onPress, ...others }, ref) => {
|
|
94
|
+
const onGestureEvent = useTemplateCallback((ev, item, rootItem) => {
|
|
95
|
+
'worklet';
|
|
96
|
+
|
|
97
|
+
if (ev.state === State.ACTIVE) {
|
|
98
|
+
onPress?.(item, rootItem);
|
|
99
|
+
}
|
|
100
|
+
}, 'onGestureHandlerStateChange');
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<PressableView
|
|
104
|
+
{...others}
|
|
105
|
+
// @ts-expect-error
|
|
106
|
+
onGestureEvent={onGestureEvent}
|
|
107
|
+
ref={ref}
|
|
108
|
+
/>
|
|
109
|
+
);
|
|
110
|
+
},
|
|
111
|
+
);
|