@shopify/react-native-skia 0.1.180 → 0.1.182

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. package/android/build.gradle +6 -1
  2. package/cpp/api/JsiSkData.h +7 -0
  3. package/cpp/api/JsiSkImage.h +7 -1
  4. package/cpp/api/JsiSkSVG.h +7 -0
  5. package/cpp/api/JsiSkTypeface.h +7 -0
  6. package/cpp/jsi/RuntimeAwareCache.cpp +0 -2
  7. package/cpp/rnskia/RNSkDomView.cpp +2 -2
  8. package/cpp/rnskia/RNSkPlatformContext.h +2 -2
  9. package/cpp/rnskia/dom/base/DerivedNodeProp.h +1 -1
  10. package/cpp/rnskia/dom/base/JsiDependencyManager.h +10 -6
  11. package/cpp/rnskia/dom/base/JsiDomNode.h +133 -78
  12. package/cpp/rnskia/dom/base/JsiDomRenderNode.h +17 -5
  13. package/cpp/rnskia/dom/base/NodeProp.h +5 -5
  14. package/cpp/rnskia/dom/base/NodePropsContainer.h +8 -2
  15. package/cpp/rnskia/dom/props/ClipProp.h +13 -20
  16. package/cpp/rnskia/dom/props/PathProp.h +16 -14
  17. package/cpp/rnskia/dom/props/PointProp.h +1 -1
  18. package/cpp/rnskia/dom/props/RRectProp.h +39 -61
  19. package/cpp/rnskia/dom/props/RectProp.h +27 -25
  20. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +0 -2
  21. package/lib/commonjs/dom/nodes/JsiSkDOM.js +56 -54
  22. package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
  23. package/lib/commonjs/renderer/Canvas.js +30 -9
  24. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  25. package/lib/commonjs/renderer/HostComponents.d.ts +1 -0
  26. package/lib/commonjs/renderer/HostComponents.js +6 -1
  27. package/lib/commonjs/renderer/HostComponents.js.map +1 -1
  28. package/lib/commonjs/renderer/Reconciler.js +3 -1
  29. package/lib/commonjs/renderer/Reconciler.js.map +1 -1
  30. package/lib/commonjs/skia/core/Data.d.ts +2 -2
  31. package/lib/commonjs/skia/core/Data.js +5 -0
  32. package/lib/commonjs/skia/core/Data.js.map +1 -1
  33. package/lib/commonjs/skia/types/Data/Data.d.ts +2 -2
  34. package/lib/commonjs/skia/types/Data/Data.js.map +1 -1
  35. package/lib/commonjs/skia/types/Image/Image.d.ts +2 -2
  36. package/lib/commonjs/skia/types/Image/Image.js.map +1 -1
  37. package/lib/commonjs/skia/types/JsiInstance.d.ts +3 -0
  38. package/lib/commonjs/skia/types/JsiInstance.js.map +1 -1
  39. package/lib/commonjs/skia/types/SVG/SVG.d.ts +2 -2
  40. package/lib/commonjs/skia/types/SVG/SVG.js.map +1 -1
  41. package/lib/commonjs/skia/types/Typeface/Typeface.d.ts +2 -2
  42. package/lib/commonjs/skia/types/Typeface/Typeface.js.map +1 -1
  43. package/lib/commonjs/skia/web/JsiSkData.d.ts +1 -0
  44. package/lib/commonjs/skia/web/JsiSkData.js +3 -0
  45. package/lib/commonjs/skia/web/JsiSkData.js.map +1 -1
  46. package/lib/commonjs/skia/web/JsiSkImage.d.ts +1 -0
  47. package/lib/commonjs/skia/web/JsiSkImage.js +4 -0
  48. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  49. package/lib/commonjs/skia/web/JsiSkTypeface.d.ts +1 -0
  50. package/lib/commonjs/skia/web/JsiSkTypeface.js +4 -0
  51. package/lib/commonjs/skia/web/JsiSkTypeface.js.map +1 -1
  52. package/lib/commonjs/views/SkiaBaseWebView.js +5 -1
  53. package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
  54. package/lib/module/dom/nodes/JsiSkDOM.js +55 -54
  55. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  56. package/lib/module/renderer/Canvas.js +29 -10
  57. package/lib/module/renderer/Canvas.js.map +1 -1
  58. package/lib/module/renderer/HostComponents.d.ts +1 -0
  59. package/lib/module/renderer/HostComponents.js +3 -0
  60. package/lib/module/renderer/HostComponents.js.map +1 -1
  61. package/lib/module/renderer/Reconciler.js +2 -1
  62. package/lib/module/renderer/Reconciler.js.map +1 -1
  63. package/lib/module/skia/core/Data.d.ts +2 -2
  64. package/lib/module/skia/core/Data.js +5 -0
  65. package/lib/module/skia/core/Data.js.map +1 -1
  66. package/lib/module/skia/types/Data/Data.d.ts +2 -2
  67. package/lib/module/skia/types/Data/Data.js.map +1 -1
  68. package/lib/module/skia/types/Image/Image.d.ts +2 -2
  69. package/lib/module/skia/types/Image/Image.js.map +1 -1
  70. package/lib/module/skia/types/JsiInstance.d.ts +3 -0
  71. package/lib/module/skia/types/JsiInstance.js.map +1 -1
  72. package/lib/module/skia/types/SVG/SVG.d.ts +2 -2
  73. package/lib/module/skia/types/SVG/SVG.js.map +1 -1
  74. package/lib/module/skia/types/Typeface/Typeface.d.ts +2 -2
  75. package/lib/module/skia/types/Typeface/Typeface.js.map +1 -1
  76. package/lib/module/skia/web/JsiSkData.d.ts +1 -0
  77. package/lib/module/skia/web/JsiSkData.js +3 -0
  78. package/lib/module/skia/web/JsiSkData.js.map +1 -1
  79. package/lib/module/skia/web/JsiSkImage.d.ts +1 -0
  80. package/lib/module/skia/web/JsiSkImage.js +4 -0
  81. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  82. package/lib/module/skia/web/JsiSkTypeface.d.ts +1 -0
  83. package/lib/module/skia/web/JsiSkTypeface.js +4 -0
  84. package/lib/module/skia/web/JsiSkTypeface.js.map +1 -1
  85. package/lib/module/views/SkiaBaseWebView.js +5 -1
  86. package/lib/module/views/SkiaBaseWebView.js.map +1 -1
  87. package/lib/typescript/src/renderer/HostComponents.d.ts +1 -0
  88. package/lib/typescript/src/skia/core/Data.d.ts +2 -2
  89. package/lib/typescript/src/skia/types/Data/Data.d.ts +2 -2
  90. package/lib/typescript/src/skia/types/Image/Image.d.ts +2 -2
  91. package/lib/typescript/src/skia/types/JsiInstance.d.ts +3 -0
  92. package/lib/typescript/src/skia/types/SVG/SVG.d.ts +2 -2
  93. package/lib/typescript/src/skia/types/Typeface/Typeface.d.ts +2 -2
  94. package/lib/typescript/src/skia/web/JsiSkData.d.ts +1 -0
  95. package/lib/typescript/src/skia/web/JsiSkImage.d.ts +1 -0
  96. package/lib/typescript/src/skia/web/JsiSkTypeface.d.ts +1 -0
  97. package/package.json +1 -1
  98. package/src/dom/nodes/JsiSkDOM.ts +55 -54
  99. package/src/renderer/Canvas.tsx +34 -14
  100. package/src/renderer/HostComponents.ts +4 -0
  101. package/src/renderer/Reconciler.tsx +2 -1
  102. package/src/skia/core/Data.ts +14 -6
  103. package/src/skia/types/Data/Data.ts +2 -2
  104. package/src/skia/types/Image/Image.ts +2 -2
  105. package/src/skia/types/JsiInstance.ts +4 -0
  106. package/src/skia/types/SVG/SVG.ts +2 -2
  107. package/src/skia/types/Typeface/Typeface.ts +2 -2
  108. package/src/skia/web/JsiSkData.ts +4 -0
  109. package/src/skia/web/JsiSkImage.ts +4 -0
  110. package/src/skia/web/JsiSkTypeface.ts +4 -0
  111. package/src/views/SkiaBaseWebView.tsx +5 -0
@@ -1,3 +1,3 @@
1
- import type { SkData, DataSourceParam } from "../types";
2
- export declare const useRawData: <T>(source: DataSourceParam, factory: (data: SkData) => T, onError?: ((err: Error) => void) | undefined) => T | null;
1
+ import type { SkData, DataSourceParam, JsiDisposable } from "../types";
2
+ export declare const useRawData: <T extends JsiDisposable>(source: DataSourceParam, factory: (data: SkData) => T | null, onError?: ((err: Error) => void) | undefined) => T | null;
3
3
  export declare const useData: (source: DataSourceParam, onError?: ((err: Error) => void) | undefined) => SkData | null;
@@ -1,5 +1,5 @@
1
- import type { SkJSIInstance } from "../JsiInstance";
2
- export declare type SkData = SkJSIInstance<"Data">;
1
+ import type { JsiDisposable, SkJSIInstance } from "../JsiInstance";
2
+ export declare type SkData = SkJSIInstance<"Data"> & JsiDisposable;
3
3
  declare type RNModule = number;
4
4
  declare type ESModule = {
5
5
  __esModule: true;
@@ -1,5 +1,5 @@
1
1
  import type { SkMatrix } from "../Matrix";
2
- import type { SkJSIInstance } from "../JsiInstance";
2
+ import type { JsiDisposable, SkJSIInstance } from "../JsiInstance";
3
3
  import type { TileMode } from "../ImageFilter";
4
4
  import type { SkShader } from "../Shader";
5
5
  export declare enum FilterMode {
@@ -16,7 +16,7 @@ export declare enum ImageFormat {
16
16
  PNG = 4,
17
17
  WEBP = 6
18
18
  }
19
- export interface SkImage extends SkJSIInstance<"Image"> {
19
+ export interface SkImage extends SkJSIInstance<"Image">, JsiDisposable {
20
20
  /**
21
21
  * Returns the possibly scaled height of the image.
22
22
  */
@@ -1,3 +1,6 @@
1
1
  export interface SkJSIInstance<T extends string> {
2
2
  __typename__: T;
3
3
  }
4
+ export interface JsiDisposable {
5
+ dispose: () => void;
6
+ }
@@ -1,2 +1,2 @@
1
- import type { SkJSIInstance } from "../JsiInstance";
2
- export declare type SkSVG = SkJSIInstance<"SVG">;
1
+ import type { JsiDisposable, SkJSIInstance } from "../JsiInstance";
2
+ export declare type SkSVG = SkJSIInstance<"SVG"> & JsiDisposable;
@@ -1,2 +1,2 @@
1
- import type { SkJSIInstance } from "../JsiInstance";
2
- export declare type SkTypeface = SkJSIInstance<"Typeface">;
1
+ import type { JsiDisposable, SkJSIInstance } from "../JsiInstance";
2
+ export declare type SkTypeface = SkJSIInstance<"Typeface"> & JsiDisposable;
@@ -4,5 +4,6 @@ import { HostObject } from "./Host";
4
4
  declare type Data = ArrayBuffer;
5
5
  export declare class JsiSkData extends HostObject<Data, "Data"> implements SkData {
6
6
  constructor(CanvasKit: CanvasKit, ref: Data);
7
+ dispose(): void;
7
8
  }
8
9
  export {};
@@ -10,4 +10,5 @@ export declare class JsiSkImage extends HostObject<Image, "Image"> implements Sk
10
10
  makeShaderCubic(tx: TileMode, ty: TileMode, B: number, C: number, localMatrix?: SkMatrix): SkShader;
11
11
  encodeToBytes(fmt?: ImageFormat, quality?: number): Uint8Array;
12
12
  encodeToBase64(fmt?: ImageFormat, quality?: number): string;
13
+ dispose(): void;
13
14
  }
@@ -5,4 +5,5 @@ export declare class JsiSkTypeface extends HostObject<Typeface, "Typeface"> impl
5
5
  constructor(CanvasKit: CanvasKit, ref: Typeface);
6
6
  get bold(): boolean;
7
7
  get italic(): boolean;
8
+ dispose(): void;
8
9
  }
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "setup-skia-web": "./scripts/setup-canvaskit.js"
8
8
  },
9
9
  "title": "React Native Skia",
10
- "version": "0.1.180",
10
+ "version": "0.1.182",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "files": [
@@ -56,6 +56,7 @@ import type {
56
56
  Path1DPathEffectProps,
57
57
  Path2DPathEffectProps,
58
58
  } from "../types/PathEffects";
59
+ import { NATIVE_DOM } from "../../renderer/HostComponents";
59
60
 
60
61
  import {
61
62
  FillNode,
@@ -127,203 +128,203 @@ export class JsiSkDOM implements SkDOM {
127
128
  constructor(private ctx: NodeContext) {}
128
129
 
129
130
  Layer(props?: ChildrenProps) {
130
- return global.SkiaDomApi && global.SkiaDomApi.LayerNode
131
+ return NATIVE_DOM
131
132
  ? global.SkiaDomApi.LayerNode(props ?? {})
132
133
  : new LayerNode(this.ctx, props ?? {});
133
134
  }
134
135
 
135
136
  Group(props?: GroupProps) {
136
- return global.SkiaDomApi && global.SkiaDomApi.GroupNode
137
+ return NATIVE_DOM
137
138
  ? global.SkiaDomApi.GroupNode(props ?? {})
138
139
  : new GroupNode(this.ctx, props ?? {});
139
140
  }
140
141
 
141
142
  Paint(props: PaintProps) {
142
- return global.SkiaDomApi && global.SkiaDomApi.PaintNode
143
+ return NATIVE_DOM
143
144
  ? global.SkiaDomApi.PaintNode(props ?? {})
144
145
  : new PaintNode(this.ctx, props);
145
146
  }
146
147
 
147
148
  // Drawings
148
149
  Fill(props?: DrawingNodeProps) {
149
- return global.SkiaDomApi && global.SkiaDomApi.FillNode
150
+ return NATIVE_DOM
150
151
  ? global.SkiaDomApi.FillNode(props ?? {})
151
152
  : new FillNode(this.ctx, props);
152
153
  }
153
154
 
154
155
  Image(props: ImageProps) {
155
- return global.SkiaDomApi && global.SkiaDomApi.ImageNode
156
+ return NATIVE_DOM
156
157
  ? global.SkiaDomApi.ImageNode(props ?? {})
157
158
  : new ImageNode(this.ctx, props);
158
159
  }
159
160
 
160
161
  Circle(props: CircleProps) {
161
- return global.SkiaDomApi && global.SkiaDomApi.CircleNode
162
+ return NATIVE_DOM
162
163
  ? global.SkiaDomApi.CircleNode(props ?? {})
163
164
  : new CircleNode(this.ctx, props);
164
165
  }
165
166
 
166
167
  Path(props: PathProps) {
167
- return global.SkiaDomApi && global.SkiaDomApi.PathNode
168
+ return NATIVE_DOM
168
169
  ? global.SkiaDomApi.PathNode(props ?? {})
169
170
  : new PathNode(this.ctx, props);
170
171
  }
171
172
 
172
173
  CustomDrawing(props: CustomDrawingNodeProps) {
173
- return global.SkiaDomApi && global.SkiaDomApi.CustomDrawingNode
174
+ return NATIVE_DOM
174
175
  ? global.SkiaDomApi.CustomDrawingNode(props ?? {})
175
176
  : new CustomDrawingNode(this.ctx, props);
176
177
  }
177
178
 
178
179
  Line(props: LineProps) {
179
- return global.SkiaDomApi && global.SkiaDomApi.LineNode
180
+ return NATIVE_DOM
180
181
  ? global.SkiaDomApi.LineNode(props ?? {})
181
182
  : new LineNode(this.ctx, props);
182
183
  }
183
184
 
184
185
  Oval(props: OvalProps) {
185
- return global.SkiaDomApi && global.SkiaDomApi.OvalNode
186
+ return NATIVE_DOM
186
187
  ? global.SkiaDomApi.OvalNode(props ?? {})
187
188
  : new OvalNode(this.ctx, props);
188
189
  }
189
190
 
190
191
  Patch(props: PatchProps) {
191
- return global.SkiaDomApi && global.SkiaDomApi.PatchNode
192
+ return NATIVE_DOM
192
193
  ? global.SkiaDomApi.PatchNode(props ?? {})
193
194
  : new PatchNode(this.ctx, props);
194
195
  }
195
196
 
196
197
  Points(props: PointsProps) {
197
- return global.SkiaDomApi && global.SkiaDomApi.PointsNode
198
+ return NATIVE_DOM
198
199
  ? global.SkiaDomApi.PointsNode(props ?? {})
199
200
  : new PointsNode(this.ctx, props);
200
201
  }
201
202
 
202
203
  Rect(props: RectProps) {
203
- return global.SkiaDomApi && global.SkiaDomApi.RectNode
204
+ return NATIVE_DOM
204
205
  ? global.SkiaDomApi.RectNode(props)
205
206
  : new RectNode(this.ctx, props);
206
207
  }
207
208
 
208
209
  RRect(props: RoundedRectProps) {
209
- return global.SkiaDomApi && global.SkiaDomApi.RRectNode
210
+ return NATIVE_DOM
210
211
  ? global.SkiaDomApi.RRectNode(props)
211
212
  : new RRectNode(this.ctx, props);
212
213
  }
213
214
 
214
215
  Vertices(props: VerticesProps) {
215
- return global.SkiaDomApi && global.SkiaDomApi.VerticesNode
216
+ return NATIVE_DOM
216
217
  ? global.SkiaDomApi.VerticesNode(props)
217
218
  : new VerticesNode(this.ctx, props);
218
219
  }
219
220
 
220
221
  Text(props: TextProps) {
221
- return global.SkiaDomApi && global.SkiaDomApi.TextNode
222
+ return NATIVE_DOM
222
223
  ? global.SkiaDomApi.TextNode(props)
223
224
  : new TextNode(this.ctx, props);
224
225
  }
225
226
 
226
227
  TextPath(props: TextPathProps) {
227
- return global.SkiaDomApi && global.SkiaDomApi.TextPathNode
228
+ return NATIVE_DOM
228
229
  ? global.SkiaDomApi.TextPathNode(props)
229
230
  : new TextPathNode(this.ctx, props);
230
231
  }
231
232
 
232
233
  TextBlob(props: TextBlobProps) {
233
- return global.SkiaDomApi && global.SkiaDomApi.TextBlobNode
234
+ return NATIVE_DOM
234
235
  ? global.SkiaDomApi.TextBlobNode(props)
235
236
  : new TextBlobNode(this.ctx, props);
236
237
  }
237
238
 
238
239
  Glyphs(props: GlyphsProps) {
239
- return global.SkiaDomApi && global.SkiaDomApi.GlyphsNode
240
+ return NATIVE_DOM
240
241
  ? global.SkiaDomApi.GlyphsNode(props)
241
242
  : new GlyphsNode(this.ctx, props);
242
243
  }
243
244
 
244
245
  DiffRect(props: DiffRectProps) {
245
- return global.SkiaDomApi && global.SkiaDomApi.DiffRectNode
246
+ return NATIVE_DOM
246
247
  ? global.SkiaDomApi.DiffRectNode(props)
247
248
  : new DiffRectNode(this.ctx, props);
248
249
  }
249
250
 
250
251
  Picture(props: PictureProps) {
251
- return global.SkiaDomApi && global.SkiaDomApi.PictureNode
252
+ return NATIVE_DOM
252
253
  ? global.SkiaDomApi.PictureNode(props)
253
254
  : new PictureNode(this.ctx, props);
254
255
  }
255
256
 
256
257
  ImageSVG(props: ImageSVGProps) {
257
- return global.SkiaDomApi && global.SkiaDomApi.ImageSVGNode
258
+ return NATIVE_DOM
258
259
  ? global.SkiaDomApi.ImageSVGNode(props)
259
260
  : new ImageSVGNode(this.ctx, props);
260
261
  }
261
262
 
262
263
  // BlurMaskFilters
263
264
  BlurMaskFilter(props: BlurMaskFilterProps) {
264
- return global.SkiaDomApi && global.SkiaDomApi.BlurMaskFilterNode
265
+ return NATIVE_DOM
265
266
  ? global.SkiaDomApi.BlurMaskFilterNode(props)
266
267
  : new BlurMaskFilterNode(this.ctx, props);
267
268
  }
268
269
 
269
270
  // ImageFilters
270
271
  BlendImageFilter(props: BlendImageFilterProps) {
271
- return global.SkiaDomApi && global.SkiaDomApi.BlendImageFilterNode
272
+ return NATIVE_DOM
272
273
  ? global.SkiaDomApi.BlendImageFilterNode(props)
273
274
  : new BlendImageFilterNode(this.ctx, props);
274
275
  }
275
276
 
276
277
  DropShadowImageFilter(props: DropShadowImageFilterProps) {
277
- return global.SkiaDomApi && global.SkiaDomApi.DropShadowImageFilterNode
278
+ return NATIVE_DOM
278
279
  ? global.SkiaDomApi.DropShadowImageFilterNode(props)
279
280
  : new DropShadowImageFilterNode(this.ctx, props);
280
281
  }
281
282
 
282
283
  DisplacementMapImageFilter(props: DisplacementMapImageFilterProps) {
283
- return global.SkiaDomApi && global.SkiaDomApi.DisplacementMapImageFilterNode
284
+ return NATIVE_DOM
284
285
  ? global.SkiaDomApi.DisplacementMapImageFilterNode(props)
285
286
  : new DisplacementMapImageFilterNode(this.ctx, props);
286
287
  }
287
288
 
288
289
  BlurImageFilter(props: BlurImageFilterProps) {
289
- return global.SkiaDomApi && global.SkiaDomApi.BlurImageFilterNode
290
+ return NATIVE_DOM
290
291
  ? global.SkiaDomApi.BlurImageFilterNode(props)
291
292
  : new BlurImageFilterNode(this.ctx, props);
292
293
  }
293
294
 
294
295
  OffsetImageFilter(props: OffsetImageFilterProps) {
295
- return global.SkiaDomApi && global.SkiaDomApi.OffsetImageFilterNode
296
+ return NATIVE_DOM
296
297
  ? global.SkiaDomApi.OffsetImageFilterNode(props)
297
298
  : new OffsetImageFilterNode(this.ctx, props);
298
299
  }
299
300
 
300
301
  MorphologyImageFilter(props: MorphologyImageFilterProps) {
301
- return global.SkiaDomApi && global.SkiaDomApi.MorphologyImageFilterNode
302
+ return NATIVE_DOM
302
303
  ? global.SkiaDomApi.MorphologyImageFilterNode(props)
303
304
  : new MorphologyImageFilterNode(this.ctx, props);
304
305
  }
305
306
 
306
307
  RuntimeShaderImageFilter(props: RuntimeShaderImageFilterProps) {
307
- return global.SkiaDomApi && global.SkiaDomApi.RuntimeShaderImageFilterNode
308
+ return NATIVE_DOM
308
309
  ? global.SkiaDomApi.RuntimeShaderImageFilterNode(props)
309
310
  : new RuntimeShaderImageFilterNode(this.ctx, props);
310
311
  }
311
312
 
312
313
  // Color Filters
313
314
  MatrixColorFilter(props: MatrixColorFilterProps) {
314
- return global.SkiaDomApi && global.SkiaDomApi.MatrixColorFilterNode
315
+ return NATIVE_DOM
315
316
  ? global.SkiaDomApi.MatrixColorFilterNode(props)
316
317
  : new MatrixColorFilterNode(this.ctx, props);
317
318
  }
318
319
 
319
320
  BlendColorFilter(props: BlendColorFilterProps) {
320
- return global.SkiaDomApi && global.SkiaDomApi.BlendColorFilterNode
321
+ return NATIVE_DOM
321
322
  ? global.SkiaDomApi.BlendColorFilterNode(props)
322
323
  : new BlendColorFilterNode(this.ctx, props);
323
324
  }
324
325
 
325
326
  LumaColorFilter() {
326
- return global.SkiaDomApi && global.SkiaDomApi.LumaColorFilterNode
327
+ return NATIVE_DOM
327
328
  ? global.SkiaDomApi.LumaColorFilterNode()
328
329
  : new LumaColorFilterNode(this.ctx);
329
330
  }
@@ -343,129 +344,129 @@ export class JsiSkDOM implements SkDOM {
343
344
  }
344
345
 
345
346
  LerpColorFilter(props: LerpColorFilterProps) {
346
- return global.SkiaDomApi && global.SkiaDomApi.LerpColorFilterNode
347
+ return NATIVE_DOM
347
348
  ? global.SkiaDomApi.LerpColorFilterNode(props)
348
349
  : new LerpColorFilterNode(this.ctx, props);
349
350
  }
350
351
 
351
352
  // Shaders
352
353
  Shader(props: ShaderProps) {
353
- return global.SkiaDomApi && global.SkiaDomApi.ShaderNode
354
+ return NATIVE_DOM
354
355
  ? global.SkiaDomApi.ShaderNode(props)
355
356
  : new ShaderNode(this.ctx, props);
356
357
  }
357
358
 
358
359
  ImageShader(props: ImageShaderProps) {
359
- return global.SkiaDomApi && global.SkiaDomApi.ImageShaderNode
360
+ return NATIVE_DOM
360
361
  ? global.SkiaDomApi.ImageShaderNode(props)
361
362
  : new ImageShaderNode(this.ctx, props);
362
363
  }
363
364
 
364
365
  ColorShader(props: ColorProps) {
365
- return global.SkiaDomApi && global.SkiaDomApi.ColorShaderNode
366
+ return NATIVE_DOM
366
367
  ? global.SkiaDomApi.ColorShaderNode(props)
367
368
  : new ColorNode(this.ctx, props);
368
369
  }
369
370
 
370
371
  SweepGradient(props: SweepGradientProps) {
371
- return global.SkiaDomApi && global.SkiaDomApi.SweepGradientNode
372
+ return NATIVE_DOM
372
373
  ? global.SkiaDomApi.SweepGradientNode(props)
373
374
  : new SweepGradientNode(this.ctx, props);
374
375
  }
375
376
 
376
377
  Turbulence(props: TurbulenceProps) {
377
- return global.SkiaDomApi && global.SkiaDomApi.TurbulenceNode
378
+ return NATIVE_DOM
378
379
  ? global.SkiaDomApi.TurbulenceNode(props)
379
380
  : new TurbulenceNode(this.ctx, props);
380
381
  }
381
382
 
382
383
  FractalNoise(props: FractalNoiseProps) {
383
- return global.SkiaDomApi && global.SkiaDomApi.FractalNoiseNode
384
+ return NATIVE_DOM
384
385
  ? global.SkiaDomApi.FractalNoiseNode(props)
385
386
  : new FractalNoiseNode(this.ctx, props);
386
387
  }
387
388
 
388
389
  LinearGradient(props: LinearGradientProps) {
389
- return global.SkiaDomApi && global.SkiaDomApi.LinearGradientNode
390
+ return NATIVE_DOM
390
391
  ? global.SkiaDomApi.LinearGradientNode(props)
391
392
  : new LinearGradientNode(this.ctx, props);
392
393
  }
393
394
 
394
395
  RadialGradient(props: RadialGradientProps) {
395
- return global.SkiaDomApi && global.SkiaDomApi.RadialGradientNode
396
+ return NATIVE_DOM
396
397
  ? global.SkiaDomApi.RadialGradientNode(props)
397
398
  : new RadialGradientNode(this.ctx, props);
398
399
  }
399
400
 
400
401
  TwoPointConicalGradient(props: TwoPointConicalGradientProps) {
401
- return global.SkiaDomApi && global.SkiaDomApi.TwoPointConicalGradientNode
402
+ return NATIVE_DOM
402
403
  ? global.SkiaDomApi.TwoPointConicalGradientNode(props)
403
404
  : new TwoPointConicalGradientNode(this.ctx, props);
404
405
  }
405
406
 
406
407
  // Path Effects
407
408
  CornerPathEffect(props: CornerPathEffectProps) {
408
- return global.SkiaDomApi && global.SkiaDomApi.CornerPathEffectNode
409
+ return NATIVE_DOM
409
410
  ? global.SkiaDomApi.CornerPathEffectNode(props)
410
411
  : new CornerPathEffectNode(this.ctx, props);
411
412
  }
412
413
 
413
414
  DiscretePathEffect(props: DiscretePathEffectProps) {
414
- return global.SkiaDomApi && global.SkiaDomApi.DiscretePathEffectNode
415
+ return NATIVE_DOM
415
416
  ? global.SkiaDomApi.DiscretePathEffectNode(props)
416
417
  : new DiscretePathEffectNode(this.ctx, props);
417
418
  }
418
419
 
419
420
  DashPathEffect(props: DashPathEffectProps) {
420
- return global.SkiaDomApi && global.SkiaDomApi.DashPathEffectNode
421
+ return NATIVE_DOM
421
422
  ? global.SkiaDomApi.DashPathEffectNode(props)
422
423
  : new DashPathEffectNode(this.ctx, props);
423
424
  }
424
425
 
425
426
  Path1DPathEffect(props: Path1DPathEffectProps) {
426
- return global.SkiaDomApi && global.SkiaDomApi.Path1DPathEffectNode
427
+ return NATIVE_DOM
427
428
  ? global.SkiaDomApi.Path1DPathEffectNode(props)
428
429
  : new Path1DPathEffectNode(this.ctx, props);
429
430
  }
430
431
 
431
432
  Path2DPathEffect(props: Path2DPathEffectProps) {
432
- return global.SkiaDomApi && global.SkiaDomApi.Path2DPathEffectNode
433
+ return NATIVE_DOM
433
434
  ? global.SkiaDomApi.Path2DPathEffectNode(props)
434
435
  : new Path2DPathEffectNode(this.ctx, props);
435
436
  }
436
437
 
437
438
  SumPathEffect() {
438
- return global.SkiaDomApi && global.SkiaDomApi.SumPathEffectNode
439
+ return NATIVE_DOM
439
440
  ? global.SkiaDomApi.SumPathEffectNode()
440
441
  : new SumPathEffectNode(this.ctx);
441
442
  }
442
443
 
443
444
  Line2DPathEffect(props: Line2DPathEffectProps) {
444
- return global.SkiaDomApi && global.SkiaDomApi.Line2DPathEffectNode
445
+ return NATIVE_DOM
445
446
  ? global.SkiaDomApi.Line2DPathEffectNode(props)
446
447
  : new Line2DPathEffectNode(this.ctx, props);
447
448
  }
448
449
 
449
450
  Blend(props: BlendProps) {
450
- return global.SkiaDomApi && global.SkiaDomApi.BlendNode
451
+ return NATIVE_DOM
451
452
  ? global.SkiaDomApi.BlendNode(props)
452
453
  : new BlendNode(this.ctx, props);
453
454
  }
454
455
 
455
456
  BackdropFilter(props: ChildrenProps) {
456
- return global.SkiaDomApi && global.SkiaDomApi.BackdropFilterNode
457
+ return NATIVE_DOM
457
458
  ? global.SkiaDomApi.BackdropFilterNode(props)
458
459
  : new BackdropFilterNode(this.ctx, props);
459
460
  }
460
461
 
461
462
  Box(props: BoxProps) {
462
- return global.SkiaDomApi && global.SkiaDomApi.BoxNode
463
+ return NATIVE_DOM
463
464
  ? global.SkiaDomApi.BoxNode(props)
464
465
  : new BoxNode(this.ctx, props);
465
466
  }
466
467
 
467
468
  BoxShadow(props: BoxShadowProps) {
468
- return global.SkiaDomApi && global.SkiaDomApi.BoxShadowNode
469
+ return NATIVE_DOM
469
470
  ? global.SkiaDomApi.BoxShadowNode(props)
470
471
  : new BoxShadowNode(this.ctx, props);
471
472
  }
@@ -12,12 +12,14 @@ import type {
12
12
  ForwardedRef,
13
13
  } from "react";
14
14
 
15
- import { SkiaDomView } from "../views";
15
+ import { SkiaDomView, SkiaView } from "../views";
16
16
  import { Skia } from "../skia/Skia";
17
17
  import type { TouchHandler, SkiaBaseViewProps } from "../views";
18
18
  import type { SkiaValue } from "../values/types";
19
+ import { JsiDrawingContext } from "../dom/types";
19
20
 
20
21
  import { SkiaRoot } from "./Reconciler";
22
+ import { NATIVE_DOM } from "./HostComponents";
21
23
 
22
24
  export const useCanvasRef = () => useRef<SkiaDomView>(null);
23
25
 
@@ -66,19 +68,37 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
66
68
  root.unmount();
67
69
  };
68
70
  }, [root]);
69
-
70
- return (
71
- <SkiaDomView
72
- ref={ref}
73
- style={style}
74
- root={root.dom}
75
- onTouch={onTouch}
76
- onSize={onSize}
77
- mode={mode}
78
- debug={debug}
79
- {...props}
80
- />
81
- );
71
+ if (NATIVE_DOM) {
72
+ return (
73
+ <SkiaDomView
74
+ ref={ref}
75
+ style={style}
76
+ root={root.dom}
77
+ onTouch={onTouch}
78
+ onSize={onSize}
79
+ mode={mode}
80
+ debug={debug}
81
+ {...props}
82
+ />
83
+ );
84
+ } else {
85
+ return (
86
+ <SkiaView
87
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
88
+ ref={ref as any}
89
+ style={style}
90
+ mode={mode}
91
+ debug={debug}
92
+ onSize={onSize}
93
+ onDraw={(canvas, info) => {
94
+ onTouch && onTouch(info.touches);
95
+ const ctx = new JsiDrawingContext(Skia, canvas);
96
+ root.dom.render(ctx);
97
+ }}
98
+ {...props}
99
+ />
100
+ );
101
+ }
82
102
  }
83
103
  ) as React.FC<CanvasProps & React.RefAttributes<SkiaDomView>>;
84
104
 
@@ -65,6 +65,10 @@ import { exhaustiveCheck } from "./typeddash";
65
65
  import type { SkiaProps } from "./processors";
66
66
  import type { DependencyManager } from "./DependencyManager";
67
67
 
68
+ // This flag should only be turned on for debugging/testing
69
+ const shouldUseJSDomOnNative = false;
70
+ export const NATIVE_DOM = shouldUseJSDomOnNative ? false : !!global.SkiaDomApi;
71
+
68
72
  declare global {
69
73
  var SkiaDomApi: {
70
74
  DependencyManager: (
@@ -8,13 +8,14 @@ import type { SkiaValue } from "../values/types";
8
8
  import { DependencyManager } from "./DependencyManager";
9
9
  import { skHostConfig, debug as hostDebug } from "./HostConfig";
10
10
  import { Container } from "./Container";
11
+ import { NATIVE_DOM } from "./HostComponents";
11
12
 
12
13
  const skiaReconciler = ReactReconciler(skHostConfig);
13
14
 
14
15
  type RegisterValues = (values: Array<SkiaValue<unknown>>) => () => void;
15
16
 
16
17
  const createDependencyManager = (registerValues: RegisterValues) =>
17
- global.SkiaDomApi && global.SkiaDomApi.DependencyManager
18
+ NATIVE_DOM
18
19
  ? global.SkiaDomApi.DependencyManager(registerValues)
19
20
  : new DependencyManager(registerValues);
20
21
 
@@ -3,7 +3,12 @@ import { Image } from "react-native";
3
3
 
4
4
  import { Skia } from "../Skia";
5
5
  import { isRNModule } from "../types";
6
- import type { SkData, DataModule, DataSourceParam } from "../types";
6
+ import type {
7
+ SkData,
8
+ DataModule,
9
+ DataSourceParam,
10
+ JsiDisposable,
11
+ } from "../types";
7
12
 
8
13
  const resolveAsset = (source: DataModule) => {
9
14
  return isRNModule(source)
@@ -27,7 +32,7 @@ const factoryWrapper = <T>(
27
32
 
28
33
  const loadData = <T>(
29
34
  source: DataSourceParam,
30
- factory: (data: SkData) => T,
35
+ factory: (data: SkData) => T | null,
31
36
  onError?: (err: Error) => void
32
37
  ): Promise<T | null> => {
33
38
  if (source === null || source === undefined) {
@@ -43,20 +48,23 @@ const loadData = <T>(
43
48
  );
44
49
  }
45
50
  };
46
- const useLoading = <T>(
51
+ const useLoading = <T extends JsiDisposable>(
47
52
  source: DataSourceParam,
48
53
  loader: () => Promise<T | null>
49
54
  ) => {
50
55
  const mounted = useRef(false);
51
56
  const [data, setData] = useState<T | null>(null);
57
+ const dataRef = useRef<T | null>(null);
52
58
  useEffect(() => {
53
59
  mounted.current = true;
54
60
  loader().then((value) => {
55
61
  if (mounted.current) {
56
62
  setData(value);
63
+ dataRef.current = value;
57
64
  }
58
65
  });
59
66
  return () => {
67
+ dataRef.current?.dispose();
60
68
  mounted.current = false;
61
69
  };
62
70
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -64,11 +72,11 @@ const useLoading = <T>(
64
72
  return data;
65
73
  };
66
74
 
67
- export const useRawData = <T>(
75
+ export const useRawData = <T extends JsiDisposable>(
68
76
  source: DataSourceParam,
69
- factory: (data: SkData) => T,
77
+ factory: (data: SkData) => T | null,
70
78
  onError?: (err: Error) => void
71
- ) => useLoading(source, () => loadData(source, factory, onError));
79
+ ) => useLoading(source, () => loadData<T>(source, factory, onError));
72
80
 
73
81
  const identity = (data: SkData) => data;
74
82
 
@@ -1,6 +1,6 @@
1
- import type { SkJSIInstance } from "../JsiInstance";
1
+ import type { JsiDisposable, SkJSIInstance } from "../JsiInstance";
2
2
 
3
- export type SkData = SkJSIInstance<"Data">;
3
+ export type SkData = SkJSIInstance<"Data"> & JsiDisposable;
4
4
 
5
5
  type RNModule = number;
6
6
  type ESModule = {
@@ -1,5 +1,5 @@
1
1
  import type { SkMatrix } from "../Matrix";
2
- import type { SkJSIInstance } from "../JsiInstance";
2
+ import type { JsiDisposable, SkJSIInstance } from "../JsiInstance";
3
3
  import type { TileMode } from "../ImageFilter";
4
4
  import type { SkShader } from "../Shader";
5
5
 
@@ -20,7 +20,7 @@ export enum ImageFormat {
20
20
  WEBP = 6,
21
21
  }
22
22
 
23
- export interface SkImage extends SkJSIInstance<"Image"> {
23
+ export interface SkImage extends SkJSIInstance<"Image">, JsiDisposable {
24
24
  /**
25
25
  * Returns the possibly scaled height of the image.
26
26
  */