@shopify/react-native-skia 2.12.0 → 2.13.1

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.
Files changed (130) hide show
  1. package/LICENSE.md +2 -1
  2. package/Package.swift +4 -4
  3. package/android/CMakeLists.txt +22 -177
  4. package/android/build.gradle +40 -209
  5. package/android/cpp/jni/JniSkiaManager.cpp +3 -45
  6. package/android/cpp/jni/include/JniPlatformContext.h +1 -1
  7. package/android/cpp/jni/include/JniSkiaBaseView.h +18 -11
  8. package/android/cpp/jni/include/JniSkiaManager.h +3 -4
  9. package/android/cpp/jni/include/JniSkiaPictureView.h +5 -5
  10. package/android/cpp/rnskia-android/OpenGLContext.h +1 -1
  11. package/android/cpp/rnskia-android/RNSkAndroidView.h +6 -6
  12. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +4 -4
  13. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +2 -2
  14. package/android/cpp/rnskia-android/gl/Surface.h +1 -1
  15. package/android/src/main/AndroidManifest.xml +1 -1
  16. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/PlatformContext.java +1 -1
  17. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/RNSkVideo.java +1 -1
  18. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/RNSkiaModule.java +1 -8
  19. package/android/src/main/java/com/reactnative/skia/RNSkiaPackage.java +57 -0
  20. package/android/src/main/java/com/reactnative/skia/SkiaBaseView.java +185 -0
  21. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/SkiaBaseViewManager.java +20 -1
  22. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/SkiaManager.java +11 -6
  23. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/SkiaPictureView.java +3 -3
  24. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/SkiaPictureViewManager.java +1 -1
  25. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/SkiaSurfaceView.java +13 -3
  26. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/SkiaTextureView.java +5 -3
  27. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/SkiaViewAPI.java +1 -1
  28. package/android/src/main/java/com/{shopify/reactnative → reactnative}/skia/ViewScreenshotService.java +1 -1
  29. package/apple/MetalContext.mm +1 -1
  30. package/apple/RNSkiaModule.h +1 -10
  31. package/apple/RNSkiaModule.mm +2 -10
  32. package/apple/SkiaManager.h +0 -2
  33. package/apple/SkiaManager.mm +4 -6
  34. package/apple/SkiaPictureView.h +2 -2
  35. package/apple/SkiaPictureView.mm +0 -4
  36. package/apple/SkiaUIView.h +3 -18
  37. package/apple/SkiaUIView.mm +0 -30
  38. package/cpp/api/CustomBlendModes.h +17 -0
  39. package/cpp/api/JsiSkCanvas.h +19 -10
  40. package/cpp/api/JsiSkImage.h +1 -1
  41. package/cpp/api/JsiSkImageFilter.h +3 -1
  42. package/cpp/api/JsiSkParagraph.h +2 -1
  43. package/cpp/api/JsiSkParagraphBuilder.h +1 -1
  44. package/cpp/api/JsiSkParagraphBuilderFactory.h +1 -1
  45. package/cpp/api/JsiSkPath.h +11 -4
  46. package/cpp/api/JsiSkPathBuilder.h +11 -4
  47. package/cpp/api/JsiSkPictureRecorder.h +2 -1
  48. package/cpp/api/JsiSkShader.h +3 -1
  49. package/cpp/api/JsiSkSkottie.h +27 -25
  50. package/cpp/api/recorder/Command.h +1 -1
  51. package/cpp/api/recorder/Convertor.h +1 -1
  52. package/cpp/api/recorder/DataTypes.h +1 -1
  53. package/cpp/api/recorder/DrawingCtx.h +1 -1
  54. package/cpp/api/recorder/JsiRecorder.h +7 -4
  55. package/cpp/api/third_party/base64.cpp +1 -1
  56. package/cpp/jsi/JSICache.cpp +23 -0
  57. package/cpp/jsi/JSICache.h +28 -1
  58. package/cpp/jsi/NativeObject.h +36 -7
  59. package/cpp/jsi/ViewProperty.h +0 -4
  60. package/cpp/rnskia/RNDawnContext.h +1 -1
  61. package/lib/commonjs/animation/functions/interpolatePaths.js +18 -0
  62. package/lib/commonjs/animation/functions/interpolatePaths.js.map +1 -1
  63. package/lib/commonjs/mock/index.js +0 -1
  64. package/lib/commonjs/mock/index.js.map +1 -1
  65. package/lib/commonjs/renderer/Canvas.d.ts +11 -3
  66. package/lib/commonjs/renderer/Canvas.js +8 -6
  67. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  68. package/lib/commonjs/skia/web/JsiSkCanvas.js +9 -4
  69. package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
  70. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +2 -0
  71. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
  72. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +3 -1
  73. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js +3 -0
  74. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js.map +1 -1
  75. package/lib/commonjs/views/SkiaPictureView.js +2 -12
  76. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  77. package/lib/commonjs/views/types.d.ts +19 -8
  78. package/lib/commonjs/views/types.js.map +1 -1
  79. package/lib/module/animation/functions/interpolatePaths.js +18 -0
  80. package/lib/module/animation/functions/interpolatePaths.js.map +1 -1
  81. package/lib/module/mock/index.js +0 -1
  82. package/lib/module/mock/index.js.map +1 -1
  83. package/lib/module/renderer/Canvas.d.ts +11 -3
  84. package/lib/module/renderer/Canvas.js +7 -5
  85. package/lib/module/renderer/Canvas.js.map +1 -1
  86. package/lib/module/skia/web/JsiSkCanvas.js +9 -4
  87. package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
  88. package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +2 -0
  89. package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
  90. package/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +3 -1
  91. package/lib/module/specs/SkiaPictureViewNativeComponent.web.js +3 -0
  92. package/lib/module/specs/SkiaPictureViewNativeComponent.web.js.map +1 -1
  93. package/lib/module/views/SkiaPictureView.js +2 -12
  94. package/lib/module/views/SkiaPictureView.js.map +1 -1
  95. package/lib/module/views/types.d.ts +19 -8
  96. package/lib/module/views/types.js.map +1 -1
  97. package/lib/typescript/lib/commonjs/mock/index.d.ts +0 -1
  98. package/lib/typescript/lib/commonjs/renderer/Canvas.d.ts +2 -2
  99. package/lib/typescript/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +3 -1
  100. package/lib/typescript/lib/module/mock/index.d.ts +0 -1
  101. package/lib/typescript/lib/module/renderer/Canvas.d.ts +2 -2
  102. package/lib/typescript/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +3 -1
  103. package/lib/typescript/src/renderer/Canvas.d.ts +11 -3
  104. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +2 -0
  105. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.web.d.ts +3 -1
  106. package/lib/typescript/src/views/types.d.ts +19 -8
  107. package/package.json +3 -3
  108. package/react-native-skia.podspec +4 -10
  109. package/src/animation/functions/interpolatePaths.ts +24 -0
  110. package/src/mock/index.ts +0 -1
  111. package/src/renderer/Canvas.tsx +23 -5
  112. package/src/skia/web/JsiSkCanvas.ts +14 -9
  113. package/src/specs/SkiaPictureViewNativeComponent.ts +5 -0
  114. package/src/specs/SkiaPictureViewNativeComponent.web.ts +5 -0
  115. package/src/views/SkiaPictureView.tsx +2 -10
  116. package/src/views/types.ts +23 -10
  117. package/android/src/latest/java/com/shopify/reactnative/skia/ReactNativeCompatible.java +0 -11
  118. package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaPackage.java +0 -79
  119. package/android/src/main/java/com/shopify/reactnative/skia/SkiaAHBView.java +0 -113
  120. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +0 -136
  121. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerDelegate.java +0 -41
  122. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerInterface.java +0 -20
  123. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaWebGPUViewManagerDelegate.java +0 -35
  124. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaWebGPUViewManagerInterface.java +0 -17
  125. package/android/src/paper/java/com/shopify/reactnative/skia/NativeSkiaModuleSpec.java +0 -38
  126. package/android/src/reactnative74/java/com/shopify/reactnative/skia/ReactNativeCompatible.java +0 -14
  127. package/apple/SkiaPictureViewManager.h +0 -8
  128. package/apple/SkiaPictureViewManager.mm +0 -60
  129. package/apple/SkiaWebGPUView.h +0 -20
  130. package/apple/WebGPUMetalView.h +0 -12
@@ -24,7 +24,7 @@ class JsiRecorder
24
24
  public:
25
25
  static constexpr const char *CLASS_NAME = "Recorder";
26
26
 
27
- JsiRecorder(std::shared_ptr<RNSkPlatformContext> context)
27
+ explicit JsiRecorder(std::shared_ptr<RNSkPlatformContext> context)
28
28
  : JsiSkWrappingSharedPtrNativeObject<JsiRecorder, Recorder>(
29
29
  std::move(context), std::make_shared<Recorder>()) {
30
30
  getObject()->_context = getContext();
@@ -379,9 +379,12 @@ public:
379
379
  installHostMethod(runtime, prototype, "reset", &JsiRecorder::reset);
380
380
  }
381
381
 
382
- // This has no basis in reality but since since these are private long-lived
383
- // objects, we think it is more than fine.
384
- size_t getMemoryPressure() override { return 5 * 1024 * 1024; }
382
+ // The recorder itself is a small command list. The resources it references
383
+ // (images, pictures, paths) report their own size through their wrappers
384
+ // and the pictures produced by play() report theirs. Do not put a made-up
385
+ // number here: a new recorder is created on every React commit and the
386
+ // charge is repeated each time it is unboxed on the UI runtime.
387
+ size_t getMemoryPressure() override { return kMinMemoryPressure; }
385
388
 
386
389
  static const jsi::HostFunctionType
387
390
  createCtor(std::shared_ptr<RNSkPlatformContext> context) {
@@ -4,7 +4,7 @@
4
4
  * Use of this source code is governed by a BSD-style license that can be
5
5
  * found in the LICENSE file.
6
6
  */
7
- #include "base64.h"
7
+ #include "api/third_party/base64.h"
8
8
 
9
9
  #include <cstdint>
10
10
 
@@ -1,5 +1,6 @@
1
1
  #include "JSICache.h"
2
2
 
3
+ #include <algorithm>
3
4
  #include <iterator>
4
5
  #include <memory>
5
6
  #include <stdexcept>
@@ -96,4 +97,26 @@ jsi::Object &JSICache::setPrototype(PrototypeKey key, jsi::Object prototype) {
96
97
  return it->second;
97
98
  }
98
99
 
100
+ jsi::Value JSICache::lockWrapper(jsi::Runtime &runtime,
101
+ const void *nativeObject) {
102
+ auto it = _wrappers.find(nativeObject);
103
+ if (it == _wrappers.end()) {
104
+ return jsi::Value::undefined();
105
+ }
106
+ return it->second.lock(runtime);
107
+ }
108
+
109
+ void JSICache::setWrapper(jsi::Runtime &runtime, const void *nativeObject,
110
+ const jsi::Object &wrapper) {
111
+ _wrappers.insert_or_assign(nativeObject, jsi::WeakObject(runtime, wrapper));
112
+ if (_wrappers.size() < _pruneWrappersAt) {
113
+ return;
114
+ }
115
+ for (auto it = _wrappers.begin(); it != _wrappers.end();) {
116
+ it = it->second.lock(runtime).isUndefined() ? _wrappers.erase(it)
117
+ : std::next(it);
118
+ }
119
+ _pruneWrappersAt = std::max(kMinPruneWrappersAt, _wrappers.size() * 2);
120
+ }
121
+
99
122
  } // namespace RNJsi
@@ -13,7 +13,8 @@ namespace jsi = facebook::jsi;
13
13
 
14
14
  /**
15
15
  * Per-runtime store for JSI values that native code wants to keep across
16
- * calls (currently: the prototype object of every NativeObject class).
16
+ * calls: the prototype object of every NativeObject class, and the JS
17
+ * wrapper of every native object that has one on the runtime.
17
18
  *
18
19
  * Ownership model (borrowed from react-native-nitro-modules' JSICache):
19
20
  *
@@ -72,6 +73,26 @@ public:
72
73
  */
73
74
  jsi::Object &setPrototype(PrototypeKey key, jsi::Object prototype);
74
75
 
76
+ /**
77
+ * Returns the JS wrapper stored for `nativeObject` on this runtime, or
78
+ * undefined if none was stored or the wrapper has been collected.
79
+ *
80
+ * The key is the native object's address. A live wrapper keeps its native
81
+ * object alive (the object is the wrapper's NativeState), so as long as
82
+ * the entry locks it still belongs to that object. Once the wrapper has
83
+ * been collected the entry is stale and is skipped or replaced, so an
84
+ * address reused by a new object can never resolve to the old wrapper.
85
+ */
86
+ jsi::Value lockWrapper(jsi::Runtime &runtime, const void *nativeObject);
87
+
88
+ /**
89
+ * Stores `wrapper` as the JS wrapper of `nativeObject` on this runtime.
90
+ * Only a weak reference is kept: the wrapper stays collectable, and the
91
+ * native object is released when it goes away.
92
+ */
93
+ void setWrapper(jsi::Runtime &runtime, const void *nativeObject,
94
+ const jsi::Object &wrapper);
95
+
75
96
  JSICache() = default;
76
97
  ~JSICache() override = default;
77
98
  JSICache(const JSICache &) = delete;
@@ -81,6 +102,12 @@ private:
81
102
  static std::shared_ptr<JSICache> getOrCreateOnGlobal(jsi::Runtime &runtime);
82
103
 
83
104
  std::unordered_map<PrototypeKey, jsi::Object> _prototypes;
105
+ // Native object -> its wrapper on this runtime. Entries of collected
106
+ // wrappers are pruned in setWrapper once the map has doubled since the
107
+ // last pruning, so it stays proportional to the number of live wrappers.
108
+ std::unordered_map<const void *, jsi::WeakObject> _wrappers;
109
+ size_t _pruneWrappersAt = kMinPruneWrappersAt;
110
+ static constexpr size_t kMinPruneWrappersAt = 64;
84
111
 
85
112
  // Runtime -> cache. Weak on purpose: the runtime's global owns the cache.
86
113
  static std::mutex _registryMutex;
@@ -210,12 +210,12 @@ public:
210
210
  if (instance == nullptr) {
211
211
  throw jsi::JSError(rt, "Invalid boxed native object state");
212
212
  }
213
- // Unboxing creates a *view* of the object on the target runtime.
214
- // Keep the runtime the object was originally created on: async
215
- // native code (e.g. GPUDevice error/lost events) delivers into
216
- // the creation runtime, and rebinding it to a worklet runtime
217
- // would invoke main-runtime jsi::Functions on the wrong runtime
218
- // and thread.
213
+ // Unboxing hands back the wrapper cached for the target runtime,
214
+ // creating it on first use. Keep the runtime the object was
215
+ // originally created on: async native code (e.g. GPUDevice
216
+ // error/lost events) delivers into the creation runtime, and
217
+ // rebinding it to a worklet runtime would invoke main-runtime
218
+ // jsi::Functions on the wrong runtime and thread.
219
219
  auto *originalRuntime = instance->getCreationRuntime();
220
220
  auto value = Derived::create(rt, instance);
221
221
  if (originalRuntime != nullptr) {
@@ -262,10 +262,37 @@ public:
262
262
  }
263
263
 
264
264
  /**
265
- * Create a JS object with native state attached.
265
+ * Returns the JS wrapper of `instance` on `runtime`, creating it on first
266
+ * use.
267
+ *
268
+ * A native object has at most one live wrapper per runtime. The wrapper is
269
+ * cached (weakly, so it stays collectable) in the runtime's JSICache, and
270
+ * converting the same object again (returning it from another native
271
+ * call, unboxing it in a worklet on every frame, ...) hands back that
272
+ * wrapper instead of a new one. Each wrapper reports the native memory the
273
+ * object owns to the GC of its runtime through setExternalMemoryPressure,
274
+ * so the memory is charged exactly once per runtime that can reach the
275
+ * object, however often it is converted; charging every conversion used
276
+ * to multiply the amount by the number of captures in a worklet until
277
+ * Hermes hit its max heap size. The hint is refreshed on every round trip
278
+ * for objects whose size changes after creation (path and paragraph
279
+ * builders).
266
280
  */
267
281
  static jsi::Value create(jsi::Runtime &runtime,
268
282
  std::shared_ptr<Derived> instance) {
283
+ auto &cache = JSICache::get(runtime);
284
+ const void *key = instance.get();
285
+
286
+ auto existing = cache.lockWrapper(runtime, key);
287
+ if (existing.isObject()) {
288
+ auto pressure = instance->getMemoryPressure();
289
+ if (pressure > 0) {
290
+ existing.getObject(runtime).setExternalMemoryPressure(runtime,
291
+ pressure);
292
+ }
293
+ return existing;
294
+ }
295
+
269
296
  // Store creation runtime for logging etc.
270
297
  instance->setCreationRuntime(&runtime);
271
298
 
@@ -290,9 +317,11 @@ public:
290
317
  obj.setExternalMemoryPressure(runtime, pressure);
291
318
  }
292
319
 
320
+ cache.setWrapper(runtime, key, obj);
293
321
  return std::move(obj);
294
322
  }
295
323
 
324
+ public:
296
325
  /**
297
326
  * Get the native state from a JS value.
298
327
  * Throws if the value doesn't have the expected native state.
@@ -21,10 +21,6 @@ public:
21
21
  }
22
22
  }
23
23
 
24
- template <typename PlatformContext>
25
- ViewProperty(jsi::Runtime &runtime, const jsi::Value &value,
26
- PlatformContext platformContext, size_t nativeId) {}
27
-
28
24
  bool isNull() { return std::holds_alternative<std::nullptr_t>(_value); }
29
25
 
30
26
  sk_sp<SkPicture> getPicture() { return std::get<sk_sp<SkPicture>>(_value); }
@@ -112,7 +112,7 @@ public:
112
112
  int height = static_cast<int>(IOSurfaceGetHeight(ioSurface));
113
113
  #else
114
114
  wgpu::SharedTextureMemoryAHardwareBufferDescriptor platformDesc;
115
- auto ahb = (AHardwareBuffer *)buffer;
115
+ auto ahb = reinterpret_cast<AHardwareBuffer *>(buffer);
116
116
  platformDesc.handle = ahb;
117
117
  AHardwareBuffer_Desc adesc;
118
118
  AHardwareBuffer_describe(ahb, &adesc);
@@ -9,6 +9,12 @@ var _interpolate = require("./interpolate");
9
9
  const lerp = (value, from, to, p1, p2) => {
10
10
  "worklet";
11
11
 
12
+ // Zero-width segment (duplicate input stops): t would be NaN or Infinity.
13
+ // Return the segment's end path (p2), i.e. the value jumps to p2 at the stop.
14
+ // reanimated's interpolate has no explicit guard here, so this is our choice.
15
+ if (to === from) {
16
+ return p2;
17
+ }
12
18
  const t = (value - from) / (to - from);
13
19
  // interpolate returns a new path (immutable operation)
14
20
  return p2.interpolate(p1, t);
@@ -33,12 +39,21 @@ const lerp = (value, from, to, p1, p2) => {
33
39
  const interpolatePaths = (value, input, outputRange, options, _output) => {
34
40
  "worklet";
35
41
 
42
+ if (input.length < 2 || input.length !== outputRange.length) {
43
+ throw new Error(`interpolatePaths() requires input and outputRange to have the same length and at least 2 entries, received ${input.length} and ${outputRange.length}`);
44
+ }
45
+ if (Number.isNaN(value)) {
46
+ throw new Error("interpolatePaths() received NaN as value");
47
+ }
36
48
  const extrapolation = (0, _interpolate.validateInterpolationOptions)(options);
37
49
  if (value < input[0]) {
38
50
  switch (extrapolation.extrapolateLeft) {
39
51
  case _interpolate.Extrapolate.CLAMP:
40
52
  return outputRange[0];
41
53
  case _interpolate.Extrapolate.EXTEND:
54
+ if (!Number.isFinite(value)) {
55
+ throw new Error("interpolatePaths() cannot extend with an infinite value, use clamp extrapolation instead");
56
+ }
42
57
  return lerp(value, input[0], input[1], outputRange[0], outputRange[1]);
43
58
  case _interpolate.Extrapolate.IDENTITY:
44
59
  throw new Error("Identity is not a supported extrapolation type for interpolatePaths()");
@@ -50,6 +65,9 @@ const interpolatePaths = (value, input, outputRange, options, _output) => {
50
65
  case _interpolate.Extrapolate.CLAMP:
51
66
  return outputRange[outputRange.length - 1];
52
67
  case _interpolate.Extrapolate.EXTEND:
68
+ if (!Number.isFinite(value)) {
69
+ throw new Error("interpolatePaths() cannot extend with an infinite value, use clamp extrapolation instead");
70
+ }
53
71
  return lerp(value, input[input.length - 2], input[input.length - 1], outputRange[input.length - 2], outputRange[input.length - 1]);
54
72
  case _interpolate.Extrapolate.IDENTITY:
55
73
  throw new Error("Identity is not a supported extrapolation type for interpolatePaths()");
@@ -1 +1 @@
1
- {"version":3,"names":["_typeddash","require","_interpolate","lerp","value","from","to","p1","p2","t","interpolate","interpolatePaths","input","outputRange","options","_output","extrapolation","validateInterpolationOptions","extrapolateLeft","Extrapolate","CLAMP","EXTEND","IDENTITY","Error","exhaustiveCheck","length","extrapolateRight","i","exports"],"sources":["interpolatePaths.ts"],"sourcesContent":["import type { SkPath } from \"../../skia/types\";\nimport { exhaustiveCheck } from \"../../renderer/typeddash\";\n\nimport type { ExtrapolationType } from \"./interpolate\";\nimport { validateInterpolationOptions, Extrapolate } from \"./interpolate\";\n\nconst lerp = (\n value: number,\n from: number,\n to: number,\n p1: SkPath,\n p2: SkPath\n) => {\n \"worklet\";\n const t = (value - from) / (to - from);\n // interpolate returns a new path (immutable operation)\n return p2.interpolate(p1, t)!;\n};\n\n/**\n * Maps an input value within a range to an output path within a path range.\n * @param value - The input value.\n * @param inputRange - The range of the input value.\n * @param outputRange - The range of the output path.\n * @param options - Extrapolation options\n * @returns The output path.\n * @example <caption>Map a value between 0 and 1 to a path between two paths.</caption>\n * const path1 = new Path();\n * path1.moveTo(0, 0);\n * path1.lineTo(100, 0);\n * const path2 = new Path();\n * path2.moveTo(0, 0);\n * path2.lineTo(0, 100);\n * const path = interpolatePath(0.5, [0, 1], [path1, path2]);\n */\nexport const interpolatePaths = (\n value: number,\n input: number[],\n outputRange: SkPath[],\n options?: ExtrapolationType,\n _output?: SkPath\n) => {\n \"worklet\";\n const extrapolation = validateInterpolationOptions(options);\n if (value < input[0]) {\n switch (extrapolation.extrapolateLeft) {\n case Extrapolate.CLAMP:\n return outputRange[0];\n case Extrapolate.EXTEND:\n return lerp(value, input[0], input[1], outputRange[0], outputRange[1]);\n case Extrapolate.IDENTITY:\n throw new Error(\n \"Identity is not a supported extrapolation type for interpolatePaths()\"\n );\n default:\n exhaustiveCheck(extrapolation.extrapolateLeft);\n }\n } else if (value > input[input.length - 1]) {\n switch (extrapolation.extrapolateRight) {\n case Extrapolate.CLAMP:\n return outputRange[outputRange.length - 1];\n case Extrapolate.EXTEND:\n return lerp(\n value,\n input[input.length - 2],\n input[input.length - 1],\n outputRange[input.length - 2],\n outputRange[input.length - 1]\n );\n case Extrapolate.IDENTITY:\n throw new Error(\n \"Identity is not a supported extrapolation type for interpolatePaths()\"\n );\n default:\n exhaustiveCheck(extrapolation.extrapolateRight);\n }\n }\n let i = 0;\n for (; i <= input.length - 1; i++) {\n if (value >= input[i] && value <= input[i + 1]) {\n break;\n }\n }\n return lerp(\n value,\n input[i],\n input[i + 1],\n outputRange[i],\n outputRange[i + 1]\n );\n};\n"],"mappings":";;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AAGA,IAAAC,YAAA,GAAAD,OAAA;AAEA,MAAME,IAAI,GAAGA,CACXC,KAAa,EACbC,IAAY,EACZC,EAAU,EACVC,EAAU,EACVC,EAAU,KACP;EACH,SAAS;;EACT,MAAMC,CAAC,GAAG,CAACL,KAAK,GAAGC,IAAI,KAAKC,EAAE,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C,CAAC,EACvBZ,WAAW,CAACD,KAAK,CAACa,MAAM,GAAG,CAAC,CAAC,EAC7BZ,WAAW,CAACD,KAAK,CAACa,MAAM,GAAG,CAAC,CAC9B,CAAC;MACH,KAAKN,wBAAW,CAACG,QAAQ;QACvB,MAAM,IAAIC,KAAK,CACb,uEACF,CAAC;MACH;QACE,IAAAC,0BAAe,EAACR,aAAa,CAACU,gBAAgB,CAAC;IACnD;EACF;EACA,IAAIC,CAAC,GAAG,CAAC;EACT,OAAOA,CAAC,IAAIf,KAAK,CAACa,MAAM,GAAG,CAAC,EAAEE,CAAC,EAAE,EAAE;IACjC,IAAIvB,KAAK,IAAIQ,KAAK,CAACe,CAAC,CAAC,IAAIvB,KAAK,IAAIQ,KAAK,CAACe,CAAC,GAAG,CAAC,CAAC,EAAE;MAC9C;IACF;EACF;EACA,OAAOxB,IAAI,CACTC,KAAK,EACLQ,KAAK,CAACe,CAAC,CAAC,EACRf,KAAK,CAACe,CAAC,GAAG,CAAC,CAAC,EACZd,WAAW,CAACc,CAAC,CAAC,EACdd,WAAW,CAACc,CAAC,GAAG,CAAC,CACnB,CAAC;AACH,CAAC;AAACC,OAAA,CAAAjB,gBAAA,GAAAA,gBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_typeddash","require","_interpolate","lerp","value","from","to","p1","p2","t","interpolate","interpolatePaths","input","outputRange","options","_output","length","Error","Number","isNaN","extrapolation","validateInterpolationOptions","extrapolateLeft","Extrapolate","CLAMP","EXTEND","isFinite","IDENTITY","exhaustiveCheck","extrapolateRight","i","exports"],"sources":["interpolatePaths.ts"],"sourcesContent":["import type { SkPath } from \"../../skia/types\";\nimport { exhaustiveCheck } from \"../../renderer/typeddash\";\n\nimport type { ExtrapolationType } from \"./interpolate\";\nimport { validateInterpolationOptions, Extrapolate } from \"./interpolate\";\n\nconst lerp = (\n value: number,\n from: number,\n to: number,\n p1: SkPath,\n p2: SkPath\n) => {\n \"worklet\";\n // Zero-width segment (duplicate input stops): t would be NaN or Infinity.\n // Return the segment's end path (p2), i.e. the value jumps to p2 at the stop.\n // reanimated's interpolate has no explicit guard here, so this is our choice.\n if (to === from) {\n return p2;\n }\n const t = (value - from) / (to - from);\n // interpolate returns a new path (immutable operation)\n return p2.interpolate(p1, t)!;\n};\n\n/**\n * Maps an input value within a range to an output path within a path range.\n * @param value - The input value.\n * @param inputRange - The range of the input value.\n * @param outputRange - The range of the output path.\n * @param options - Extrapolation options\n * @returns The output path.\n * @example <caption>Map a value between 0 and 1 to a path between two paths.</caption>\n * const path1 = new Path();\n * path1.moveTo(0, 0);\n * path1.lineTo(100, 0);\n * const path2 = new Path();\n * path2.moveTo(0, 0);\n * path2.lineTo(0, 100);\n * const path = interpolatePath(0.5, [0, 1], [path1, path2]);\n */\nexport const interpolatePaths = (\n value: number,\n input: number[],\n outputRange: SkPath[],\n options?: ExtrapolationType,\n _output?: SkPath\n) => {\n \"worklet\";\n if (input.length < 2 || input.length !== outputRange.length) {\n throw new Error(\n `interpolatePaths() requires input and outputRange to have the same length and at least 2 entries, received ${input.length} and ${outputRange.length}`\n );\n }\n if (Number.isNaN(value)) {\n throw new Error(\"interpolatePaths() received NaN as value\");\n }\n const extrapolation = validateInterpolationOptions(options);\n if (value < input[0]) {\n switch (extrapolation.extrapolateLeft) {\n case Extrapolate.CLAMP:\n return outputRange[0];\n case Extrapolate.EXTEND:\n if (!Number.isFinite(value)) {\n throw new Error(\n \"interpolatePaths() cannot extend with an infinite value, use clamp extrapolation instead\"\n );\n }\n return lerp(value, input[0], input[1], outputRange[0], outputRange[1]);\n case Extrapolate.IDENTITY:\n throw new Error(\n \"Identity is not a supported extrapolation type for interpolatePaths()\"\n );\n default:\n exhaustiveCheck(extrapolation.extrapolateLeft);\n }\n } else if (value > input[input.length - 1]) {\n switch (extrapolation.extrapolateRight) {\n case Extrapolate.CLAMP:\n return outputRange[outputRange.length - 1];\n case Extrapolate.EXTEND:\n if (!Number.isFinite(value)) {\n throw new Error(\n \"interpolatePaths() cannot extend with an infinite value, use clamp extrapolation instead\"\n );\n }\n return lerp(\n value,\n input[input.length - 2],\n input[input.length - 1],\n outputRange[input.length - 2],\n outputRange[input.length - 1]\n );\n case Extrapolate.IDENTITY:\n throw new Error(\n \"Identity is not a supported extrapolation type for interpolatePaths()\"\n );\n default:\n exhaustiveCheck(extrapolation.extrapolateRight);\n }\n }\n let i = 0;\n for (; i <= input.length - 1; i++) {\n if (value >= input[i] && value <= input[i + 1]) {\n break;\n }\n }\n return lerp(\n value,\n input[i],\n input[i + 1],\n outputRange[i],\n outputRange[i + 1]\n );\n};\n"],"mappings":";;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AAGA,IAAAC,YAAA,GAAAD,OAAA;AAEA,MAAME,IAAI,GAAGA,CACXC,KAAa,EACbC,IAAY,EACZC,EAAU,EACVC,EAAU,EACVC,EAAU,KACP;EACH,SAAS;;EACT;EACA;EACA;EACA,IAAIF,EAAE,KAAKD,IAAI,EAAE;IACf,OAAOG,EAAE;EACX;EACA,MAAMC,CAAC,GAAG,CAACL,KAAK,GAAGC,IAAI,KAAKC,EAAE,GAAGD,IAAI,CAAC;EACtC;EACA,OAAOG,EAAE,CAACE,WAAW,CAACH,EAAE,EAAEE,CAAC,CAAC;AAC9B,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAME,gBAAgB,GAAGA,CAC9BP,KAAa,EACbQ,KAAe,EACfC,WAAqB,EACrBC,OAA2B,EAC3BC,OAAgB,KACb;EACH,SAAS;;EACT,IAAIH,KAAK,CAACI,MAAM,GAAG,CAAC,IAAIJ,KAAK,CAACI,MAAM,KAAKH,WAAW,CAACG,MAAM,EAAE;IAC3D,MAAM,IAAIC,KAAK,CACb,8GAA8GL,KAAK,CAACI,MAAM,QAAQH,WAAW,CAACG,MAAM,EACtJ,CAAC;EACH;EACA,IAAIE,MAAM,CAACC,KAAK,CAACf,KAAK,CAAC,EAAE;IACvB,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CAACD,KAAK,CAACI,MAAM,GAAG,CAAC,CAAC,EAC7BH,WAAW,CAACD,KAAK,CAACI,MAAM,GAAG,CAAC,CAC9B,CAAC;MACH,KAAKO,wBAAW,CAACI,QAAQ;QACvB,MAAM,IAAIV,KAAK,CACb,uEACF,CAAC;MACH;QACE,IAAAW,0BAAe,EAACR,aAAa,CAACS,gBAAgB,CAAC;IACnD;EACF;EACA,IAAIC,CAAC,GAAG,CAAC;EACT,OAAOA,CAAC,IAAIlB,KAAK,CAACI,MAAM,GAAG,CAAC,EAAEc,CAAC,EAAE,EAAE;IACjC,IAAI1B,KAAK,IAAIQ,KAAK,CAACkB,CAAC,CAAC,IAAI1B,KAAK,IAAIQ,KAAK,CAACkB,CAAC,GAAG,CAAC,CAAC,EAAE;MAC9C;IACF;EACF;EACA,OAAO3B,IAAI,CACTC,KAAK,EACLQ,KAAK,CAACkB,CAAC,CAAC,EACRlB,KAAK,CAACkB,CAAC,GAAG,CAAC,CAAC,EACZjB,WAAW,CAACiB,CAAC,CAAC,EACdjB,WAAW,CAACiB,CAAC,GAAG,CAAC,CACnB,CAAC;AACH,CAAC;AAACC,OAAA,CAAApB,gBAAA,GAAAA,gBAAA","ignoreList":[]}
@@ -55,7 +55,6 @@ const Mock = CanvasKit => {
55
55
  useValueEffect: Noop,
56
56
  // Reanimated hooks
57
57
  isOnMainThread: () => true,
58
- isFabric: true,
59
58
  useClock: NoopSharedValue,
60
59
  usePathInterpolation: NoopSharedValue,
61
60
  useImageAsTexture: NoopSharedValue,
@@ -1 +1 @@
1
- {"version":3,"names":["_web","require","_JsiSkImage","Noop","undefined","NoopValue","current","NoopSharedValue","value","Mock","CanvasKit","global","SkiaApi","JsiSkApi","Skia","Canvas","View","getPreferredHighBitDepthCanvasFormat","SkiaPictureView","JsiSkImage","drawAsPicture","drawAsImage","drawAsImageFromPicture","useCanvasRef","useCanvasSize","ref","size","width","height","useValue","useComputedValue","useTiming","useLoop","useSpring","useClockValue","useValueEffect","isOnMainThread","isFabric","useClock","usePathInterpolation","useImageAsTexture","useTextureValue","useTextureValueFromPicture","useRSXformBuffer","usePointBuffer","useColorBuffer","useRectBuffer","useBuffer","useRawData","useData","useFont","Font","useFonts","useTypeface","useImage","useSVG","useVideo","exports"],"sources":["index.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport { JsiSkApi } from \"../skia/web\";\nimport { JsiSkImage } from \"../skia/web/JsiSkImage\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst Noop: () => any = () => undefined;\nconst NoopValue = () => ({ current: 0 });\nconst NoopSharedValue = () => ({ value: 0 });\n\nexport const Mock = (CanvasKit: CanvasKit) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n global.SkiaApi = JsiSkApi(CanvasKit);\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const Skia = global.SkiaApi;\n return {\n Skia,\n ...require(\"../renderer/components\"),\n ...require(\"../skia\"),\n ...require(\"../animation\"),\n ...require(\"../dom/types\"),\n ...require(\"../dom/nodes\"),\n Canvas: require(\"react-native\").View,\n getPreferredHighBitDepthCanvasFormat: () => \"rgba16float\",\n SkiaPictureView: require(\"react-native\").View,\n JsiSkImage: JsiSkImage,\n drawAsPicture: Noop,\n drawAsImage: Noop,\n drawAsImageFromPicture: Noop,\n useCanvasRef: NoopValue,\n useCanvasSize: () => ({\n ref: {\n current: 0,\n },\n size: {\n width: 0,\n height: 0,\n },\n }),\n // Skia Animations\n useValue: NoopValue,\n useComputedValue: NoopValue,\n useTiming: NoopValue,\n useLoop: NoopValue,\n useSpring: NoopValue,\n useClockValue: NoopValue,\n useValueEffect: Noop,\n // Reanimated hooks\n isOnMainThread: () => true,\n isFabric: true,\n useClock: NoopSharedValue,\n usePathInterpolation: NoopSharedValue,\n useImageAsTexture: NoopSharedValue,\n useTextureValue: NoopSharedValue,\n useTextureValueFromPicture: NoopSharedValue,\n useRSXformBuffer: NoopSharedValue,\n usePointBuffer: NoopSharedValue,\n useColorBuffer: NoopSharedValue,\n useRectBuffer: NoopSharedValue,\n useBuffer: NoopSharedValue,\n useRawData: Noop,\n useData: Noop,\n useFont: () => Skia.Font(undefined, 0),\n useFonts: Noop,\n useTypeface: () => null,\n useImage: () => null,\n useSVG: () => null,\n useVideo: () => null,\n };\n};\n"],"mappings":";;;;;;AAEA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAEA;AACA,MAAME,IAAe,GAAGA,CAAA,KAAMC,SAAS;AACvC,MAAMC,SAAS,GAAGA,CAAA,MAAO;EAAEC,OAAO,EAAE;AAAE,CAAC,CAAC;AACxC,MAAMC,eAAe,GAAGA,CAAA,MAAO;EAAEC,KAAK,EAAE;AAAE,CAAC,CAAC;AAErC,MAAMC,IAAI,GAAIC,SAAoB,IAAK;EAC5C;EACA;EACAC,MAAM,CAACC,OAAO,GAAG,IAAAC,aAAQ,EAACH,SAAS,CAAC;EACpC;EACA;EACA,MAAMI,IAAI,GAAGH,MAAM,CAACC,OAAO;EAC3B,OAAO;IACLE,IAAI;IACJ,GAAGb,OAAO,CAAC,wBAAwB,CAAC;IACpC,GAAGA,OAAO,CAAC,SAAS,CAAC;IACrB,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1B,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1B,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1Bc,MAAM,EAAEd,OAAO,CAAC,cAAc,CAAC,CAACe,IAAI;IACpCC,oCAAoC,EAAEA,CAAA,KAAM,aAAa;IACzDC,eAAe,EAAEjB,OAAO,CAAC,cAAc,CAAC,CAACe,IAAI;IAC7CG,UAAU,EAAEA,sBAAU;IACtBC,aAAa,EAAEjB,IAAI;IACnBkB,WAAW,EAAElB,IAAI;IACjBmB,sBAAsB,EAAEnB,IAAI;IAC5BoB,YAAY,EAAElB,SAAS;IACvBmB,aAAa,EAAEA,CAAA,MAAO;MACpBC,GAAG,EAAE;QACHnB,OAAO,EAAE;MACX,CAAC;MACDoB,IAAI,EAAE;QACJC,KAAK,EAAE,CAAC;QACRC,MAAM,EAAE;MACV;IACF,CAAC,CAAC;IACF;IACAC,QAAQ,EAAExB,SAAS;IACnByB,gBAAgB,EAAEzB,SAAS;IAC3B0B,SAAS,EAAE1B,SAAS;IACpB2B,OAAO,EAAE3B,SAAS;IAClB4B,SAAS,EAAE5B,SAAS;IACpB6B,aAAa,EAAE7B,SAAS;IACxB8B,cAAc,EAAEhC,IAAI;IACpB;IACAiC,cAAc,EAAEA,CAAA,KAAM,IAAI;IAC1BC,QAAQ,EAAE,IAAI;IACdC,QAAQ,EAAE/B,eAAe;IACzBgC,oBAAoB,EAAEhC,eAAe;IACrCiC,iBAAiB,EAAEjC,eAAe;IAClCkC,eAAe,EAAElC,eAAe;IAChCmC,0BAA0B,EAAEnC,eAAe;IAC3CoC,gBAAgB,EAAEpC,eAAe;IACjCqC,cAAc,EAAErC,eAAe;IAC/BsC,cAAc,EAAEtC,eAAe;IAC/BuC,aAAa,EAAEvC,eAAe;IAC9BwC,SAAS,EAAExC,eAAe;IAC1ByC,UAAU,EAAE7C,IAAI;IAChB8C,OAAO,EAAE9C,IAAI;IACb+C,OAAO,EAAEA,CAAA,KAAMpC,IAAI,CAACqC,IAAI,CAAC/C,SAAS,EAAE,CAAC,CAAC;IACtCgD,QAAQ,EAAEjD,IAAI;IACdkD,WAAW,EAAEA,CAAA,KAAM,IAAI;IACvBC,QAAQ,EAAEA,CAAA,KAAM,IAAI;IACpBC,MAAM,EAAEA,CAAA,KAAM,IAAI;IAClBC,QAAQ,EAAEA,CAAA,KAAM;EAClB,CAAC;AACH,CAAC;AAACC,OAAA,CAAAhD,IAAA,GAAAA,IAAA","ignoreList":[]}
1
+ {"version":3,"names":["_web","require","_JsiSkImage","Noop","undefined","NoopValue","current","NoopSharedValue","value","Mock","CanvasKit","global","SkiaApi","JsiSkApi","Skia","Canvas","View","getPreferredHighBitDepthCanvasFormat","SkiaPictureView","JsiSkImage","drawAsPicture","drawAsImage","drawAsImageFromPicture","useCanvasRef","useCanvasSize","ref","size","width","height","useValue","useComputedValue","useTiming","useLoop","useSpring","useClockValue","useValueEffect","isOnMainThread","useClock","usePathInterpolation","useImageAsTexture","useTextureValue","useTextureValueFromPicture","useRSXformBuffer","usePointBuffer","useColorBuffer","useRectBuffer","useBuffer","useRawData","useData","useFont","Font","useFonts","useTypeface","useImage","useSVG","useVideo","exports"],"sources":["index.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport { JsiSkApi } from \"../skia/web\";\nimport { JsiSkImage } from \"../skia/web/JsiSkImage\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst Noop: () => any = () => undefined;\nconst NoopValue = () => ({ current: 0 });\nconst NoopSharedValue = () => ({ value: 0 });\n\nexport const Mock = (CanvasKit: CanvasKit) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n global.SkiaApi = JsiSkApi(CanvasKit);\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const Skia = global.SkiaApi;\n return {\n Skia,\n ...require(\"../renderer/components\"),\n ...require(\"../skia\"),\n ...require(\"../animation\"),\n ...require(\"../dom/types\"),\n ...require(\"../dom/nodes\"),\n Canvas: require(\"react-native\").View,\n getPreferredHighBitDepthCanvasFormat: () => \"rgba16float\",\n SkiaPictureView: require(\"react-native\").View,\n JsiSkImage: JsiSkImage,\n drawAsPicture: Noop,\n drawAsImage: Noop,\n drawAsImageFromPicture: Noop,\n useCanvasRef: NoopValue,\n useCanvasSize: () => ({\n ref: {\n current: 0,\n },\n size: {\n width: 0,\n height: 0,\n },\n }),\n // Skia Animations\n useValue: NoopValue,\n useComputedValue: NoopValue,\n useTiming: NoopValue,\n useLoop: NoopValue,\n useSpring: NoopValue,\n useClockValue: NoopValue,\n useValueEffect: Noop,\n // Reanimated hooks\n isOnMainThread: () => true,\n useClock: NoopSharedValue,\n usePathInterpolation: NoopSharedValue,\n useImageAsTexture: NoopSharedValue,\n useTextureValue: NoopSharedValue,\n useTextureValueFromPicture: NoopSharedValue,\n useRSXformBuffer: NoopSharedValue,\n usePointBuffer: NoopSharedValue,\n useColorBuffer: NoopSharedValue,\n useRectBuffer: NoopSharedValue,\n useBuffer: NoopSharedValue,\n useRawData: Noop,\n useData: Noop,\n useFont: () => Skia.Font(undefined, 0),\n useFonts: Noop,\n useTypeface: () => null,\n useImage: () => null,\n useSVG: () => null,\n useVideo: () => null,\n };\n};\n"],"mappings":";;;;;;AAEA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAEA;AACA,MAAME,IAAe,GAAGA,CAAA,KAAMC,SAAS;AACvC,MAAMC,SAAS,GAAGA,CAAA,MAAO;EAAEC,OAAO,EAAE;AAAE,CAAC,CAAC;AACxC,MAAMC,eAAe,GAAGA,CAAA,MAAO;EAAEC,KAAK,EAAE;AAAE,CAAC,CAAC;AAErC,MAAMC,IAAI,GAAIC,SAAoB,IAAK;EAC5C;EACA;EACAC,MAAM,CAACC,OAAO,GAAG,IAAAC,aAAQ,EAACH,SAAS,CAAC;EACpC;EACA;EACA,MAAMI,IAAI,GAAGH,MAAM,CAACC,OAAO;EAC3B,OAAO;IACLE,IAAI;IACJ,GAAGb,OAAO,CAAC,wBAAwB,CAAC;IACpC,GAAGA,OAAO,CAAC,SAAS,CAAC;IACrB,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1B,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1B,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1Bc,MAAM,EAAEd,OAAO,CAAC,cAAc,CAAC,CAACe,IAAI;IACpCC,oCAAoC,EAAEA,CAAA,KAAM,aAAa;IACzDC,eAAe,EAAEjB,OAAO,CAAC,cAAc,CAAC,CAACe,IAAI;IAC7CG,UAAU,EAAEA,sBAAU;IACtBC,aAAa,EAAEjB,IAAI;IACnBkB,WAAW,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2
2
  import React from "react";
3
3
  import type { MeasureInWindowOnSuccessCallback, MeasureOnSuccessCallback, ViewProps } from "react-native";
4
4
  import type { SharedValue } from "react-native-reanimated";
5
+ import type { AndroidCanvasProps } from "../views/types";
5
6
  import type { SkImage, SkRect, SkSize } from "../skia/types";
6
7
  export interface CanvasRef extends FC<CanvasProps> {
7
8
  makeImageSnapshot(rect?: SkRect): SkImage;
@@ -16,11 +17,16 @@ export declare const useCanvasSize: (userRef?: RefObject<CanvasRef | null>) => {
16
17
  ref: RefObject<CanvasRef | null>;
17
18
  size: SkSize;
18
19
  };
19
- export declare const isFabric: boolean;
20
20
  export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
21
21
  debug?: boolean;
22
- /** @deprecated Not supported on Fabric. Use `onSize` or `useCanvasSize()` instead. */
22
+ /** @deprecated Not supported on native. Use `onSize` or `useCanvasSize()` instead. */
23
23
  onLayout?: ViewProps["onLayout"];
24
+ /**
25
+ * Declares that the canvas covers every pixel of its bounds, so nothing
26
+ * behind it needs to show through. On Android an opaque canvas is backed by
27
+ * a `SurfaceView` by default, the cheapest path (see `android.surfaceType`).
28
+ * Defaults to false.
29
+ */
24
30
  opaque?: boolean;
25
31
  onSize?: SharedValue<SkSize>;
26
32
  colorSpace?: "p3" | "srgb";
@@ -33,8 +39,10 @@ export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
33
39
  * before the canvas is mounted.
34
40
  */
35
41
  highBitDepth?: boolean;
42
+ /** Android-only rendering options. Ignored on iOS and web. */
43
+ android?: AndroidCanvasProps;
36
44
  ref?: React.Ref<CanvasRef>;
37
45
  androidWarmup?: boolean;
38
46
  __destroyWebGLContextAfterRender?: boolean;
39
47
  }
40
- export declare const Canvas: ({ debug, opaque, children, onSize, colorSpace, highBitDepth, androidWarmup, ref, onLayout, ...viewProps }: CanvasProps) => React.JSX.Element;
48
+ export declare const Canvas: ({ debug, opaque, children, onSize, colorSpace, highBitDepth, androidWarmup, android, ref, onLayout, ...viewProps }: CanvasProps) => React.JSX.Element;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useCanvasSize = exports.useCanvasRef = exports.isFabric = exports.Canvas = void 0;
6
+ exports.useCanvasSize = exports.useCanvasRef = exports.Canvas = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _ReanimatedProxy = _interopRequireDefault(require("../external/reanimated/ReanimatedProxy"));
9
9
  var _SkiaViewNativeId = require("../views/SkiaViewNativeId");
@@ -12,7 +12,6 @@ var _Reconciler = require("../sksg/Reconciler");
12
12
  var _skia = require("../skia");
13
13
  var _Platform = require("../Platform");
14
14
  var _external = require("../external");
15
- var _global;
16
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
16
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
18
17
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
@@ -44,10 +43,10 @@ const useCanvasSize = userRef => {
44
43
  size
45
44
  };
46
45
  };
47
-
48
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
46
  exports.useCanvasSize = useCanvasSize;
50
- const isFabric = exports.isFabric = Boolean((_global = global) === null || _global === void 0 ? void 0 : _global.nativeFabricUIManager);
47
+ // Anything else reaching the native component would hit the generated
48
+ // string-enum parser, which aborts on unknown values.
49
+ const resolveSurfaceType = surfaceType => surfaceType === "SurfaceView" || surfaceType === "TextureView" ? surfaceType : "auto";
51
50
  const Canvas = ({
52
51
  debug,
53
52
  opaque,
@@ -56,11 +55,12 @@ const Canvas = ({
56
55
  colorSpace = "p3",
57
56
  highBitDepth = false,
58
57
  androidWarmup = false,
58
+ android,
59
59
  ref,
60
60
  onLayout,
61
61
  ...viewProps
62
62
  }) => {
63
- if (onLayout && isFabric) {
63
+ if (onLayout && _Platform.Platform.OS !== "web") {
64
64
  console.error("<Canvas onLayout={onLayout} /> is not supported on the new architecture, to fix the issue, see: https://shopify.github.io/react-native-skia/docs/canvas/overview/#getting-the-canvas-size");
65
65
  }
66
66
  const viewRef = useCanvasRefPriv(null);
@@ -162,6 +162,8 @@ const Canvas = ({
162
162
  colorSpace: colorSpace,
163
163
  highBitDepth: highBitDepth,
164
164
  androidWarmup: androidWarmup,
165
+ androidSurfaceType: resolveSurfaceType(android === null || android === void 0 ? void 0 : android.surfaceType),
166
+ androidZOrderOnTop: !!(android !== null && android !== void 0 && android.zOrderOnTop),
165
167
  onLayout: _Platform.Platform.OS === "web" && (onSize || onLayout) ? onLayoutWeb : onLayout
166
168
  }, viewProps));
167
169
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_ReanimatedProxy","_interopRequireDefault","_SkiaViewNativeId","_SkiaPictureViewNativeComponent","_Reconciler","_skia","_Platform","_external","_global","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","useCanvasRef","useRef","exports","useReanimatedFrame","HAS_REANIMATED_3","Rea","useFrameCallback","measure","useCanvasRefPriv","useAnimatedRef","useCanvasSize","userRef","ourRef","ref","size","setSize","useState","width","height","useLayoutEffect","current","_x","_y","isFabric","Boolean","global","nativeFabricUIManager","Canvas","debug","opaque","children","onSize","colorSpace","highBitDepth","androidWarmup","onLayout","viewProps","console","error","viewRef","nativeId","useMemo","SkiaViewNativeId","root","SkiaSGRoot","Skia","_viewRef$current","result","Platform","OS","canvasRef","value","render","useEffect","unmount","useImperativeHandle","makeImageSnapshot","rect","SkiaViewApi","makeImageSnapshotAsync","redraw","requestRedraw","getNativeId","callback","_viewRef$current2","measureInWindow","_viewRef$current3","onLayoutWeb","useCallback","nativeEvent","layout","createElement","collapsable","nativeID"],"sources":["Canvas.tsx"],"sourcesContent":["import type { FC, RefObject } from \"react\";\nimport React, {\n useCallback,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type {\n LayoutChangeEvent,\n MeasureInWindowOnSuccessCallback,\n MeasureOnSuccessCallback,\n View,\n ViewProps,\n} from \"react-native\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport Rea from \"../external/reanimated/ReanimatedProxy\";\nimport { SkiaViewNativeId } from \"../views/SkiaViewNativeId\";\nimport SkiaPictureViewNativeComponent from \"../specs/SkiaPictureViewNativeComponent\";\nimport type { SkImage, SkRect, SkSize } from \"../skia/types\";\nimport { SkiaSGRoot } from \"../sksg/Reconciler\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\nimport { HAS_REANIMATED_3 } from \"../external\";\n\nexport interface CanvasRef extends FC<CanvasProps> {\n makeImageSnapshot(rect?: SkRect): SkImage;\n makeImageSnapshotAsync(rect?: SkRect): Promise<SkImage>;\n redraw(): void;\n getNativeId(): number;\n measure(callback: MeasureOnSuccessCallback): void;\n measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;\n}\n\nexport const useCanvasRef = () => useRef<CanvasRef>(null);\n\nconst useReanimatedFrame = !HAS_REANIMATED_3 ? () => {} : Rea.useFrameCallback;\nconst measure = !HAS_REANIMATED_3 ? null : Rea.measure;\n\nconst useCanvasRefPriv: typeof useRef<View> = !HAS_REANIMATED_3\n ? useRef\n : Rea.useAnimatedRef;\n\nexport const useCanvasSize = (userRef?: RefObject<CanvasRef | null>) => {\n const ourRef = useCanvasRef();\n const ref = userRef ?? ourRef;\n const [size, setSize] = useState<SkSize>({ width: 0, height: 0 });\n useLayoutEffect(() => {\n if (ref.current) {\n ref.current.measure((_x, _y, width, height) => {\n setSize({ width, height });\n });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return { ref, size };\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isFabric = Boolean((global as any)?.nativeFabricUIManager);\n\nexport interface CanvasProps extends Omit<ViewProps, \"onLayout\"> {\n debug?: boolean;\n /** @deprecated Not supported on Fabric. Use `onSize` or `useCanvasSize()` instead. */\n onLayout?: ViewProps[\"onLayout\"];\n opaque?: boolean;\n onSize?: SharedValue<SkSize>;\n colorSpace?: \"p3\" | \"srgb\";\n /**\n * Renders into a surface with more than 8 bits per channel (16-bit float on\n * iOS, 10-bit on Android) to avoid banding in subtle gradients. Colors are\n * identical to the default 8-bit surface, only with more precision (this is\n * about bit depth, not HDR). On Android the extra precision survives\n * composition only when combined with `opaque`, and the prop must be set\n * before the canvas is mounted.\n */\n highBitDepth?: boolean;\n ref?: React.Ref<CanvasRef>;\n androidWarmup?: boolean;\n __destroyWebGLContextAfterRender?: boolean;\n}\n\nexport const Canvas = ({\n debug,\n opaque,\n children,\n onSize,\n colorSpace = \"p3\",\n highBitDepth = false,\n androidWarmup = false,\n ref,\n onLayout,\n ...viewProps\n}: CanvasProps) => {\n if (onLayout && isFabric) {\n console.error(\n \"<Canvas onLayout={onLayout} /> is not supported on the new architecture, to fix the issue, see: https://shopify.github.io/react-native-skia/docs/canvas/overview/#getting-the-canvas-size\"\n );\n }\n const viewRef = useCanvasRefPriv(null);\n // Native ID\n const nativeId = useMemo(() => {\n return SkiaViewNativeId.current++;\n }, []);\n\n // Root\n const root = useMemo(() => new SkiaSGRoot(Skia, nativeId), [nativeId]);\n\n useReanimatedFrame(() => {\n \"worklet\";\n if (onSize && measure) {\n const result =\n // eslint-disable-next-line no-nested-ternary\n Platform.OS === \"web\"\n ? // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n viewRef.current?.canvasRef\n ? // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n measure(viewRef.current.canvasRef)\n : { width: 0, height: 0 }\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n measure(viewRef as any);\n if (result) {\n const { width, height } = result;\n if (onSize.value.width !== width || onSize.value.height !== height) {\n onSize.value = { width, height };\n }\n }\n }\n }, !!onSize);\n\n // Render effects\n useLayoutEffect(() => {\n root.render(children);\n }, [children, root, nativeId]);\n\n useEffect(() => {\n return () => {\n root.unmount();\n };\n }, [root]);\n\n // Component methods\n useImperativeHandle(\n ref,\n () =>\n ({\n makeImageSnapshot: (rect?: SkRect) => {\n return SkiaViewApi.makeImageSnapshot(nativeId, rect);\n },\n makeImageSnapshotAsync: (rect?: SkRect) => {\n return SkiaViewApi.makeImageSnapshotAsync(nativeId, rect);\n },\n redraw: () => {\n SkiaViewApi.requestRedraw(nativeId);\n },\n getNativeId: () => {\n return nativeId;\n },\n measure: (callback) => {\n viewRef.current?.measure(callback);\n },\n measureInWindow: (callback) => {\n viewRef.current?.measureInWindow(callback);\n },\n }) as CanvasRef\n );\n\n const onLayoutWeb = useCallback(\n (e: LayoutChangeEvent) => {\n if (onLayout) {\n onLayout(e);\n }\n if (Platform.OS === \"web\" && onSize) {\n const { width, height } = e.nativeEvent.layout;\n onSize.value = { width, height };\n }\n },\n [onLayout, onSize]\n );\n return (\n <SkiaPictureViewNativeComponent\n ref={viewRef}\n collapsable={false}\n nativeID={`${nativeId}`}\n debug={debug}\n opaque={opaque}\n colorSpace={colorSpace}\n highBitDepth={highBitDepth}\n androidWarmup={androidWarmup}\n onLayout={\n Platform.OS === \"web\" && (onSize || onLayout) ? onLayoutWeb : onLayout\n }\n {...viewProps}\n />\n );\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,uBAAA,C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IAC3BC,aAAa,EAAEA,aAAc;IAC7BC,QAAQ,EACNa,kBAAQ,CAACC,EAAE,KAAK,KAAK,KAAKlB,MAAM,IAAII,QAAQ,CAAC,GAAGgC,WAAW,GAAGhC;EAC/D,GACGC,SAAS,CACd,CAAC;AAEN,CAAC;AAAClC,OAAA,CAAAyB,MAAA,GAAAA,MAAA","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_ReanimatedProxy","_interopRequireDefault","_SkiaViewNativeId","_SkiaPictureViewNativeComponent","_Reconciler","_skia","_Platform","_external","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","useCanvasRef","useRef","exports","useReanimatedFrame","HAS_REANIMATED_3","Rea","useFrameCallback","measure","useCanvasRefPriv","useAnimatedRef","useCanvasSize","userRef","ourRef","ref","size","setSize","useState","width","height","useLayoutEffect","current","_x","_y","resolveSurfaceType","surfaceType","Canvas","debug","opaque","children","onSize","colorSpace","highBitDepth","androidWarmup","android","onLayout","viewProps","Platform","OS","console","error","viewRef","nativeId","useMemo","SkiaViewNativeId","root","SkiaSGRoot","Skia","_viewRef$current","result","canvasRef","value","render","useEffect","unmount","useImperativeHandle","makeImageSnapshot","rect","SkiaViewApi","makeImageSnapshotAsync","redraw","requestRedraw","getNativeId","callback","_viewRef$current2","measureInWindow","_viewRef$current3","onLayoutWeb","useCallback","nativeEvent","layout","createElement","collapsable","nativeID","androidSurfaceType","androidZOrderOnTop","zOrderOnTop"],"sources":["Canvas.tsx"],"sourcesContent":["import type { FC, RefObject } from \"react\";\nimport React, {\n useCallback,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type {\n LayoutChangeEvent,\n MeasureInWindowOnSuccessCallback,\n MeasureOnSuccessCallback,\n View,\n ViewProps,\n} from \"react-native\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport Rea from \"../external/reanimated/ReanimatedProxy\";\nimport { SkiaViewNativeId } from \"../views/SkiaViewNativeId\";\nimport type { AndroidCanvasProps, AndroidSurfaceType } from \"../views/types\";\nimport SkiaPictureViewNativeComponent from \"../specs/SkiaPictureViewNativeComponent\";\nimport type { SkImage, SkRect, SkSize } from \"../skia/types\";\nimport { SkiaSGRoot } from \"../sksg/Reconciler\";\nimport { Skia } from \"../skia\";\nimport { Platform } from \"../Platform\";\nimport { HAS_REANIMATED_3 } from \"../external\";\n\nexport interface CanvasRef extends FC<CanvasProps> {\n makeImageSnapshot(rect?: SkRect): SkImage;\n makeImageSnapshotAsync(rect?: SkRect): Promise<SkImage>;\n redraw(): void;\n getNativeId(): number;\n measure(callback: MeasureOnSuccessCallback): void;\n measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;\n}\n\nexport const useCanvasRef = () => useRef<CanvasRef>(null);\n\nconst useReanimatedFrame = !HAS_REANIMATED_3 ? () => {} : Rea.useFrameCallback;\nconst measure = !HAS_REANIMATED_3 ? null : Rea.measure;\n\nconst useCanvasRefPriv: typeof useRef<View> = !HAS_REANIMATED_3\n ? useRef\n : Rea.useAnimatedRef;\n\nexport const useCanvasSize = (userRef?: RefObject<CanvasRef | null>) => {\n const ourRef = useCanvasRef();\n const ref = userRef ?? ourRef;\n const [size, setSize] = useState<SkSize>({ width: 0, height: 0 });\n useLayoutEffect(() => {\n if (ref.current) {\n ref.current.measure((_x, _y, width, height) => {\n setSize({ width, height });\n });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return { ref, size };\n};\n\nexport interface CanvasProps extends Omit<ViewProps, \"onLayout\"> {\n debug?: boolean;\n /** @deprecated Not supported on native. Use `onSize` or `useCanvasSize()` instead. */\n onLayout?: ViewProps[\"onLayout\"];\n /**\n * Declares that the canvas covers every pixel of its bounds, so nothing\n * behind it needs to show through. On Android an opaque canvas is backed by\n * a `SurfaceView` by default, the cheapest path (see `android.surfaceType`).\n * Defaults to false.\n */\n opaque?: boolean;\n onSize?: SharedValue<SkSize>;\n colorSpace?: \"p3\" | \"srgb\";\n /**\n * Renders into a surface with more than 8 bits per channel (16-bit float on\n * iOS, 10-bit on Android) to avoid banding in subtle gradients. Colors are\n * identical to the default 8-bit surface, only with more precision (this is\n * about bit depth, not HDR). On Android the extra precision survives\n * composition only when combined with `opaque`, and the prop must be set\n * before the canvas is mounted.\n */\n highBitDepth?: boolean;\n /** Android-only rendering options. Ignored on iOS and web. */\n android?: AndroidCanvasProps;\n ref?: React.Ref<CanvasRef>;\n androidWarmup?: boolean;\n __destroyWebGLContextAfterRender?: boolean;\n}\n\n// Anything else reaching the native component would hit the generated\n// string-enum parser, which aborts on unknown values.\nconst resolveSurfaceType = (\n surfaceType: AndroidSurfaceType | undefined\n): \"auto\" | AndroidSurfaceType =>\n surfaceType === \"SurfaceView\" || surfaceType === \"TextureView\"\n ? surfaceType\n : \"auto\";\n\nexport const Canvas = ({\n debug,\n opaque,\n children,\n onSize,\n colorSpace = \"p3\",\n highBitDepth = false,\n androidWarmup = false,\n android,\n ref,\n onLayout,\n ...viewProps\n}: CanvasProps) => {\n if (onLayout && Platform.OS !== \"web\") {\n console.error(\n \"<Canvas onLayout={onLayout} /> is not supported on the new architecture, to fix the issue, see: https://shopify.github.io/react-native-skia/docs/canvas/overview/#getting-the-canvas-size\"\n );\n }\n const viewRef = useCanvasRefPriv(null);\n // Native ID\n const nativeId = useMemo(() => {\n return SkiaViewNativeId.current++;\n }, []);\n\n // Root\n const root = useMemo(() => new SkiaSGRoot(Skia, nativeId), [nativeId]);\n\n useReanimatedFrame(() => {\n \"worklet\";\n if (onSize && measure) {\n const result =\n // eslint-disable-next-line no-nested-ternary\n Platform.OS === \"web\"\n ? // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n viewRef.current?.canvasRef\n ? // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n measure(viewRef.current.canvasRef)\n : { width: 0, height: 0 }\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n measure(viewRef as any);\n if (result) {\n const { width, height } = result;\n if (onSize.value.width !== width || onSize.value.height !== height) {\n onSize.value = { width, height };\n }\n }\n }\n }, !!onSize);\n\n // Render effects\n useLayoutEffect(() => {\n root.render(children);\n }, [children, root, nativeId]);\n\n useEffect(() => {\n return () => {\n root.unmount();\n };\n }, [root]);\n\n // Component methods\n useImperativeHandle(\n ref,\n () =>\n ({\n makeImageSnapshot: (rect?: SkRect) => {\n return SkiaViewApi.makeImageSnapshot(nativeId, rect);\n },\n makeImageSnapshotAsync: (rect?: SkRect) => {\n return SkiaViewApi.makeImageSnapshotAsync(nativeId, rect);\n },\n redraw: () => {\n SkiaViewApi.requestRedraw(nativeId);\n },\n getNativeId: () => {\n return nativeId;\n },\n measure: (callback) => {\n viewRef.current?.measure(callback);\n },\n measureInWindow: (callback) => {\n viewRef.current?.measureInWindow(callback);\n },\n }) as CanvasRef\n );\n\n const onLayoutWeb = useCallback(\n (e: LayoutChangeEvent) => {\n if (onLayout) {\n onLayout(e);\n }\n if (Platform.OS === \"web\" && onSize) {\n const { width, height } = e.nativeEvent.layout;\n onSize.value = { width, height };\n }\n },\n [onLayout, onSize]\n );\n return (\n <SkiaPictureViewNativeComponent\n ref={viewRef}\n collapsable={false}\n nativeID={`${nativeId}`}\n debug={debug}\n opaque={opaque}\n colorSpace={colorSpace}\n highBitDepth={highBitDepth}\n androidWarmup={androidWarmup}\n androidSurfaceType={resolveSurfaceType(android?.surfaceType)}\n androidZOrderOnTop={!!android?.zOrderOnTop}\n onLayout={\n Platform.OS === \"web\" && (onSize || onLayout) ? onLayoutWeb : onLayout\n }\n {...viewProps}\n />\n );\n};\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAkBA,IAAAC,gBAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AAEA,IAAAI,+BAAA,GAAA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,EAAE,CAAC,EAACzC,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAE0C,WAAW,CAAC;IAC3CzC,QAAQ,EACNE,kBAAQ,CAACC,EAAE,KAAK,KAAK,KAAKR,MAAM,IAAIK,QAAQ,CAAC,GAAGgC,WAAW,GAAGhC;EAC/D,GACGC,SAAS,CACd,CAAC;AAEN,CAAC;AAACjC,OAAA,CAAAuB,MAAA,GAAAA,MAAA","ignoreList":[]}
@@ -60,10 +60,15 @@ class JsiSkCanvas extends _Host.HostObject {
60
60
  this.ref.drawVertices(_JsiSkVertices.JsiSkVertices.fromValue(verts), (0, _Host.getEnum)(this.CanvasKit, "BlendMode", mode), _JsiSkPaint.JsiSkPaint.fromValue(paint));
61
61
  }
62
62
  drawPatch(cubics, colors, texs, mode, paint) {
63
- this.ref.drawPatch(cubics.map(({
64
- x,
65
- y
66
- }) => [x, y]).flat(), colors, texs ? texs.flatMap(p => Array.from(_JsiSkPoint.JsiSkPoint.fromValue(p))) : texs, mode !== undefined && mode !== null ? (0, _Host.getEnum)(this.CanvasKit, "BlendMode", mode) : null, paint ? _JsiSkPaint.JsiSkPaint.fromValue(paint) : undefined);
63
+ const defaultPaint = paint ? null : new this.CanvasKit.Paint();
64
+ try {
65
+ this.ref.drawPatch(cubics.map(({
66
+ x,
67
+ y
68
+ }) => [x, y]).flat(), colors, texs ? texs.flatMap(p => Array.from(_JsiSkPoint.JsiSkPoint.fromValue(p))) : texs, mode !== undefined && mode !== null ? (0, _Host.getEnum)(this.CanvasKit, "BlendMode", mode) : null, paint ? _JsiSkPaint.JsiSkPaint.fromValue(paint) : defaultPaint);
69
+ } finally {
70
+ defaultPaint === null || defaultPaint === void 0 || defaultPaint.delete();
71
+ }
67
72
  }
68
73
  restoreToCount(saveCount) {
69
74
  this.ref.restoreToCount(saveCount);