@shopify/react-native-skia 2.2.14 → 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.
- package/apple/MetalContext.h +3 -25
- package/apple/MetalContext.mm +7 -3
- package/apple/MetalWindowContext.mm +1 -1
- package/apple/RNSkMetalCanvasProvider.mm +3 -6
- package/cpp/api/JsiSkImage.h +20 -1
- package/cpp/api/JsiSkSurface.h +20 -1
- package/cpp/api/JsiSkThreadSafeDeletion.h +105 -0
- package/cpp/api/recorder/Drawings.h +7 -7
- package/cpp/jsi/JsiHostObject.cpp +0 -27
- package/cpp/jsi/JsiHostObject.h +5 -5
- package/cpp/jsi/ViewProperty.h +34 -2
- package/cpp/rnskia/RNSkJsiViewApi.h +14 -24
- package/cpp/rnskia/RNSkPictureView.h +25 -2
- package/cpp/rnskia/RNSkView.h +7 -0
- package/lib/commonjs/Platform/Platform.js +2 -1
- package/lib/commonjs/Platform/Platform.js.map +1 -1
- package/lib/commonjs/Platform/Platform.web.js +3 -0
- package/lib/commonjs/Platform/Platform.web.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.js +35 -1
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/skia/core/SVG.web.js +1 -1
- package/lib/commonjs/skia/core/SVG.web.js.map +1 -1
- package/lib/commonjs/skia/types/Data/Data.d.ts +6 -1
- package/lib/commonjs/skia/types/Data/Data.js.map +1 -1
- package/lib/commonjs/sksg/Container.d.ts +2 -3
- package/lib/commonjs/sksg/Container.js +1 -1
- package/lib/commonjs/sksg/Container.js.map +1 -1
- package/lib/commonjs/sksg/Container.native.d.ts +3 -5
- package/lib/commonjs/sksg/Container.native.js +8 -15
- package/lib/commonjs/sksg/Container.native.js.map +1 -1
- package/lib/commonjs/sksg/Container.web.d.ts +2 -3
- package/lib/commonjs/sksg/Container.web.js +1 -1
- package/lib/commonjs/sksg/Container.web.js.map +1 -1
- package/lib/commonjs/sksg/Reconciler.d.ts +2 -3
- package/lib/commonjs/sksg/Reconciler.js +2 -2
- package/lib/commonjs/sksg/Reconciler.js.map +1 -1
- package/lib/module/Platform/Platform.js +2 -1
- package/lib/module/Platform/Platform.js.map +1 -1
- package/lib/module/Platform/Platform.web.js +3 -0
- package/lib/module/Platform/Platform.web.js.map +1 -1
- package/lib/module/renderer/Canvas.js +35 -1
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/skia/core/SVG.web.js +1 -1
- package/lib/module/skia/core/SVG.web.js.map +1 -1
- package/lib/module/skia/types/Data/Data.d.ts +6 -1
- package/lib/module/skia/types/Data/Data.js.map +1 -1
- package/lib/module/sksg/Container.d.ts +2 -3
- package/lib/module/sksg/Container.js +1 -1
- package/lib/module/sksg/Container.js.map +1 -1
- package/lib/module/sksg/Container.native.d.ts +3 -5
- package/lib/module/sksg/Container.native.js +8 -15
- package/lib/module/sksg/Container.native.js.map +1 -1
- package/lib/module/sksg/Container.web.d.ts +2 -3
- package/lib/module/sksg/Container.web.js +1 -1
- package/lib/module/sksg/Container.web.js.map +1 -1
- package/lib/module/sksg/Reconciler.d.ts +2 -3
- package/lib/module/sksg/Reconciler.js +2 -2
- package/lib/module/sksg/Reconciler.js.map +1 -1
- package/lib/typescript/lib/commonjs/sksg/Container.d.ts +1 -1
- package/lib/typescript/lib/commonjs/sksg/Container.native.d.ts +2 -3
- package/lib/typescript/lib/commonjs/sksg/Container.web.d.ts +1 -1
- package/lib/typescript/lib/commonjs/sksg/Reconciler.d.ts +1 -1
- package/lib/typescript/lib/module/sksg/Container.d.ts +1 -1
- package/lib/typescript/lib/module/sksg/Container.native.d.ts +2 -3
- package/lib/typescript/lib/module/sksg/Container.web.d.ts +1 -1
- package/lib/typescript/lib/module/sksg/Reconciler.d.ts +1 -1
- package/lib/typescript/src/skia/types/Data/Data.d.ts +6 -1
- package/lib/typescript/src/sksg/Container.d.ts +2 -3
- package/lib/typescript/src/sksg/Container.native.d.ts +3 -5
- package/lib/typescript/src/sksg/Container.web.d.ts +2 -3
- package/lib/typescript/src/sksg/Reconciler.d.ts +2 -3
- package/package.json +1 -1
- package/src/Platform/Platform.ts +3 -0
- package/src/Platform/Platform.web.tsx +3 -0
- package/src/renderer/Canvas.tsx +33 -3
- package/src/skia/core/SVG.web.ts +3 -0
- package/src/skia/types/Data/Data.ts +7 -1
- package/src/sksg/Container.native.ts +10 -27
- package/src/sksg/Container.ts +2 -8
- package/src/sksg/Container.web.ts +2 -8
- package/src/sksg/Reconciler.ts +3 -4
package/src/renderer/Canvas.tsx
CHANGED
@@ -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
|
-
|
93
|
-
|
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(() => {
|
package/src/skia/core/SVG.web.ts
CHANGED
@@ -7,7 +7,13 @@ type ESModule = {
|
|
7
7
|
__esModule: true;
|
8
8
|
default: string;
|
9
9
|
};
|
10
|
-
|
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
|
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
|
-
|
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((
|
42
|
+
Rea.runOnUI(() => {
|
55
43
|
"worklet";
|
56
|
-
nativeDrawOnscreen(nativeId, sharedRecorder
|
57
|
-
})(
|
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
|
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
|
58
|
+
return new NativeReanimatedContainer(Skia, nativeId);
|
76
59
|
} else {
|
77
60
|
return new StaticContainer(Skia, nativeId);
|
78
61
|
}
|
package/src/sksg/Container.ts
CHANGED
@@ -1,13 +1,7 @@
|
|
1
|
-
import type {
|
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
|
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 {
|
package/src/sksg/Reconciler.ts
CHANGED
@@ -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
|
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
|
28
|
-
this.container = createContainer(Skia, nativeId
|
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,
|