@shopify/react-native-skia 2.2.13 → 2.2.15

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 (81) hide show
  1. package/apple/MetalContext.h +3 -25
  2. package/apple/MetalContext.mm +7 -3
  3. package/apple/MetalWindowContext.mm +1 -1
  4. package/apple/RNSkMetalCanvasProvider.mm +3 -6
  5. package/cpp/api/JsiSkImage.h +20 -1
  6. package/cpp/api/JsiSkSurface.h +20 -1
  7. package/cpp/api/JsiSkThreadSafeDeletion.h +105 -0
  8. package/cpp/api/recorder/Drawings.h +4 -4
  9. package/cpp/jsi/JsiHostObject.cpp +0 -27
  10. package/cpp/jsi/JsiHostObject.h +5 -5
  11. package/cpp/jsi/ViewProperty.h +34 -2
  12. package/cpp/rnskia/RNSkJsiViewApi.h +14 -24
  13. package/cpp/rnskia/RNSkPictureView.h +25 -2
  14. package/cpp/rnskia/RNSkView.h +7 -0
  15. package/lib/commonjs/Platform/Platform.js +2 -1
  16. package/lib/commonjs/Platform/Platform.js.map +1 -1
  17. package/lib/commonjs/Platform/Platform.web.js +3 -0
  18. package/lib/commonjs/Platform/Platform.web.js.map +1 -1
  19. package/lib/commonjs/renderer/Canvas.js +35 -1
  20. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  21. package/lib/commonjs/skia/core/SVG.web.js +1 -1
  22. package/lib/commonjs/skia/core/SVG.web.js.map +1 -1
  23. package/lib/commonjs/skia/types/Data/Data.d.ts +6 -1
  24. package/lib/commonjs/skia/types/Data/Data.js.map +1 -1
  25. package/lib/commonjs/sksg/Container.d.ts +2 -3
  26. package/lib/commonjs/sksg/Container.js +1 -1
  27. package/lib/commonjs/sksg/Container.js.map +1 -1
  28. package/lib/commonjs/sksg/Container.native.d.ts +3 -5
  29. package/lib/commonjs/sksg/Container.native.js +8 -15
  30. package/lib/commonjs/sksg/Container.native.js.map +1 -1
  31. package/lib/commonjs/sksg/Container.web.d.ts +2 -3
  32. package/lib/commonjs/sksg/Container.web.js +1 -1
  33. package/lib/commonjs/sksg/Container.web.js.map +1 -1
  34. package/lib/commonjs/sksg/Reconciler.d.ts +2 -3
  35. package/lib/commonjs/sksg/Reconciler.js +2 -2
  36. package/lib/commonjs/sksg/Reconciler.js.map +1 -1
  37. package/lib/module/Platform/Platform.js +2 -1
  38. package/lib/module/Platform/Platform.js.map +1 -1
  39. package/lib/module/Platform/Platform.web.js +3 -0
  40. package/lib/module/Platform/Platform.web.js.map +1 -1
  41. package/lib/module/renderer/Canvas.js +35 -1
  42. package/lib/module/renderer/Canvas.js.map +1 -1
  43. package/lib/module/skia/core/SVG.web.js +1 -1
  44. package/lib/module/skia/core/SVG.web.js.map +1 -1
  45. package/lib/module/skia/types/Data/Data.d.ts +6 -1
  46. package/lib/module/skia/types/Data/Data.js.map +1 -1
  47. package/lib/module/sksg/Container.d.ts +2 -3
  48. package/lib/module/sksg/Container.js +1 -1
  49. package/lib/module/sksg/Container.js.map +1 -1
  50. package/lib/module/sksg/Container.native.d.ts +3 -5
  51. package/lib/module/sksg/Container.native.js +8 -15
  52. package/lib/module/sksg/Container.native.js.map +1 -1
  53. package/lib/module/sksg/Container.web.d.ts +2 -3
  54. package/lib/module/sksg/Container.web.js +1 -1
  55. package/lib/module/sksg/Container.web.js.map +1 -1
  56. package/lib/module/sksg/Reconciler.d.ts +2 -3
  57. package/lib/module/sksg/Reconciler.js +2 -2
  58. package/lib/module/sksg/Reconciler.js.map +1 -1
  59. package/lib/typescript/lib/commonjs/sksg/Container.d.ts +1 -1
  60. package/lib/typescript/lib/commonjs/sksg/Container.native.d.ts +2 -3
  61. package/lib/typescript/lib/commonjs/sksg/Container.web.d.ts +1 -1
  62. package/lib/typescript/lib/commonjs/sksg/Reconciler.d.ts +1 -1
  63. package/lib/typescript/lib/module/sksg/Container.d.ts +1 -1
  64. package/lib/typescript/lib/module/sksg/Container.native.d.ts +2 -3
  65. package/lib/typescript/lib/module/sksg/Container.web.d.ts +1 -1
  66. package/lib/typescript/lib/module/sksg/Reconciler.d.ts +1 -1
  67. package/lib/typescript/src/skia/types/Data/Data.d.ts +6 -1
  68. package/lib/typescript/src/sksg/Container.d.ts +2 -3
  69. package/lib/typescript/src/sksg/Container.native.d.ts +3 -5
  70. package/lib/typescript/src/sksg/Container.web.d.ts +2 -3
  71. package/lib/typescript/src/sksg/Reconciler.d.ts +2 -3
  72. package/package.json +1 -1
  73. package/src/Platform/Platform.ts +3 -0
  74. package/src/Platform/Platform.web.tsx +3 -0
  75. package/src/renderer/Canvas.tsx +33 -3
  76. package/src/skia/core/SVG.web.ts +3 -0
  77. package/src/skia/types/Data/Data.ts +7 -1
  78. package/src/sksg/Container.native.ts +10 -27
  79. package/src/sksg/Container.ts +2 -8
  80. package/src/sksg/Container.web.ts +2 -8
  81. package/src/sksg/Reconciler.ts +3 -4
@@ -17,6 +17,7 @@ import type {
17
17
  } from "react-native";
18
18
  import { type SharedValue } from "react-native-reanimated";
19
19
 
20
+ import Rea from "../external/reanimated/ReanimatedProxy";
20
21
  import { SkiaViewNativeId } from "../views/SkiaViewNativeId";
21
22
  import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeComponent";
22
23
  import type { SkImage, SkRect, SkSize } from "../skia/types";
@@ -88,10 +89,39 @@ export const Canvas = ({
88
89
  }, []);
89
90
 
90
91
  // Root
91
- const root = useMemo(
92
- () => new SkiaSGRoot(Skia, nativeId, onSize),
93
- [nativeId, onSize]
92
+ const root = useMemo(() => new SkiaSGRoot(Skia, nativeId), [nativeId]);
93
+
94
+ const updateSize = useCallback(
95
+ (value: SkSize) => {
96
+ if (onSize) {
97
+ onSize.value = value;
98
+ }
99
+ },
100
+ [onSize]
94
101
  );
102
+ useEffect(() => {
103
+ if (onSize) {
104
+ const { runOnJS } = Rea;
105
+ const uiOnSize = Rea.makeMutable({ width: 0, height: 0 });
106
+ Rea.runOnUI(() => {
107
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
108
+ // @ts-expect-error
109
+ global[`__onSize_${nativeId}`] = uiOnSize;
110
+ uiOnSize.addListener(nativeId, (value) => {
111
+ runOnJS(updateSize)(value);
112
+ });
113
+ })();
114
+ return () => {
115
+ Rea.runOnUI(() => {
116
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
117
+ // @ts-expect-error
118
+ delete global[`__onSize_${nativeId}`];
119
+ uiOnSize.removeListener(nativeId);
120
+ })();
121
+ };
122
+ }
123
+ return undefined;
124
+ }, [onSize, nativeId, updateSize]);
95
125
 
96
126
  // Render effects
97
127
  useLayoutEffect(() => {
@@ -11,6 +11,9 @@ export const useSVG = (
11
11
  if (
12
12
  typeof source !== "object" ||
13
13
  source instanceof Uint8Array ||
14
+ !("uri" in source) ||
15
+ typeof source.uri !== "string" ||
16
+ !("default" in source) ||
14
17
  typeof source.default !== "string"
15
18
  ) {
16
19
  throw new Error(
@@ -7,7 +7,13 @@ type ESModule = {
7
7
  __esModule: true;
8
8
  default: string;
9
9
  };
10
- export type DataModule = RNModule | ESModule;
10
+ type MetroAsset = {
11
+ uri: string;
12
+ width: number;
13
+ height: number;
14
+ };
15
+
16
+ export type DataModule = RNModule | ESModule | MetroAsset;
11
17
  export type DataSource = DataModule | string | Uint8Array;
12
18
  export type DataSourceParam = DataSource | null | undefined;
13
19
 
@@ -1,7 +1,5 @@
1
- import type { SharedValue } from "react-native-reanimated";
2
-
3
1
  import Rea from "../external/reanimated/ReanimatedProxy";
4
- import type { Skia, SkSize } from "../skia/types";
2
+ import type { Skia } from "../skia/types";
5
3
  import { HAS_REANIMATED_3 } from "../external/reanimated/renderHelpers";
6
4
  import type { JsiRecorder } from "../skia/types/Recorder";
7
5
 
@@ -12,15 +10,9 @@ import { visit } from "./Recorder/Visitor";
12
10
  import "../skia/NativeSetup";
13
11
  import "../views/api";
14
12
 
15
- const nativeDrawOnscreen = (
16
- nativeId: number,
17
- recorder: JsiRecorder,
18
- onSize?: SharedValue<SkSize>
19
- ) => {
13
+ const nativeDrawOnscreen = (nativeId: number, recorder: JsiRecorder) => {
20
14
  "worklet";
21
- if (onSize) {
22
- SkiaViewApi.setJsiProperty(nativeId, "onSize", onSize);
23
- }
15
+
24
16
  //const start = performance.now();
25
17
  const picture = recorder.play();
26
18
  //const end = performance.now();
@@ -31,11 +23,7 @@ const nativeDrawOnscreen = (
31
23
  class NativeReanimatedContainer extends Container {
32
24
  private mapperId: number | null = null;
33
25
 
34
- constructor(
35
- Skia: Skia,
36
- private nativeId: number,
37
- private onSize?: SharedValue<SkSize>
38
- ) {
26
+ constructor(Skia: Skia, private nativeId: number) {
39
27
  super(Skia);
40
28
  }
41
29
 
@@ -51,28 +39,23 @@ class NativeReanimatedContainer extends Container {
51
39
  visit(recorder, this.root);
52
40
  const sharedValues = recorder.getSharedValues();
53
41
  const sharedRecorder = recorder.getRecorder();
54
- Rea.runOnUI((onSize?: SharedValue<SkSize>) => {
42
+ Rea.runOnUI(() => {
55
43
  "worklet";
56
- nativeDrawOnscreen(nativeId, sharedRecorder, onSize);
57
- })(this.onSize);
44
+ nativeDrawOnscreen(nativeId, sharedRecorder);
45
+ })();
58
46
  if (sharedValues.length > 0) {
59
- const { onSize } = this;
60
47
  this.mapperId = Rea.startMapper(() => {
61
48
  "worklet";
62
49
  sharedRecorder.applyUpdates(sharedValues);
63
- nativeDrawOnscreen(nativeId, sharedRecorder, onSize);
50
+ nativeDrawOnscreen(nativeId, sharedRecorder);
64
51
  }, sharedValues);
65
52
  }
66
53
  }
67
54
  }
68
55
 
69
- export const createContainer = (
70
- Skia: Skia,
71
- nativeId: number,
72
- onSize?: SharedValue<SkSize>
73
- ) => {
56
+ export const createContainer = (Skia: Skia, nativeId: number) => {
74
57
  if (HAS_REANIMATED_3 && nativeId !== -1) {
75
- return new NativeReanimatedContainer(Skia, nativeId, onSize);
58
+ return new NativeReanimatedContainer(Skia, nativeId);
76
59
  } else {
77
60
  return new StaticContainer(Skia, nativeId);
78
61
  }
@@ -1,13 +1,7 @@
1
- import type { SharedValue } from "react-native-reanimated";
2
-
3
- import type { Skia, SkSize } from "../skia/types";
1
+ import type { Skia } from "../skia/types";
4
2
 
5
3
  import { StaticContainer } from "./StaticContainer";
6
4
 
7
- export const createContainer = (
8
- Skia: Skia,
9
- nativeId: number,
10
- _onSize?: SharedValue<SkSize>
11
- ) => {
5
+ export const createContainer = (Skia: Skia, nativeId: number) => {
12
6
  return new StaticContainer(Skia, nativeId);
13
7
  };
@@ -1,7 +1,5 @@
1
- import type { SharedValue } from "react-native-reanimated";
2
-
3
1
  import Rea from "../external/reanimated/ReanimatedProxy";
4
- import type { Skia, SkSize } from "../skia/types";
2
+ import type { Skia } from "../skia/types";
5
3
  import { HAS_REANIMATED_3 } from "../external/reanimated/renderHelpers";
6
4
 
7
5
  import type { Recording } from "./Recorder/Recorder";
@@ -64,11 +62,7 @@ class ReanimatedContainer extends Container {
64
62
  }
65
63
  }
66
64
 
67
- export const createContainer = (
68
- Skia: Skia,
69
- nativeId: number,
70
- _onSize?: SharedValue<SkSize>
71
- ) => {
65
+ export const createContainer = (Skia: Skia, nativeId: number) => {
72
66
  if (HAS_REANIMATED_3 && nativeId !== -1) {
73
67
  return new ReanimatedContainer(Skia, nativeId);
74
68
  } else {
@@ -1,9 +1,8 @@
1
1
  import type { ReactNode } from "react";
2
2
  import type { OpaqueRoot } from "react-reconciler";
3
- import type { SharedValue } from "react-native-reanimated";
4
3
  import ReactReconciler from "react-reconciler";
5
4
 
6
- import type { SkCanvas, Skia, SkSize } from "../skia/types";
5
+ import type { SkCanvas, Skia } from "../skia/types";
7
6
  import { NodeType } from "../dom/types";
8
7
 
9
8
  import { debug, sksgHostConfig } from "./HostConfig";
@@ -24,8 +23,8 @@ export class SkiaSGRoot {
24
23
  private root: OpaqueRoot;
25
24
  private container: Container;
26
25
 
27
- constructor(public Skia: Skia, nativeId = -1, onSize?: SharedValue<SkSize>) {
28
- this.container = createContainer(Skia, nativeId, onSize);
26
+ constructor(public Skia: Skia, nativeId = -1) {
27
+ this.container = createContainer(Skia, nativeId);
29
28
  this.root = skiaReconciler.createContainer(
30
29
  this.container,
31
30
  0,