@shopify/react-native-skia 2.3.10 → 2.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/cpp/jni/include/JniSkiaBaseView.h +9 -2
- package/android/cpp/jni/include/JniSkiaPictureView.h +97 -2
- package/android/cpp/rnskia-android/OpenGLContext.h +1 -0
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +3 -1
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureView.java +42 -0
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureViewManager.java +5 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerDelegate.java +8 -2
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerInterface.java +1 -0
- package/apple/SkiaCVPixelBufferUtils.mm +8 -4
- package/cpp/api/recorder/Drawings.h +10 -2
- package/cpp/api/recorder/JsiRecorder.h +1 -1
- package/cpp/rnskia/RNSkJsiViewApi.h +2 -0
- package/cpp/rnskia/RNSkPictureView.h +2 -0
- package/lib/commonjs/renderer/Canvas.js +2 -1
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/sksg/Container.native.d.ts +0 -3
- package/lib/commonjs/sksg/Container.native.js +8 -14
- package/lib/commonjs/sksg/Container.native.js.map +1 -1
- package/lib/commonjs/sksg/Reconciler.js +2 -2
- package/lib/commonjs/sksg/Reconciler.js.map +1 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.d.ts +1 -0
- package/lib/commonjs/views/SkiaPictureView.js +3 -1
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.web.js +13 -2
- package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
- package/lib/module/renderer/Canvas.js +2 -1
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/sksg/Container.native.d.ts +0 -3
- package/lib/module/sksg/Container.native.js +8 -14
- package/lib/module/sksg/Container.native.js.map +1 -1
- package/lib/module/sksg/Reconciler.js +2 -2
- package/lib/module/sksg/Reconciler.js.map +1 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/module/views/SkiaPictureView.d.ts +1 -0
- package/lib/module/views/SkiaPictureView.js +3 -1
- package/lib/module/views/SkiaPictureView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.web.js +13 -2
- package/lib/module/views/SkiaPictureView.web.js.map +1 -1
- package/lib/typescript/lib/commonjs/sksg/Container.native.d.ts +0 -4
- package/lib/typescript/lib/module/sksg/Container.native.d.ts +0 -4
- package/lib/typescript/src/sksg/Container.native.d.ts +0 -3
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/typescript/src/views/SkiaPictureView.d.ts +1 -0
- package/package.json +1 -1
- package/src/renderer/Canvas.tsx +4 -2
- package/src/sksg/Container.native.ts +7 -16
- package/src/sksg/Reconciler.ts +2 -2
- package/src/specs/SkiaPictureViewNativeComponent.ts +1 -0
- package/src/views/SkiaPictureView.tsx +3 -1
- package/src/views/SkiaPictureView.web.tsx +14 -2
|
@@ -4,12 +4,8 @@ import _StaticContainer = require("./StaticContainer");
|
|
|
4
4
|
declare class NativeReanimatedContainer extends _StaticContainer.Container {
|
|
5
5
|
constructor(Skia: any, nativeId: any);
|
|
6
6
|
nativeId: any;
|
|
7
|
-
recorderA: _ReanimatedRecorder.ReanimatedRecorder;
|
|
8
|
-
recorderB: _ReanimatedRecorder.ReanimatedRecorder;
|
|
9
|
-
currentRecorder: _ReanimatedRecorder.ReanimatedRecorder;
|
|
10
7
|
picture: any;
|
|
11
8
|
redraw(): void;
|
|
12
9
|
mapperId: any;
|
|
13
10
|
}
|
|
14
|
-
import _ReanimatedRecorder = require("./Recorder/ReanimatedRecorder");
|
|
15
11
|
export {};
|
|
@@ -3,13 +3,9 @@ import { StaticContainer } from "./StaticContainer";
|
|
|
3
3
|
declare class NativeReanimatedContainer extends Container {
|
|
4
4
|
constructor(Skia: any, nativeId: any);
|
|
5
5
|
nativeId: any;
|
|
6
|
-
recorderA: ReanimatedRecorder;
|
|
7
|
-
recorderB: ReanimatedRecorder;
|
|
8
|
-
currentRecorder: ReanimatedRecorder;
|
|
9
6
|
picture: any;
|
|
10
7
|
redraw(): void;
|
|
11
8
|
mapperId: any;
|
|
12
9
|
}
|
|
13
10
|
import { Container } from "./StaticContainer";
|
|
14
|
-
import { ReanimatedRecorder } from "./Recorder/ReanimatedRecorder";
|
|
15
11
|
export {};
|
|
@@ -3,6 +3,7 @@ export interface NativeProps extends ViewProps {
|
|
|
3
3
|
debug?: boolean;
|
|
4
4
|
opaque?: boolean;
|
|
5
5
|
colorSpace?: string;
|
|
6
|
+
coldStart?: boolean;
|
|
6
7
|
}
|
|
7
8
|
declare const _default: import("react-native/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
|
|
8
9
|
export default _default;
|
|
@@ -3,6 +3,7 @@ import type { SkRect } from "../skia/types";
|
|
|
3
3
|
import type { SkiaPictureViewNativeProps } from "./types";
|
|
4
4
|
interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {
|
|
5
5
|
mode?: "default" | "continuous";
|
|
6
|
+
coldStart?: boolean;
|
|
6
7
|
}
|
|
7
8
|
export declare class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
|
|
8
9
|
private requestId;
|
package/package.json
CHANGED
package/src/renderer/Canvas.tsx
CHANGED
|
@@ -160,7 +160,6 @@ export const Canvas = ({
|
|
|
160
160
|
},
|
|
161
161
|
[onLayout, onSize]
|
|
162
162
|
);
|
|
163
|
-
|
|
164
163
|
return (
|
|
165
164
|
<SkiaPictureViewNativeComponent
|
|
166
165
|
ref={viewRef}
|
|
@@ -169,7 +168,10 @@ export const Canvas = ({
|
|
|
169
168
|
debug={debug}
|
|
170
169
|
opaque={opaque}
|
|
171
170
|
colorSpace={colorSpace}
|
|
172
|
-
|
|
171
|
+
coldStart={false}
|
|
172
|
+
onLayout={
|
|
173
|
+
Platform.OS === "web" && (onSize || onLayout) ? onLayoutWeb : onLayout
|
|
174
|
+
}
|
|
173
175
|
{...viewProps}
|
|
174
176
|
/>
|
|
175
177
|
);
|
|
@@ -27,18 +27,12 @@ const nativeDrawOnscreen = (
|
|
|
27
27
|
class NativeReanimatedContainer extends Container {
|
|
28
28
|
private mapperId: number | null = null;
|
|
29
29
|
private picture: SkPicture;
|
|
30
|
-
private recorderA: ReanimatedRecorder;
|
|
31
|
-
private recorderB: ReanimatedRecorder;
|
|
32
|
-
private currentRecorder: ReanimatedRecorder;
|
|
33
30
|
|
|
34
31
|
constructor(
|
|
35
32
|
Skia: Skia,
|
|
36
33
|
private nativeId: number
|
|
37
34
|
) {
|
|
38
35
|
super(Skia);
|
|
39
|
-
this.recorderA = new ReanimatedRecorder(Skia);
|
|
40
|
-
this.recorderB = new ReanimatedRecorder(Skia);
|
|
41
|
-
this.currentRecorder = this.recorderA;
|
|
42
36
|
this.picture = Skia.Picture.MakePicture(null)!;
|
|
43
37
|
}
|
|
44
38
|
|
|
@@ -49,21 +43,18 @@ class NativeReanimatedContainer extends Container {
|
|
|
49
43
|
if (this.unmounted) {
|
|
50
44
|
return;
|
|
51
45
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const recorder = this.currentRecorder;
|
|
55
|
-
this.currentRecorder =
|
|
56
|
-
this.currentRecorder === this.recorderA ? this.recorderB : this.recorderA;
|
|
57
|
-
|
|
58
|
-
const { nativeId, picture } = this;
|
|
59
|
-
recorder.reset();
|
|
46
|
+
const recorder = new ReanimatedRecorder(this.Skia);
|
|
47
|
+
const { nativeId, picture, Skia } = this;
|
|
60
48
|
visit(recorder, this.root);
|
|
61
49
|
const sharedValues = recorder.getSharedValues();
|
|
62
50
|
const sharedRecorder = recorder.getRecorder();
|
|
63
|
-
|
|
51
|
+
// Draw first frame
|
|
52
|
+
Rea.executeOnUIRuntimeSync(() => {
|
|
64
53
|
"worklet";
|
|
65
|
-
|
|
54
|
+
const firstPicture = Skia.Picture.MakePicture(null)!;
|
|
55
|
+
nativeDrawOnscreen(nativeId, sharedRecorder, firstPicture);
|
|
66
56
|
})();
|
|
57
|
+
// Animate
|
|
67
58
|
if (sharedValues.length > 0) {
|
|
68
59
|
this.mapperId = Rea.startMapper(() => {
|
|
69
60
|
"worklet";
|
package/src/sksg/Reconciler.ts
CHANGED
|
@@ -27,12 +27,13 @@ export class SkiaSGRoot {
|
|
|
27
27
|
public Skia: Skia,
|
|
28
28
|
nativeId = -1
|
|
29
29
|
) {
|
|
30
|
+
const strictMode = false;
|
|
30
31
|
this.container = createContainer(Skia, nativeId);
|
|
31
32
|
this.root = skiaReconciler.createContainer(
|
|
32
33
|
this.container,
|
|
33
34
|
0,
|
|
34
35
|
null,
|
|
35
|
-
|
|
36
|
+
strictMode,
|
|
36
37
|
null,
|
|
37
38
|
"",
|
|
38
39
|
console.error,
|
|
@@ -48,7 +49,6 @@ export class SkiaSGRoot {
|
|
|
48
49
|
private updateContainer(element: ReactNode) {
|
|
49
50
|
return new Promise((resolve) => {
|
|
50
51
|
skiaReconciler.updateContainer(element, this.root, null, () => {
|
|
51
|
-
debug("updateContainer");
|
|
52
52
|
resolve(true);
|
|
53
53
|
});
|
|
54
54
|
});
|
|
@@ -11,6 +11,7 @@ const NativeSkiaPictureView = SkiaPictureViewNativeComponent;
|
|
|
11
11
|
|
|
12
12
|
interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {
|
|
13
13
|
mode?: "default" | "continuous";
|
|
14
|
+
coldStart?: boolean;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
|
|
@@ -82,13 +83,14 @@ export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
render() {
|
|
85
|
-
const { mode, debug = false, opaque = false, ...viewProps } = this.props;
|
|
86
|
+
const { mode, debug = false, opaque = false, coldStart = false, ...viewProps } = this.props;
|
|
86
87
|
return (
|
|
87
88
|
<NativeSkiaPictureView
|
|
88
89
|
collapsable={false}
|
|
89
90
|
nativeID={`${this._nativeId}`}
|
|
90
91
|
debug={debug}
|
|
91
92
|
opaque={opaque}
|
|
93
|
+
coldStart={coldStart}
|
|
92
94
|
{...viewProps}
|
|
93
95
|
/>
|
|
94
96
|
);
|
|
@@ -16,6 +16,18 @@ import type { ISkiaViewApiWeb } from "../specs/NativeSkiaModule.web";
|
|
|
16
16
|
import type { SkiaPictureViewNativeProps } from "./types";
|
|
17
17
|
import { SkiaViewNativeId } from "./SkiaViewNativeId";
|
|
18
18
|
|
|
19
|
+
const dp2Pixel = (pd: number, rect?: SkRect) => {
|
|
20
|
+
if (!rect) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
x: rect.x * pd,
|
|
25
|
+
y: rect.y * pd,
|
|
26
|
+
width: rect.width * pd,
|
|
27
|
+
height: rect.height * pd,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
19
31
|
interface Renderer {
|
|
20
32
|
onResize(): void;
|
|
21
33
|
draw(picture: SkPicture): void;
|
|
@@ -41,7 +53,7 @@ class WebGLRenderer implements Renderer {
|
|
|
41
53
|
canvas!.clear(CanvasKit.TRANSPARENT);
|
|
42
54
|
this.draw(picture);
|
|
43
55
|
this.surface.ref.flush();
|
|
44
|
-
return this.surface.makeImageSnapshot(rect);
|
|
56
|
+
return this.surface.makeImageSnapshot(dp2Pixel(this.pd, rect));
|
|
45
57
|
}
|
|
46
58
|
|
|
47
59
|
onResize() {
|
|
@@ -187,7 +199,7 @@ class StaticWebGLRenderer implements Renderer {
|
|
|
187
199
|
const { surface, tempCanvas } = renderResult;
|
|
188
200
|
|
|
189
201
|
try {
|
|
190
|
-
this.cachedImage = surface.makeImageSnapshot(rect);
|
|
202
|
+
this.cachedImage = surface.makeImageSnapshot(dp2Pixel(this.pd, rect));
|
|
191
203
|
} catch (error) {
|
|
192
204
|
console.error("Error creating image snapshot:", error);
|
|
193
205
|
} finally {
|