@shopify/react-native-skia 2.9.1 → 2.10.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/android/CMakeLists.txt +1 -5
- package/cpp/api/JsiNativeBuffer.h +15 -10
- package/cpp/api/JsiSkAnimatedImage.h +21 -19
- package/cpp/api/JsiSkAnimatedImageFactory.h +13 -14
- package/cpp/api/JsiSkApi.h +246 -92
- package/cpp/api/JsiSkCanvas.h +76 -58
- package/cpp/api/JsiSkColor.h +7 -5
- package/cpp/api/JsiSkColorFilter.h +15 -8
- package/cpp/api/JsiSkColorFilterFactory.h +45 -45
- package/cpp/api/JsiSkContourMeasure.h +24 -21
- package/cpp/api/JsiSkContourMeasureIter.h +18 -21
- package/cpp/api/JsiSkData.h +13 -7
- package/cpp/api/JsiSkDataFactory.h +22 -21
- package/cpp/api/JsiSkFont.h +56 -44
- package/cpp/api/JsiSkFontMgr.h +22 -13
- package/cpp/api/JsiSkFontMgrFactory.h +12 -10
- package/cpp/api/JsiSkFontStyle.h +14 -12
- package/cpp/api/JsiSkImage.h +45 -34
- package/cpp/api/JsiSkImageFactory.h +47 -52
- package/cpp/api/JsiSkImageFilter.h +21 -11
- package/cpp/api/JsiSkImageFilterFactory.h +96 -96
- package/cpp/api/JsiSkImageInfo.h +22 -19
- package/cpp/api/JsiSkMaskFilter.h +21 -11
- package/cpp/api/JsiSkMaskFilterFactory.h +16 -13
- package/cpp/api/JsiSkMatrix.h +31 -31
- package/cpp/api/JsiSkNativeObjects.h +419 -0
- package/cpp/api/JsiSkPaint.h +59 -39
- package/cpp/api/JsiSkParagraph.h +39 -32
- package/cpp/api/JsiSkParagraphBuilder.h +24 -21
- package/cpp/api/JsiSkParagraphBuilderFactory.h +13 -12
- package/cpp/api/JsiSkPath.h +95 -70
- package/cpp/api/JsiSkPathBuilder.h +83 -67
- package/cpp/api/JsiSkPathBuilderFactory.h +16 -17
- package/cpp/api/JsiSkPathEffect.h +21 -11
- package/cpp/api/JsiSkPathEffectFactory.h +33 -32
- package/cpp/api/JsiSkPathFactory.h +79 -103
- package/cpp/api/JsiSkPicture.h +24 -13
- package/cpp/api/JsiSkPictureFactory.h +21 -26
- package/cpp/api/JsiSkPictureRecorder.h +21 -22
- package/cpp/api/JsiSkPoint.h +19 -22
- package/cpp/api/JsiSkRRect.h +22 -29
- package/cpp/api/JsiSkRSXform.h +26 -30
- package/cpp/api/JsiSkRect.h +28 -30
- package/cpp/api/JsiSkRuntimeEffect.h +39 -30
- package/cpp/api/JsiSkRuntimeEffectFactory.h +12 -12
- package/cpp/api/JsiSkRuntimeShaderBuilder.h +25 -18
- package/cpp/api/JsiSkSVG.h +13 -13
- package/cpp/api/JsiSkSVGFactory.h +17 -20
- package/cpp/api/JsiSkShader.h +15 -8
- package/cpp/api/JsiSkShaderFactory.h +41 -48
- package/cpp/api/JsiSkSkottie.h +49 -39
- package/cpp/api/JsiSkSurface.h +24 -24
- package/cpp/api/JsiSkSurfaceFactory.h +15 -16
- package/cpp/api/JsiSkTextBlob.h +15 -8
- package/cpp/api/JsiSkTextBlobFactory.h +25 -28
- package/cpp/api/JsiSkTypeface.h +19 -12
- package/cpp/api/JsiSkTypefaceFactory.h +12 -12
- package/cpp/api/JsiSkTypefaceFontProvider.h +30 -25
- package/cpp/api/JsiSkTypefaceFontProviderFactory.h +14 -12
- package/cpp/api/JsiSkVertices.h +21 -18
- package/cpp/api/JsiSkiaContext.h +17 -17
- package/cpp/api/JsiSkottieFactory.h +16 -17
- package/cpp/api/JsiVideo.h +27 -25
- package/cpp/api/recorder/Convertor.h +31 -61
- package/cpp/api/recorder/DataTypes.h +8 -16
- package/cpp/api/recorder/JsiRecorder.h +83 -55
- package/cpp/api/recorder/RNRecorder.h +1 -1
- package/cpp/jsi/BoxedNativeObject.h +146 -0
- package/cpp/{jsi2 → jsi}/EnumMapper.h +4 -1
- package/cpp/{jsi2 → jsi}/NativeObject.h +120 -146
- package/cpp/jsi/RuntimeAwareCache.cpp +1 -1
- package/cpp/jsi/RuntimeAwareCache.h +26 -8
- package/cpp/jsi/ViewProperty.h +5 -11
- package/cpp/rnskia/RNSkJsiViewApi.h +20 -11
- package/cpp/rnskia/RNSkManager.cpp +23 -25
- package/cpp/rnskia/RNSkPictureView.h +1 -1
- package/cpp/rnwgpu/ArrayBuffer.h +5 -6
- package/cpp/rnwgpu/Canvas.h +4 -2
- package/cpp/rnwgpu/api/GPU.cpp +4 -4
- package/cpp/rnwgpu/api/GPU.h +1 -1
- package/cpp/rnwgpu/api/GPUAdapter.cpp +2 -3
- package/cpp/rnwgpu/api/GPUAdapter.h +4 -4
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +1 -1
- package/cpp/rnwgpu/api/GPUBindGroup.h +1 -1
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +1 -1
- package/cpp/rnwgpu/api/GPUBuffer.h +1 -1
- package/cpp/rnwgpu/api/GPUCanvasContext.h +1 -1
- package/cpp/rnwgpu/api/GPUCommandBuffer.h +1 -1
- package/cpp/rnwgpu/api/GPUCommandEncoder.h +1 -1
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +1 -1
- package/cpp/rnwgpu/api/GPUCompilationMessage.h +1 -1
- package/cpp/rnwgpu/api/GPUComputePassEncoder.h +1 -1
- package/cpp/rnwgpu/api/GPUComputePipeline.h +1 -1
- package/cpp/rnwgpu/api/GPUDevice.cpp +6 -7
- package/cpp/rnwgpu/api/GPUDevice.h +3 -3
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +1 -1
- package/cpp/rnwgpu/api/GPUError.h +1 -1
- package/cpp/rnwgpu/api/GPUExtent3D.h +1 -1
- package/cpp/rnwgpu/api/GPUExternalTexture.h +1 -1
- package/cpp/rnwgpu/api/GPUInternalError.h +1 -1
- package/cpp/rnwgpu/api/GPUOrigin2D.h +1 -1
- package/cpp/rnwgpu/api/GPUOrigin3D.h +1 -1
- package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +1 -1
- package/cpp/rnwgpu/api/GPUPipelineLayout.h +1 -1
- package/cpp/rnwgpu/api/GPUQuerySet.h +1 -1
- package/cpp/rnwgpu/api/GPUQueue.h +1 -1
- package/cpp/rnwgpu/api/GPURenderBundle.h +1 -1
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +1 -1
- package/cpp/rnwgpu/api/GPURenderPassEncoder.h +1 -1
- package/cpp/rnwgpu/api/GPURenderPipeline.h +1 -1
- package/cpp/rnwgpu/api/GPUSampler.h +1 -1
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +1 -1
- package/cpp/rnwgpu/api/GPUShaderModule.h +1 -1
- package/cpp/rnwgpu/api/GPUSharedFence.h +1 -1
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +1 -1
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +1 -1
- package/cpp/rnwgpu/api/GPUTexture.h +1 -1
- package/cpp/rnwgpu/api/GPUTextureView.h +1 -1
- package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +1 -1
- package/cpp/rnwgpu/api/GPUValidationError.h +1 -1
- package/cpp/rnwgpu/api/ImageBitmap.h +1 -1
- package/cpp/rnwgpu/api/RNWebGPU.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUColor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUDawnTogglesDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUSharedFenceDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUSharedFenceState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/Unions.h +1 -1
- package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +20 -21
- package/lib/commonjs/external/reanimated/renderHelpers.d.ts +15 -0
- package/lib/commonjs/external/reanimated/renderHelpers.js +30 -1
- package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -1
- package/lib/commonjs/skia/NativeSetup.js +4 -0
- package/lib/commonjs/skia/NativeSetup.js.map +1 -1
- package/lib/commonjs/skia/SkiaWorkletSerialization.d.ts +1 -0
- package/lib/commonjs/skia/SkiaWorkletSerialization.js +66 -0
- package/lib/commonjs/skia/SkiaWorkletSerialization.js.map +1 -0
- package/lib/commonjs/sksg/Container.native.js +20 -1
- package/lib/commonjs/sksg/Container.native.js.map +1 -1
- package/lib/module/external/reanimated/renderHelpers.d.ts +15 -0
- package/lib/module/external/reanimated/renderHelpers.js +29 -0
- package/lib/module/external/reanimated/renderHelpers.js.map +1 -1
- package/lib/module/skia/NativeSetup.js +4 -0
- package/lib/module/skia/NativeSetup.js.map +1 -1
- package/lib/module/skia/SkiaWorkletSerialization.d.ts +1 -0
- package/lib/module/skia/SkiaWorkletSerialization.js +59 -0
- package/lib/module/skia/SkiaWorkletSerialization.js.map +1 -0
- package/lib/module/sksg/Container.native.js +21 -2
- package/lib/module/sksg/Container.native.js.map +1 -1
- package/lib/typescript/lib/commonjs/external/reanimated/renderHelpers.d.ts +2 -0
- package/lib/typescript/lib/commonjs/skia/SkiaWorkletSerialization.d.ts +2 -0
- package/lib/typescript/lib/module/external/reanimated/renderHelpers.d.ts +15 -0
- package/lib/typescript/lib/module/skia/SkiaWorkletSerialization.d.ts +1 -0
- package/lib/typescript/src/external/reanimated/renderHelpers.d.ts +15 -0
- package/lib/typescript/src/skia/SkiaWorkletSerialization.d.ts +1 -0
- package/package.json +6 -2
- package/react-native-skia.podspec +1 -2
- package/src/external/reanimated/renderHelpers.ts +30 -0
- package/src/skia/NativeSetup.ts +5 -0
- package/src/skia/SkiaWorkletSerialization.ts +67 -0
- package/src/sksg/Container.native.ts +40 -2
- package/cpp/api/JsiSkHostObjects.h +0 -257
- package/cpp/jsi/JsiHostObject.cpp +0 -137
- package/cpp/jsi/JsiHostObject.h +0 -385
- /package/cpp/{jsi2 → jsi}/JSIConverter.h +0 -0
- /package/cpp/{jsi2 → jsi}/Promise.cpp +0 -0
- /package/cpp/{jsi2 → jsi}/Promise.h +0 -0
|
@@ -1 +1,16 @@
|
|
|
1
1
|
export declare let HAS_REANIMATED_3: boolean;
|
|
2
|
+
/**
|
|
3
|
+
* True when the worklets-based Reanimated integration is available
|
|
4
|
+
* (Reanimated 4 with react-native-worklets providing
|
|
5
|
+
* registerCustomSerializable). Skia objects use the JSI NativeState pattern
|
|
6
|
+
* and can only be transferred to worklet runtimes through a custom
|
|
7
|
+
* serializer, so on native the Reanimated integration requires Reanimated 4 —
|
|
8
|
+
* Reanimated 3 is not supported.
|
|
9
|
+
*/
|
|
10
|
+
export declare let HAS_REANIMATED_4: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Major version of the installed react-native-reanimated package, or null if
|
|
13
|
+
* it is not installed. Used to give actionable diagnostics when the
|
|
14
|
+
* integration cannot be enabled.
|
|
15
|
+
*/
|
|
16
|
+
export declare let REANIMATED_VERSION_MAJOR: number | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const registerSkiaWorkletSerialization: () => void;
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"setup-skia-web": "scripts/setup-canvaskit.js"
|
|
9
9
|
},
|
|
10
10
|
"title": "React Native Skia",
|
|
11
|
-
"version": "2.
|
|
11
|
+
"version": "2.10.0",
|
|
12
12
|
"description": "High-performance React Native Graphics using Skia",
|
|
13
13
|
"main": "lib/module/index.js",
|
|
14
14
|
"react-native": "src/index.ts",
|
|
@@ -79,7 +79,8 @@
|
|
|
79
79
|
"peerDependencies": {
|
|
80
80
|
"react": ">=19.0",
|
|
81
81
|
"react-native": ">=0.78",
|
|
82
|
-
"react-native-reanimated": ">=
|
|
82
|
+
"react-native-reanimated": ">=4.0.0",
|
|
83
|
+
"react-native-worklets": ">=0.7.0"
|
|
83
84
|
},
|
|
84
85
|
"peerDependenciesMeta": {
|
|
85
86
|
"react-native": {
|
|
@@ -87,6 +88,9 @@
|
|
|
87
88
|
},
|
|
88
89
|
"react-native-reanimated": {
|
|
89
90
|
"optional": true
|
|
91
|
+
},
|
|
92
|
+
"react-native-worklets": {
|
|
93
|
+
"optional": true
|
|
90
94
|
}
|
|
91
95
|
},
|
|
92
96
|
"devDependencies": {
|
|
@@ -155,8 +155,7 @@ Pod::Spec.new do |s|
|
|
|
155
155
|
'cpp/rnskia/RNDawnWindowContext.h',
|
|
156
156
|
'cpp/rnskia/RNDawnWindowContext.cpp',
|
|
157
157
|
'cpp/rnskia/RNImageProvider.h',
|
|
158
|
-
'cpp/rnwgpu/**/*.{h,cpp}'
|
|
159
|
-
'cpp/jsi2/**/*.{h,cpp}'
|
|
158
|
+
'cpp/rnwgpu/**/*.{h,cpp}'
|
|
160
159
|
]
|
|
161
160
|
s.exclude_files = graphite_exclusions unless use_graphite
|
|
162
161
|
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
export let HAS_REANIMATED_3 = false;
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* True when the worklets-based Reanimated integration is available
|
|
5
|
+
* (Reanimated 4 with react-native-worklets providing
|
|
6
|
+
* registerCustomSerializable). Skia objects use the JSI NativeState pattern
|
|
7
|
+
* and can only be transferred to worklet runtimes through a custom
|
|
8
|
+
* serializer, so on native the Reanimated integration requires Reanimated 4 —
|
|
9
|
+
* Reanimated 3 is not supported.
|
|
10
|
+
*/
|
|
11
|
+
export let HAS_REANIMATED_4 = false;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Major version of the installed react-native-reanimated package, or null if
|
|
15
|
+
* it is not installed. Used to give actionable diagnostics when the
|
|
16
|
+
* integration cannot be enabled.
|
|
17
|
+
*/
|
|
18
|
+
export let REANIMATED_VERSION_MAJOR: number | null = null;
|
|
19
|
+
|
|
3
20
|
try {
|
|
4
21
|
// This logic is convoluted but necessary
|
|
5
22
|
// In most systems, `require("react-native-reanimated")` throws an error, all is well.
|
|
@@ -14,6 +31,19 @@ try {
|
|
|
14
31
|
) {
|
|
15
32
|
HAS_REANIMATED_3 = true;
|
|
16
33
|
}
|
|
34
|
+
const majorVersion = parseInt(reanimatedVersion.split(".")[0], 10);
|
|
35
|
+
if (!isNaN(majorVersion)) {
|
|
36
|
+
REANIMATED_VERSION_MAJOR = majorVersion;
|
|
37
|
+
}
|
|
38
|
+
if (majorVersion >= 4) {
|
|
39
|
+
try {
|
|
40
|
+
const worklets = require("react-native-worklets");
|
|
41
|
+
HAS_REANIMATED_4 =
|
|
42
|
+
typeof worklets.registerCustomSerializable === "function";
|
|
43
|
+
} catch (e) {
|
|
44
|
+
// react-native-worklets not installed
|
|
45
|
+
}
|
|
46
|
+
}
|
|
17
47
|
} catch (e) {
|
|
18
48
|
// do nothing
|
|
19
49
|
}
|
package/src/skia/NativeSetup.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Platform } from "../Platform";
|
|
2
2
|
import NativeSkiaModule from "../specs/NativeSkiaModule";
|
|
3
3
|
|
|
4
|
+
import { registerSkiaWorkletSerialization } from "./SkiaWorkletSerialization";
|
|
5
|
+
|
|
4
6
|
if (Platform.OS !== "web" && global.SkiaApi == null) {
|
|
5
7
|
// Initialize RN Skia
|
|
6
8
|
const SkiaModule = NativeSkiaModule;
|
|
@@ -16,4 +18,7 @@ if (Platform.OS !== "web" && global.SkiaApi == null) {
|
|
|
16
18
|
`Native Skia Module failed to correctly install JSI Bindings! Result: ${result}`
|
|
17
19
|
);
|
|
18
20
|
}
|
|
21
|
+
// Skia objects use the JSI NativeState pattern and need a custom
|
|
22
|
+
// serializer to be transferable to worklet runtimes (Reanimated).
|
|
23
|
+
registerSkiaWorkletSerialization();
|
|
19
24
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Skia and WebGPU API objects are implemented with the JSI NativeState
|
|
5
|
+
* pattern: plain JS objects with a shared prototype and native state
|
|
6
|
+
* attached. Worklets cannot serialize such objects by default (the prototype
|
|
7
|
+
* would be lost when moving them to another runtime), so we register a
|
|
8
|
+
* Custom Serializable that:
|
|
9
|
+
*
|
|
10
|
+
* - determine: detects native objects via the `__box` method installed on
|
|
11
|
+
* every Skia and WebGPU prototype (plain objects never reach the
|
|
12
|
+
* custom-serializable path, so this cannot misfire on user data).
|
|
13
|
+
* - pack: boxes the object into a HostObject wrapper that carries the native
|
|
14
|
+
* state and the class brand. HostObjects are transferred by reference.
|
|
15
|
+
* - unpack: unboxes on the target runtime, re-installing the class prototype
|
|
16
|
+
* there and re-attaching the same native state.
|
|
17
|
+
*
|
|
18
|
+
* See cpp/jsi/BoxedNativeObject.h for the native side.
|
|
19
|
+
*
|
|
20
|
+
* `react-native-worklets` (Reanimated 4) is required for this to work —
|
|
21
|
+
* without it, Skia and WebGPU objects cannot be captured in worklets or
|
|
22
|
+
* stored in shared values.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
interface BoxedNativeObject {
|
|
26
|
+
unbox: () => object;
|
|
27
|
+
__boxedNativeObject: true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const determine = (value: object): value is object => {
|
|
31
|
+
"worklet";
|
|
32
|
+
return typeof (value as any).__box === "function";
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const pack = (value: object): BoxedNativeObject => {
|
|
36
|
+
"worklet";
|
|
37
|
+
return (value as any).__box();
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const unpack = (packed: BoxedNativeObject): object => {
|
|
41
|
+
"worklet";
|
|
42
|
+
return packed.unbox();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const registerSkiaWorkletSerialization = () => {
|
|
46
|
+
try {
|
|
47
|
+
const worklets = require("react-native-worklets");
|
|
48
|
+
if (typeof worklets.registerCustomSerializable === "function") {
|
|
49
|
+
worklets.registerCustomSerializable({
|
|
50
|
+
name: "ReactNativeSkia",
|
|
51
|
+
determine,
|
|
52
|
+
pack,
|
|
53
|
+
unpack,
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
console.error(
|
|
57
|
+
"React Native Skia requires react-native-worklets >= 0.7.0 " +
|
|
58
|
+
"(registerCustomSerializable) to use Skia objects inside worklets. " +
|
|
59
|
+
"Please upgrade react-native-worklets and react-native-reanimated."
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
} catch (e) {
|
|
63
|
+
// react-native-worklets is not installed. This is fine for apps that do
|
|
64
|
+
// not use Reanimated: Skia objects simply cannot be used inside worklets
|
|
65
|
+
// or shared values in this configuration.
|
|
66
|
+
}
|
|
67
|
+
};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import Rea from "../external/reanimated/ReanimatedProxy";
|
|
2
2
|
import type { Skia, SkPicture } from "../skia/types";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
HAS_REANIMATED_3,
|
|
5
|
+
HAS_REANIMATED_4,
|
|
6
|
+
REANIMATED_VERSION_MAJOR,
|
|
7
|
+
} from "../external/reanimated/renderHelpers";
|
|
4
8
|
import type { JsiRecorder } from "../skia/types/Recorder";
|
|
5
9
|
|
|
6
10
|
import { ReanimatedRecorder } from "./Recorder/ReanimatedRecorder";
|
|
@@ -79,10 +83,44 @@ class NativeReanimatedContainer extends Container {
|
|
|
79
83
|
}
|
|
80
84
|
}
|
|
81
85
|
|
|
86
|
+
let hasWarnedAboutReanimatedSupport = false;
|
|
87
|
+
|
|
88
|
+
const reanimatedSupportError = () => {
|
|
89
|
+
if (REANIMATED_VERSION_MAJOR !== null && REANIMATED_VERSION_MAJOR >= 4) {
|
|
90
|
+
return (
|
|
91
|
+
"React Native Skia requires react-native-worklets >= 0.7.0 for its " +
|
|
92
|
+
"Reanimated integration on native platforms. Reanimated 4 is " +
|
|
93
|
+
"installed, but react-native-worklets is missing or too old. " +
|
|
94
|
+
"Please install or upgrade react-native-worklets."
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
return (
|
|
98
|
+
"React Native Skia requires Reanimated 4 (react-native-worklets >= " +
|
|
99
|
+
"0.7.0) for its Reanimated integration on native platforms. " +
|
|
100
|
+
"Reanimated 3 is not supported anymore: Skia objects cannot be used " +
|
|
101
|
+
"inside worklets or shared values with it. " +
|
|
102
|
+
"Please upgrade to react-native-reanimated >= 4.0.0."
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
82
106
|
export const createContainer = (Skia: Skia, nativeId: number) => {
|
|
83
|
-
if (
|
|
107
|
+
if (HAS_REANIMATED_4 && nativeId !== -1) {
|
|
84
108
|
return new NativeReanimatedContainer(Skia, nativeId);
|
|
85
109
|
} else {
|
|
110
|
+
if (HAS_REANIMATED_3 && !HAS_REANIMATED_4) {
|
|
111
|
+
const message = reanimatedSupportError();
|
|
112
|
+
if (__DEV__) {
|
|
113
|
+
// Fail loudly in development — a silent fallback to static rendering
|
|
114
|
+
// would only be noticed as frozen animations.
|
|
115
|
+
throw new Error(message);
|
|
116
|
+
}
|
|
117
|
+
if (!hasWarnedAboutReanimatedSupport) {
|
|
118
|
+
hasWarnedAboutReanimatedSupport = true;
|
|
119
|
+
console.error(
|
|
120
|
+
`${message} Falling back to static rendering (animations will not run).`
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
86
124
|
return new StaticContainer(Skia, nativeId);
|
|
87
125
|
}
|
|
88
126
|
};
|
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <algorithm>
|
|
4
|
-
#include <memory>
|
|
5
|
-
#include <string>
|
|
6
|
-
#include <utility>
|
|
7
|
-
|
|
8
|
-
#include "jsi/JsiHostObject.h"
|
|
9
|
-
#include "utils/RNSkLog.h"
|
|
10
|
-
#include "rnskia/RNSkPlatformContext.h"
|
|
11
|
-
|
|
12
|
-
namespace RNSkia {
|
|
13
|
-
|
|
14
|
-
namespace jsi = facebook::jsi;
|
|
15
|
-
|
|
16
|
-
// Minimum memory pressure reported for any host object.
|
|
17
|
-
// This accounts for C++ wrapper overhead and ensures dispose() never
|
|
18
|
-
// increases reported memory pressure (which would defeat its purpose).
|
|
19
|
-
static constexpr size_t kMinMemoryPressure = 256;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Base class for jsi host objects - these are all implemented as JsiHostObjects
|
|
23
|
-
* and has a pointer to the platform context.
|
|
24
|
-
*/
|
|
25
|
-
class JsiSkHostObject : public RNJsi::JsiHostObject {
|
|
26
|
-
public:
|
|
27
|
-
/**
|
|
28
|
-
* Default constructor
|
|
29
|
-
* @param context Platform context
|
|
30
|
-
*/
|
|
31
|
-
explicit JsiSkHostObject(std::shared_ptr<RNSkPlatformContext> context)
|
|
32
|
-
: _context(context) {}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Override this method to return the memory pressure for the wrapped object.
|
|
36
|
-
* @return The memory pressure in bytes
|
|
37
|
-
*/
|
|
38
|
-
virtual size_t getMemoryPressure() const = 0;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Returns the type name of the host object.
|
|
42
|
-
*/
|
|
43
|
-
virtual std::string getObjectType() const = 0;
|
|
44
|
-
|
|
45
|
-
protected:
|
|
46
|
-
/**
|
|
47
|
-
* @return A pointer to the platform context
|
|
48
|
-
*/
|
|
49
|
-
std::shared_ptr<RNSkPlatformContext> getContext() { return _context; }
|
|
50
|
-
|
|
51
|
-
private:
|
|
52
|
-
std::shared_ptr<RNSkPlatformContext> _context;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
#define JSI_API_TYPENAME(A) \
|
|
56
|
-
JSI_PROPERTY_GET(__typename__) { \
|
|
57
|
-
return jsi::String::createFromUtf8(runtime, #A); \
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
#define EXPORT_JSI_API_TYPENAME(CLASS, TYPENAME) \
|
|
61
|
-
JSI_API_TYPENAME(TYPENAME) \
|
|
62
|
-
JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(CLASS, __typename__))
|
|
63
|
-
|
|
64
|
-
// Define this macro to enable memory pressure debug logging
|
|
65
|
-
// #define RNSKIA_DEBUG_MEMORY_PRESSURE
|
|
66
|
-
|
|
67
|
-
#ifdef RNSKIA_DEBUG_MEMORY_PRESSURE
|
|
68
|
-
// Version with debug logging
|
|
69
|
-
#define JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE( \
|
|
70
|
-
runtime, hostObjectInstance, context) \
|
|
71
|
-
[&]() { \
|
|
72
|
-
auto result = \
|
|
73
|
-
jsi::Object::createFromHostObject(runtime, hostObjectInstance); \
|
|
74
|
-
auto memoryPressure = hostObjectInstance->getMemoryPressure(); \
|
|
75
|
-
const void *hostObjectId = \
|
|
76
|
-
static_cast<const void *>(hostObjectInstance.get()); \
|
|
77
|
-
const char *mpUnit = "bytes"; \
|
|
78
|
-
double mpValue = static_cast<double>(memoryPressure); \
|
|
79
|
-
if (memoryPressure >= 1024ULL * 1024ULL) { \
|
|
80
|
-
mpUnit = "MB"; \
|
|
81
|
-
mpValue /= (1024.0 * 1024.0); \
|
|
82
|
-
RNSkLogger::logToConsole( \
|
|
83
|
-
"Host object %s (id=%p) memory pressure %.2f %s", \
|
|
84
|
-
hostObjectInstance->getObjectType().c_str(), hostObjectId, mpValue, \
|
|
85
|
-
mpUnit); \
|
|
86
|
-
} else if (memoryPressure >= 1024ULL) { \
|
|
87
|
-
mpUnit = "KB"; \
|
|
88
|
-
mpValue /= 1024.0; \
|
|
89
|
-
RNSkLogger::logToConsole( \
|
|
90
|
-
"Host object %s (id=%p) memory pressure %.2f %s", \
|
|
91
|
-
hostObjectInstance->getObjectType().c_str(), hostObjectId, mpValue, \
|
|
92
|
-
mpUnit); \
|
|
93
|
-
} else { \
|
|
94
|
-
RNSkLogger::logToConsole( \
|
|
95
|
-
"Host object %s (id=%p) memory pressure %zu %s", \
|
|
96
|
-
hostObjectInstance->getObjectType().c_str(), hostObjectId, \
|
|
97
|
-
memoryPressure, mpUnit); \
|
|
98
|
-
} \
|
|
99
|
-
if (memoryPressure > 0) { \
|
|
100
|
-
result.setExternalMemoryPressure(runtime, memoryPressure); \
|
|
101
|
-
} \
|
|
102
|
-
return result; \
|
|
103
|
-
}()
|
|
104
|
-
#else
|
|
105
|
-
// Version without debug logging (optimized)
|
|
106
|
-
#define JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE( \
|
|
107
|
-
runtime, hostObjectInstance, context) \
|
|
108
|
-
[&]() { \
|
|
109
|
-
auto result = \
|
|
110
|
-
jsi::Object::createFromHostObject(runtime, hostObjectInstance); \
|
|
111
|
-
auto memoryPressure = hostObjectInstance->getMemoryPressure(); \
|
|
112
|
-
if (memoryPressure > 0) { \
|
|
113
|
-
result.setExternalMemoryPressure(runtime, memoryPressure); \
|
|
114
|
-
} \
|
|
115
|
-
return result; \
|
|
116
|
-
}()
|
|
117
|
-
#endif
|
|
118
|
-
|
|
119
|
-
template <typename T> class JsiSkWrappingHostObject : public JsiSkHostObject {
|
|
120
|
-
public:
|
|
121
|
-
/**
|
|
122
|
-
* Default constructor
|
|
123
|
-
* @param context Platform context
|
|
124
|
-
*/
|
|
125
|
-
JsiSkWrappingHostObject(std::shared_ptr<RNSkPlatformContext> context,
|
|
126
|
-
T object)
|
|
127
|
-
: JsiSkHostObject(std::move(context)), _object(std::move(object)) {}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Returns the underlying object exposed by this host object. This object
|
|
131
|
-
* should be wrapped in a shared pointer of some kind.
|
|
132
|
-
* Throws if the object has been disposed.
|
|
133
|
-
* @return Underlying object
|
|
134
|
-
*/
|
|
135
|
-
T getObject() { return validateObject(); }
|
|
136
|
-
const T getObject() const { return validateObject(); }
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Updates the inner object with a new version of the object.
|
|
140
|
-
*/
|
|
141
|
-
void setObject(T object) { _object = object; }
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Dispose function that can be exposed to JS by using the JSI_API_TYPENAME
|
|
145
|
-
* macro.
|
|
146
|
-
*/
|
|
147
|
-
JSI_HOST_FUNCTION(dispose) {
|
|
148
|
-
if (!isDisposed()) {
|
|
149
|
-
thisValue.asObject(runtime).setExternalMemoryPressure(runtime,
|
|
150
|
-
kMinMemoryPressure);
|
|
151
|
-
}
|
|
152
|
-
safeDispose();
|
|
153
|
-
return jsi::Value::undefined();
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
protected:
|
|
157
|
-
/**
|
|
158
|
-
* Override to implement disposal of allocated resources like smart pointers.
|
|
159
|
-
* This method will only be called once for each instance of this class.
|
|
160
|
-
*/
|
|
161
|
-
virtual void releaseResources() = 0;
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Returns true if the object has been disposed.
|
|
165
|
-
*/
|
|
166
|
-
bool isDisposed() const {
|
|
167
|
-
return _isDisposed.load(std::memory_order_acquire);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Returns the underlying object without checking if disposed.
|
|
172
|
-
* Use this in destructors and releaseResources() where we need to access
|
|
173
|
-
* the object even after dispose() was called.
|
|
174
|
-
*/
|
|
175
|
-
T getObjectUnchecked() const { return _object; }
|
|
176
|
-
|
|
177
|
-
private:
|
|
178
|
-
/**
|
|
179
|
-
* Validates that _object was not disposed and returns it.
|
|
180
|
-
*/
|
|
181
|
-
T validateObject() const {
|
|
182
|
-
if (_isDisposed.load(std::memory_order_acquire)) {
|
|
183
|
-
throw std::runtime_error("Attempted to access a disposed object.");
|
|
184
|
-
}
|
|
185
|
-
return _object;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
void safeDispose() {
|
|
189
|
-
bool expected = false;
|
|
190
|
-
if (_isDisposed.compare_exchange_strong(expected, true,
|
|
191
|
-
std::memory_order_acq_rel)) {
|
|
192
|
-
releaseResources();
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Wrapped object.
|
|
198
|
-
*/
|
|
199
|
-
T _object;
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Resource disposed flag.
|
|
203
|
-
*/
|
|
204
|
-
std::atomic<bool> _isDisposed = {false};
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
template <typename T>
|
|
208
|
-
class JsiSkWrappingSharedPtrHostObject
|
|
209
|
-
: public JsiSkWrappingHostObject<std::shared_ptr<T>> {
|
|
210
|
-
public:
|
|
211
|
-
JsiSkWrappingSharedPtrHostObject(std::shared_ptr<RNSkPlatformContext> context,
|
|
212
|
-
std::shared_ptr<T> object)
|
|
213
|
-
: JsiSkWrappingHostObject<std::shared_ptr<T>>(std::move(context),
|
|
214
|
-
std::move(object)) {}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
Returns the underlying object from a host object of this type
|
|
218
|
-
*/
|
|
219
|
-
static std::shared_ptr<T> fromValue(jsi::Runtime &runtime,
|
|
220
|
-
const jsi::Value &obj) {
|
|
221
|
-
return std::static_pointer_cast<JsiSkWrappingSharedPtrHostObject>(
|
|
222
|
-
obj.asObject(runtime).asHostObject(runtime))
|
|
223
|
-
->getObject();
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
protected:
|
|
227
|
-
void releaseResources() override {
|
|
228
|
-
// Clear internally allocated objects
|
|
229
|
-
this->setObject(nullptr);
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
template <typename T>
|
|
234
|
-
class JsiSkWrappingSkPtrHostObject : public JsiSkWrappingHostObject<sk_sp<T>> {
|
|
235
|
-
public:
|
|
236
|
-
JsiSkWrappingSkPtrHostObject(std::shared_ptr<RNSkPlatformContext> context,
|
|
237
|
-
sk_sp<T> object)
|
|
238
|
-
: JsiSkWrappingHostObject<sk_sp<T>>(std::move(context),
|
|
239
|
-
std::move(object)) {}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
Returns the underlying object from a host object of this type
|
|
243
|
-
*/
|
|
244
|
-
static sk_sp<T> fromValue(jsi::Runtime &runtime, const jsi::Value &obj) {
|
|
245
|
-
return std::static_pointer_cast<JsiSkWrappingSkPtrHostObject>(
|
|
246
|
-
obj.asObject(runtime).asHostObject(runtime))
|
|
247
|
-
->getObject();
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
protected:
|
|
251
|
-
void releaseResources() override {
|
|
252
|
-
// Clear internally allocated objects
|
|
253
|
-
this->setObject(nullptr);
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
} // namespace RNSkia
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
#include "JsiHostObject.h"
|
|
2
|
-
#include <functional>
|
|
3
|
-
#include <vector>
|
|
4
|
-
|
|
5
|
-
namespace RNJsi {
|
|
6
|
-
|
|
7
|
-
void JsiHostObject::set(jsi::Runtime &rt, const jsi::PropNameID &name,
|
|
8
|
-
const jsi::Value &value) {
|
|
9
|
-
|
|
10
|
-
auto nameStr = name.utf8(rt);
|
|
11
|
-
|
|
12
|
-
/** Check the static setters map */
|
|
13
|
-
const JsiPropertySettersMap &setters = getExportedPropertySettersMap();
|
|
14
|
-
auto setter = setters.find(nameStr);
|
|
15
|
-
if (setter != setters.end()) {
|
|
16
|
-
auto dispatcher = std::bind(setter->second, this, std::placeholders::_1,
|
|
17
|
-
std::placeholders::_2);
|
|
18
|
-
return dispatcher(rt, value);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (_propMap.count(nameStr) > 0) {
|
|
22
|
-
auto prop = _propMap.at(nameStr);
|
|
23
|
-
(prop.set)(rt, value);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
jsi::Value JsiHostObject::get(jsi::Runtime &runtime,
|
|
28
|
-
const jsi::PropNameID &name) {
|
|
29
|
-
auto nameStr = name.utf8(runtime);
|
|
30
|
-
|
|
31
|
-
// Happy path - cached host functions are cheapest to look up
|
|
32
|
-
const JsiFunctionMap &funcs = getExportedFunctionMap();
|
|
33
|
-
auto func = funcs.find(nameStr);
|
|
34
|
-
|
|
35
|
-
// Check function cache
|
|
36
|
-
if (func != funcs.end()) {
|
|
37
|
-
std::map<std::string, jsi::Function> &runtimeCache =
|
|
38
|
-
_hostFunctionCache.get(runtime);
|
|
39
|
-
auto cachedFunc = runtimeCache.find(nameStr);
|
|
40
|
-
if (cachedFunc != runtimeCache.end()) {
|
|
41
|
-
return cachedFunc->second.asFunction(runtime);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Check the static getters map
|
|
46
|
-
const JsiPropertyGettersMap &getters = getExportedPropertyGettersMap();
|
|
47
|
-
auto getter = getters.find(nameStr);
|
|
48
|
-
if (getter != getters.end()) {
|
|
49
|
-
auto dispatcher = std::bind(getter->second, this, std::placeholders::_1);
|
|
50
|
-
return dispatcher(runtime);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Check the static function map
|
|
54
|
-
if (func != funcs.end()) {
|
|
55
|
-
|
|
56
|
-
// Create dispatcher
|
|
57
|
-
auto dispatcher =
|
|
58
|
-
std::bind(func->second, reinterpret_cast<JsiHostObject *>(this),
|
|
59
|
-
std::placeholders::_1, std::placeholders::_2,
|
|
60
|
-
std::placeholders::_3, std::placeholders::_4);
|
|
61
|
-
|
|
62
|
-
// Add to cache - it is important to cache the results from the
|
|
63
|
-
// createFromHostFunction function which takes some time.
|
|
64
|
-
return _hostFunctionCache.get(runtime)
|
|
65
|
-
.emplace(nameStr, jsi::Function::createFromHostFunction(runtime, name,
|
|
66
|
-
0, dispatcher))
|
|
67
|
-
.first->second.asFunction(runtime);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (_funcMap.count(nameStr) > 0) {
|
|
71
|
-
return jsi::Function::createFromHostFunction(runtime, name, 0,
|
|
72
|
-
_funcMap.at(nameStr));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (_propMap.count(nameStr) > 0) {
|
|
76
|
-
auto prop = _propMap.at(nameStr);
|
|
77
|
-
return (prop.get)(runtime);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Check for dispose symbol as last resort
|
|
81
|
-
static const auto disposeSymbol = jsi::PropNameID::forSymbol(
|
|
82
|
-
runtime,
|
|
83
|
-
runtime.global()
|
|
84
|
-
.getPropertyAsObject(runtime, "Symbol")
|
|
85
|
-
.getPropertyAsFunction(runtime, "for")
|
|
86
|
-
.call(runtime, "Symbol.dispose")
|
|
87
|
-
.getSymbol(runtime));
|
|
88
|
-
if (jsi::PropNameID::compare(runtime, disposeSymbol, name)) {
|
|
89
|
-
// Recursively call get with "dispose" string
|
|
90
|
-
auto disposeName = jsi::PropNameID::forAscii(runtime, "dispose");
|
|
91
|
-
return get(runtime, disposeName);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return jsi::Value::undefined();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
std::vector<jsi::PropNameID>
|
|
98
|
-
JsiHostObject::getPropertyNames(jsi::Runtime &runtime) {
|
|
99
|
-
// statically exported functions
|
|
100
|
-
const auto &funcs = getExportedFunctionMap();
|
|
101
|
-
|
|
102
|
-
// Statically exported property getters
|
|
103
|
-
const auto &getters = getExportedPropertyGettersMap();
|
|
104
|
-
|
|
105
|
-
// Statically exported property setters
|
|
106
|
-
const auto &setters = getExportedPropertySettersMap();
|
|
107
|
-
|
|
108
|
-
std::vector<jsi::PropNameID> propNames;
|
|
109
|
-
propNames.reserve(funcs.size() + getters.size() + setters.size() +
|
|
110
|
-
_funcMap.size() + _propMap.size());
|
|
111
|
-
|
|
112
|
-
for (auto it = funcs.cbegin(); it != funcs.cend(); ++it) {
|
|
113
|
-
propNames.push_back(jsi::PropNameID::forAscii(runtime, it->first));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
for (auto it = getters.cbegin(); it != getters.cend(); ++it) {
|
|
117
|
-
propNames.push_back(jsi::PropNameID::forUtf8(runtime, it->first));
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
for (auto it = getters.cbegin(); it != getters.cend(); ++it) {
|
|
121
|
-
if (getters.count(it->first) == 0) {
|
|
122
|
-
propNames.push_back(jsi::PropNameID::forUtf8(runtime, it->first));
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// functions
|
|
127
|
-
for (auto it = _funcMap.cbegin(); it != _funcMap.cend(); ++it) {
|
|
128
|
-
propNames.push_back(jsi::PropNameID::forAscii(runtime, it->first));
|
|
129
|
-
}
|
|
130
|
-
// props
|
|
131
|
-
for (auto it = _propMap.cbegin(); it != _propMap.cend(); ++it) {
|
|
132
|
-
propNames.push_back(jsi::PropNameID::forAscii(runtime, it->first));
|
|
133
|
-
}
|
|
134
|
-
return propNames;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
} // namespace RNJsi
|