@shopify/react-native-skia 2.2.6 → 2.2.7
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/lib/commonjs/sksg/Container.d.ts +3 -31
- package/lib/commonjs/sksg/Container.js +5 -120
- package/lib/commonjs/sksg/Container.js.map +1 -1
- package/lib/commonjs/sksg/Container.native.d.ts +14 -0
- package/lib/commonjs/sksg/Container.native.js +81 -0
- package/lib/commonjs/sksg/Container.native.js.map +1 -0
- package/lib/commonjs/sksg/HostConfig.d.ts +1 -1
- package/lib/commonjs/sksg/HostConfig.js.map +1 -1
- package/lib/commonjs/sksg/Reconciler.js.map +1 -1
- package/lib/commonjs/sksg/StaticContainer.d.ts +24 -0
- package/lib/commonjs/sksg/StaticContainer.js +70 -0
- package/lib/commonjs/sksg/StaticContainer.js.map +1 -0
- package/lib/module/sksg/Container.d.ts +3 -31
- package/lib/module/sksg/Container.js +2 -116
- package/lib/module/sksg/Container.js.map +1 -1
- package/lib/module/sksg/Container.native.d.ts +14 -0
- package/lib/module/sksg/Container.native.js +73 -0
- package/lib/module/sksg/Container.native.js.map +1 -0
- package/lib/module/sksg/HostConfig.d.ts +1 -1
- package/lib/module/sksg/HostConfig.js.map +1 -1
- package/lib/module/sksg/Reconciler.js.map +1 -1
- package/lib/module/sksg/StaticContainer.d.ts +24 -0
- package/lib/module/sksg/StaticContainer.js +62 -0
- package/lib/module/sksg/StaticContainer.js.map +1 -0
- package/lib/typescript/lib/commonjs/sksg/Container.d.ts +3 -31
- package/lib/typescript/lib/commonjs/sksg/Container.native.d.ts +11 -0
- package/lib/typescript/lib/commonjs/sksg/Reconciler.d.ts +1 -29
- package/lib/typescript/lib/commonjs/sksg/StaticContainer.d.ts +23 -0
- package/lib/typescript/lib/module/sksg/Container.d.ts +3 -30
- package/lib/typescript/lib/module/sksg/Container.native.d.ts +11 -0
- package/lib/typescript/lib/module/sksg/Reconciler.d.ts +1 -29
- package/lib/typescript/lib/module/sksg/StaticContainer.d.ts +22 -0
- package/lib/typescript/src/sksg/Container.d.ts +3 -31
- package/lib/typescript/src/sksg/Container.native.d.ts +14 -0
- package/lib/typescript/src/sksg/HostConfig.d.ts +1 -1
- package/lib/typescript/src/sksg/StaticContainer.d.ts +24 -0
- package/package.json +1 -1
- package/src/sksg/Container.native.ts +86 -0
- package/src/sksg/Container.ts +3 -144
- package/src/sksg/HostConfig.ts +1 -1
- package/src/sksg/Reconciler.ts +1 -1
- package/src/sksg/StaticContainer.ts +83 -0
@@ -1,26 +1,5 @@
|
|
1
|
-
export
|
2
|
-
|
3
|
-
Skia: any;
|
4
|
-
set root(value: any);
|
5
|
-
get root(): any;
|
6
|
-
_root: any;
|
7
|
-
mount(): void;
|
8
|
-
unmounted: boolean | undefined;
|
9
|
-
unmount(): void;
|
10
|
-
drawOnCanvas(canvas: any): void;
|
11
|
-
}
|
12
|
-
export function createContainer(Skia: any, nativeId: any, onSize: any): StaticContainer | ReanimatedContainer | NativeReanimatedContainer;
|
13
|
-
declare class StaticContainer extends Container {
|
14
|
-
constructor(Skia: any, nativeId: any, onSize: any);
|
15
|
-
nativeId: any;
|
16
|
-
onSize: any;
|
17
|
-
redraw(): void;
|
18
|
-
recording: {
|
19
|
-
commands: any;
|
20
|
-
paintPool: never[];
|
21
|
-
animationValues: any;
|
22
|
-
} | undefined;
|
23
|
-
}
|
1
|
+
export function createContainer(Skia: any, nativeId: any, onSize: any): StaticContainer | ReanimatedContainer;
|
2
|
+
import { StaticContainer } from "./StaticContainer";
|
24
3
|
declare class ReanimatedContainer extends Container {
|
25
4
|
constructor(Skia: any, nativeId: any, onSize: any);
|
26
5
|
nativeId: any;
|
@@ -32,11 +11,5 @@ declare class ReanimatedContainer extends Container {
|
|
32
11
|
} | undefined;
|
33
12
|
mapperId: any;
|
34
13
|
}
|
35
|
-
|
36
|
-
constructor(Skia: any, nativeId: any, onSize: any);
|
37
|
-
nativeId: any;
|
38
|
-
onSize: any;
|
39
|
-
redraw(): void;
|
40
|
-
mapperId: any;
|
41
|
-
}
|
14
|
+
import { Container } from "./StaticContainer";
|
42
15
|
export {};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export function createContainer(Skia: any, nativeId: any, onSize: any): StaticContainer | NativeReanimatedContainer;
|
2
|
+
import { StaticContainer } from "./StaticContainer";
|
3
|
+
declare class NativeReanimatedContainer extends Container {
|
4
|
+
constructor(Skia: any, nativeId: any, onSize: any);
|
5
|
+
nativeId: any;
|
6
|
+
onSize: any;
|
7
|
+
redraw(): void;
|
8
|
+
mapperId: any;
|
9
|
+
}
|
10
|
+
import { Container } from "./StaticContainer";
|
11
|
+
export {};
|
@@ -1,42 +1,14 @@
|
|
1
1
|
export class SkiaSGRoot {
|
2
2
|
constructor(Skia: any, nativeId: number | undefined, onSize: any);
|
3
3
|
Skia: any;
|
4
|
-
container: {
|
4
|
+
container: import("./StaticContainer").StaticContainer | {
|
5
5
|
nativeId: any;
|
6
6
|
onSize: any;
|
7
7
|
redraw(): void;
|
8
8
|
recording: {
|
9
9
|
commands: any;
|
10
10
|
paintPool: never[];
|
11
|
-
animationValues: any;
|
12
11
|
} | undefined;
|
13
|
-
Skia: any;
|
14
|
-
root: any;
|
15
|
-
_root: any;
|
16
|
-
mount(): void;
|
17
|
-
unmounted: boolean | undefined;
|
18
|
-
unmount(): void;
|
19
|
-
drawOnCanvas(canvas: any): void;
|
20
|
-
} | {
|
21
|
-
nativeId: any;
|
22
|
-
onSize: any;
|
23
|
-
redraw(): void;
|
24
|
-
recording: {
|
25
|
-
commands: any;
|
26
|
-
paintPool: never[];
|
27
|
-
} | undefined;
|
28
|
-
mapperId: any;
|
29
|
-
Skia: any;
|
30
|
-
root: any;
|
31
|
-
_root: any;
|
32
|
-
mount(): void;
|
33
|
-
unmounted: boolean | undefined;
|
34
|
-
unmount(): void;
|
35
|
-
drawOnCanvas(canvas: any): void;
|
36
|
-
} | {
|
37
|
-
nativeId: any;
|
38
|
-
onSize: any;
|
39
|
-
redraw(): void;
|
40
12
|
mapperId: any;
|
41
13
|
Skia: any;
|
42
14
|
root: any;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
export class Container {
|
2
|
+
constructor(Skia: any);
|
3
|
+
Skia: any;
|
4
|
+
set root(value: any);
|
5
|
+
get root(): any;
|
6
|
+
_root: any;
|
7
|
+
mount(): void;
|
8
|
+
unmounted: boolean | undefined;
|
9
|
+
unmount(): void;
|
10
|
+
drawOnCanvas(canvas: any): void;
|
11
|
+
}
|
12
|
+
export class StaticContainer extends Container {
|
13
|
+
constructor(Skia: any, nativeId: any, onSize: any);
|
14
|
+
nativeId: any;
|
15
|
+
onSize: any;
|
16
|
+
redraw(): void;
|
17
|
+
recording: {
|
18
|
+
commands: any;
|
19
|
+
paintPool: never[];
|
20
|
+
animationValues: any;
|
21
|
+
} | undefined;
|
22
|
+
}
|
@@ -1,27 +1,6 @@
|
|
1
1
|
import type { SharedValue } from "react-native-reanimated";
|
2
|
-
import type { Skia,
|
3
|
-
import
|
4
|
-
import type { Recording } from "./Recorder/Recorder";
|
5
|
-
import "../views/api";
|
6
|
-
export declare abstract class Container {
|
7
|
-
protected Skia: Skia;
|
8
|
-
private _root;
|
9
|
-
protected recording: Recording | null;
|
10
|
-
protected unmounted: boolean;
|
11
|
-
constructor(Skia: Skia);
|
12
|
-
get root(): Node[];
|
13
|
-
set root(value: Node[]);
|
14
|
-
mount(): void;
|
15
|
-
unmount(): void;
|
16
|
-
drawOnCanvas(canvas: SkCanvas): void;
|
17
|
-
abstract redraw(): void;
|
18
|
-
}
|
19
|
-
declare class StaticContainer extends Container {
|
20
|
-
private nativeId;
|
21
|
-
private onSize?;
|
22
|
-
constructor(Skia: Skia, nativeId: number, onSize?: SharedValue<SkSize> | undefined);
|
23
|
-
redraw(): void;
|
24
|
-
}
|
2
|
+
import type { Skia, SkSize } from "../skia/types";
|
3
|
+
import { Container, StaticContainer } from "./StaticContainer";
|
25
4
|
declare class ReanimatedContainer extends Container {
|
26
5
|
private nativeId;
|
27
6
|
private onSize?;
|
@@ -29,12 +8,5 @@ declare class ReanimatedContainer extends Container {
|
|
29
8
|
constructor(Skia: Skia, nativeId: number, onSize?: SharedValue<SkSize> | undefined);
|
30
9
|
redraw(): void;
|
31
10
|
}
|
32
|
-
declare
|
33
|
-
private nativeId;
|
34
|
-
private onSize?;
|
35
|
-
private mapperId;
|
36
|
-
constructor(Skia: Skia, nativeId: number, onSize?: SharedValue<SkSize> | undefined);
|
37
|
-
redraw(): void;
|
38
|
-
}
|
39
|
-
export declare const createContainer: (Skia: Skia, nativeId: number, onSize?: SharedValue<SkSize>) => StaticContainer | ReanimatedContainer | NativeReanimatedContainer;
|
11
|
+
export declare const createContainer: (Skia: Skia, nativeId: number, onSize?: SharedValue<SkSize>) => StaticContainer | ReanimatedContainer;
|
40
12
|
export {};
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { SharedValue } from "react-native-reanimated";
|
2
|
+
import type { Skia, SkSize } from "../skia/types";
|
3
|
+
import { Container, StaticContainer } from "./StaticContainer";
|
4
|
+
import "../skia/NativeSetup";
|
5
|
+
import "../views/api";
|
6
|
+
declare class NativeReanimatedContainer extends Container {
|
7
|
+
private nativeId;
|
8
|
+
private onSize?;
|
9
|
+
private mapperId;
|
10
|
+
constructor(Skia: Skia, nativeId: number, onSize?: SharedValue<SkSize> | undefined);
|
11
|
+
redraw(): void;
|
12
|
+
}
|
13
|
+
export declare const createContainer: (Skia: Skia, nativeId: number, onSize?: SharedValue<SkSize>) => StaticContainer | NativeReanimatedContainer;
|
14
|
+
export {};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { HostConfig } from "react-reconciler";
|
2
2
|
import type { NodeType } from "../dom/types";
|
3
3
|
import type { Node } from "./Node";
|
4
|
-
import type { Container } from "./
|
4
|
+
import type { Container } from "./StaticContainer";
|
5
5
|
export declare const debug: (...args: Parameters<typeof console.log>) => void;
|
6
6
|
type Instance = Node;
|
7
7
|
type Props = object;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import type { SharedValue } from "react-native-reanimated";
|
2
|
+
import type { Skia, SkCanvas, SkSize } from "../skia/types";
|
3
|
+
import type { Node } from "./Node";
|
4
|
+
import type { Recording } from "./Recorder/Recorder";
|
5
|
+
import "../views/api";
|
6
|
+
export declare abstract class Container {
|
7
|
+
protected Skia: Skia;
|
8
|
+
private _root;
|
9
|
+
protected recording: Recording | null;
|
10
|
+
protected unmounted: boolean;
|
11
|
+
constructor(Skia: Skia);
|
12
|
+
get root(): Node[];
|
13
|
+
set root(value: Node[]);
|
14
|
+
mount(): void;
|
15
|
+
unmount(): void;
|
16
|
+
drawOnCanvas(canvas: SkCanvas): void;
|
17
|
+
abstract redraw(): void;
|
18
|
+
}
|
19
|
+
export declare class StaticContainer extends Container {
|
20
|
+
private nativeId;
|
21
|
+
private onSize?;
|
22
|
+
constructor(Skia: Skia, nativeId: number, onSize?: SharedValue<SkSize> | undefined);
|
23
|
+
redraw(): void;
|
24
|
+
}
|
package/package.json
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
"setup-skia-web": "scripts/setup-canvaskit.js"
|
9
9
|
},
|
10
10
|
"title": "React Native Skia",
|
11
|
-
"version": "2.2.
|
11
|
+
"version": "2.2.7",
|
12
12
|
"description": "High-performance React Native Graphics using Skia",
|
13
13
|
"main": "lib/module/index.js",
|
14
14
|
"react-native": "src/index.ts",
|
@@ -0,0 +1,86 @@
|
|
1
|
+
import type { SharedValue } from "react-native-reanimated";
|
2
|
+
|
3
|
+
import Rea from "../external/reanimated/ReanimatedProxy";
|
4
|
+
import type { Skia, SkSize } from "../skia/types";
|
5
|
+
import { HAS_REANIMATED_3 } from "../external/reanimated/renderHelpers";
|
6
|
+
import type { JsiRecorder } from "../skia/types/Recorder";
|
7
|
+
|
8
|
+
import { ReanimatedRecorder } from "./Recorder/ReanimatedRecorder";
|
9
|
+
import { Container, StaticContainer } from "./StaticContainer";
|
10
|
+
import { visit } from "./Recorder/Visitor";
|
11
|
+
|
12
|
+
import "../skia/NativeSetup";
|
13
|
+
import "../views/api";
|
14
|
+
|
15
|
+
const nativeDrawOnscreen = (
|
16
|
+
nativeId: number,
|
17
|
+
recorder: JsiRecorder,
|
18
|
+
onSize?: SharedValue<SkSize>
|
19
|
+
) => {
|
20
|
+
"worklet";
|
21
|
+
|
22
|
+
//const start = performance.now();
|
23
|
+
if (onSize) {
|
24
|
+
const size = SkiaViewApi.size(nativeId);
|
25
|
+
if (
|
26
|
+
size.width !== onSize.value.width ||
|
27
|
+
size.height !== onSize.value.height
|
28
|
+
) {
|
29
|
+
onSize.value = size;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
const picture = recorder.play();
|
33
|
+
//const end = performance.now();
|
34
|
+
//console.log("Recording time: ", end - start);
|
35
|
+
SkiaViewApi.setJsiProperty(nativeId, "picture", picture);
|
36
|
+
};
|
37
|
+
|
38
|
+
class NativeReanimatedContainer extends Container {
|
39
|
+
private mapperId: number | null = null;
|
40
|
+
|
41
|
+
constructor(
|
42
|
+
Skia: Skia,
|
43
|
+
private nativeId: number,
|
44
|
+
private onSize?: SharedValue<SkSize>
|
45
|
+
) {
|
46
|
+
super(Skia);
|
47
|
+
}
|
48
|
+
|
49
|
+
redraw() {
|
50
|
+
if (this.mapperId !== null) {
|
51
|
+
Rea.stopMapper(this.mapperId);
|
52
|
+
}
|
53
|
+
if (this.unmounted) {
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
const { nativeId, Skia } = this;
|
57
|
+
const recorder = new ReanimatedRecorder(Skia);
|
58
|
+
visit(recorder, this.root);
|
59
|
+
const sharedValues = recorder.getSharedValues();
|
60
|
+
const sharedRecorder = recorder.getRecorder();
|
61
|
+
Rea.runOnUI((onSize?: SharedValue<SkSize>) => {
|
62
|
+
"worklet";
|
63
|
+
nativeDrawOnscreen(nativeId, sharedRecorder, onSize);
|
64
|
+
})(this.onSize);
|
65
|
+
if (sharedValues.length > 0) {
|
66
|
+
const { onSize } = this;
|
67
|
+
this.mapperId = Rea.startMapper(() => {
|
68
|
+
"worklet";
|
69
|
+
sharedRecorder.applyUpdates(sharedValues);
|
70
|
+
nativeDrawOnscreen(nativeId, sharedRecorder, onSize);
|
71
|
+
}, sharedValues);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
export const createContainer = (
|
77
|
+
Skia: Skia,
|
78
|
+
nativeId: number,
|
79
|
+
onSize?: SharedValue<SkSize>
|
80
|
+
) => {
|
81
|
+
if (HAS_REANIMATED_3 && nativeId !== -1) {
|
82
|
+
return new NativeReanimatedContainer(Skia, nativeId, onSize);
|
83
|
+
} else {
|
84
|
+
return new StaticContainer(Skia, nativeId);
|
85
|
+
}
|
86
|
+
};
|
package/src/sksg/Container.ts
CHANGED
@@ -1,19 +1,15 @@
|
|
1
1
|
import type { SharedValue } from "react-native-reanimated";
|
2
2
|
|
3
3
|
import Rea from "../external/reanimated/ReanimatedProxy";
|
4
|
-
import type { Skia,
|
4
|
+
import type { Skia, SkSize } from "../skia/types";
|
5
5
|
import { HAS_REANIMATED_3 } from "../external/reanimated/renderHelpers";
|
6
|
-
import type { JsiRecorder } from "../skia/types/Recorder";
|
7
6
|
|
8
|
-
import type { Node } from "./Node";
|
9
7
|
import type { Recording } from "./Recorder/Recorder";
|
10
8
|
import { Recorder } from "./Recorder/Recorder";
|
11
9
|
import { visit } from "./Recorder/Visitor";
|
12
10
|
import { replay } from "./Recorder/Player";
|
13
11
|
import { createDrawingContext } from "./Recorder/DrawingContext";
|
14
|
-
import {
|
15
|
-
|
16
|
-
import "../views/api";
|
12
|
+
import { Container, StaticContainer } from "./StaticContainer";
|
17
13
|
|
18
14
|
const drawOnscreen = (
|
19
15
|
Skia: Skia,
|
@@ -43,100 +39,6 @@ const drawOnscreen = (
|
|
43
39
|
SkiaViewApi.setJsiProperty(nativeId, "picture", picture);
|
44
40
|
};
|
45
41
|
|
46
|
-
const nativeDrawOnscreen = (
|
47
|
-
nativeId: number,
|
48
|
-
recorder: JsiRecorder,
|
49
|
-
onSize?: SharedValue<SkSize>
|
50
|
-
) => {
|
51
|
-
"worklet";
|
52
|
-
|
53
|
-
//const start = performance.now();
|
54
|
-
if (onSize) {
|
55
|
-
const size = SkiaViewApi.size(nativeId);
|
56
|
-
if (
|
57
|
-
size.width !== onSize.value.width ||
|
58
|
-
size.height !== onSize.value.height
|
59
|
-
) {
|
60
|
-
onSize.value = size;
|
61
|
-
}
|
62
|
-
}
|
63
|
-
const picture = recorder.play();
|
64
|
-
//const end = performance.now();
|
65
|
-
//console.log("Recording time: ", end - start);
|
66
|
-
SkiaViewApi.setJsiProperty(nativeId, "picture", picture);
|
67
|
-
};
|
68
|
-
|
69
|
-
export abstract class Container {
|
70
|
-
private _root: Node[] = [];
|
71
|
-
protected recording: Recording | null = null;
|
72
|
-
protected unmounted = false;
|
73
|
-
|
74
|
-
constructor(protected Skia: Skia) {}
|
75
|
-
|
76
|
-
get root() {
|
77
|
-
return this._root;
|
78
|
-
}
|
79
|
-
|
80
|
-
set root(value: Node[]) {
|
81
|
-
this._root = value;
|
82
|
-
}
|
83
|
-
|
84
|
-
mount() {
|
85
|
-
this.unmounted = false;
|
86
|
-
}
|
87
|
-
|
88
|
-
unmount() {
|
89
|
-
this.unmounted = true;
|
90
|
-
}
|
91
|
-
|
92
|
-
drawOnCanvas(canvas: SkCanvas) {
|
93
|
-
if (!this.recording) {
|
94
|
-
throw new Error("No recording to draw");
|
95
|
-
}
|
96
|
-
const ctx = createDrawingContext(
|
97
|
-
this.Skia,
|
98
|
-
this.recording.paintPool,
|
99
|
-
canvas
|
100
|
-
);
|
101
|
-
replay(ctx, this.recording.commands);
|
102
|
-
}
|
103
|
-
|
104
|
-
abstract redraw(): void;
|
105
|
-
}
|
106
|
-
|
107
|
-
class StaticContainer extends Container {
|
108
|
-
constructor(
|
109
|
-
Skia: Skia,
|
110
|
-
private nativeId: number,
|
111
|
-
private onSize?: SharedValue<SkSize>
|
112
|
-
) {
|
113
|
-
super(Skia);
|
114
|
-
}
|
115
|
-
|
116
|
-
redraw() {
|
117
|
-
const recorder = new Recorder();
|
118
|
-
visit(recorder, this.root);
|
119
|
-
this.recording = recorder.getRecording();
|
120
|
-
const isOnScreen = this.nativeId !== -1;
|
121
|
-
if (isOnScreen) {
|
122
|
-
if (this.onSize) {
|
123
|
-
const size = SkiaViewApi.size(this.nativeId);
|
124
|
-
if (
|
125
|
-
size.width !== this.onSize.value.width ||
|
126
|
-
size.height !== this.onSize.value.height
|
127
|
-
) {
|
128
|
-
this.onSize.value = size;
|
129
|
-
}
|
130
|
-
}
|
131
|
-
const rec = this.Skia.PictureRecorder();
|
132
|
-
const canvas = rec.beginRecording();
|
133
|
-
this.drawOnCanvas(canvas);
|
134
|
-
const picture = rec.finishRecordingAsPicture();
|
135
|
-
SkiaViewApi.setJsiProperty(this.nativeId, "picture", picture);
|
136
|
-
}
|
137
|
-
}
|
138
|
-
}
|
139
|
-
|
140
42
|
class ReanimatedContainer extends Container {
|
141
43
|
private mapperId: number | null = null;
|
142
44
|
|
@@ -177,56 +79,13 @@ class ReanimatedContainer extends Container {
|
|
177
79
|
}
|
178
80
|
}
|
179
81
|
|
180
|
-
class NativeReanimatedContainer extends Container {
|
181
|
-
private mapperId: number | null = null;
|
182
|
-
|
183
|
-
constructor(
|
184
|
-
Skia: Skia,
|
185
|
-
private nativeId: number,
|
186
|
-
private onSize?: SharedValue<SkSize>
|
187
|
-
) {
|
188
|
-
super(Skia);
|
189
|
-
}
|
190
|
-
|
191
|
-
redraw() {
|
192
|
-
if (this.mapperId !== null) {
|
193
|
-
Rea.stopMapper(this.mapperId);
|
194
|
-
}
|
195
|
-
if (this.unmounted) {
|
196
|
-
return;
|
197
|
-
}
|
198
|
-
const { nativeId, Skia } = this;
|
199
|
-
const recorder = new ReanimatedRecorder(Skia);
|
200
|
-
visit(recorder, this.root);
|
201
|
-
const sharedValues = recorder.getSharedValues();
|
202
|
-
const sharedRecorder = recorder.getRecorder();
|
203
|
-
Rea.runOnUI((onSize?: SharedValue<SkSize>) => {
|
204
|
-
"worklet";
|
205
|
-
nativeDrawOnscreen(nativeId, sharedRecorder, onSize);
|
206
|
-
})(this.onSize);
|
207
|
-
if (sharedValues.length > 0) {
|
208
|
-
const { onSize } = this;
|
209
|
-
this.mapperId = Rea.startMapper(() => {
|
210
|
-
"worklet";
|
211
|
-
sharedRecorder.applyUpdates(sharedValues);
|
212
|
-
nativeDrawOnscreen(nativeId, sharedRecorder, onSize);
|
213
|
-
}, sharedValues);
|
214
|
-
}
|
215
|
-
}
|
216
|
-
}
|
217
|
-
|
218
82
|
export const createContainer = (
|
219
83
|
Skia: Skia,
|
220
84
|
nativeId: number,
|
221
85
|
onSize?: SharedValue<SkSize>
|
222
86
|
) => {
|
223
|
-
const web = global.SkiaViewApi && global.SkiaViewApi.web;
|
224
87
|
if (HAS_REANIMATED_3 && nativeId !== -1) {
|
225
|
-
|
226
|
-
return new NativeReanimatedContainer(Skia, nativeId, onSize);
|
227
|
-
} else {
|
228
|
-
return new ReanimatedContainer(Skia, nativeId, onSize);
|
229
|
-
}
|
88
|
+
return new ReanimatedContainer(Skia, nativeId, onSize);
|
230
89
|
} else {
|
231
90
|
return new StaticContainer(Skia, nativeId);
|
232
91
|
}
|
package/src/sksg/HostConfig.ts
CHANGED
@@ -7,7 +7,7 @@ import type { NodeType } from "../dom/types";
|
|
7
7
|
import { shallowEq } from "../renderer/typeddash";
|
8
8
|
|
9
9
|
import type { Node } from "./Node";
|
10
|
-
import type { Container } from "./
|
10
|
+
import type { Container } from "./StaticContainer";
|
11
11
|
|
12
12
|
type EventPriority = number;
|
13
13
|
const NoEventPriority = 0;
|
package/src/sksg/Reconciler.ts
CHANGED
@@ -7,7 +7,7 @@ import type { SkCanvas, Skia, SkSize } from "../skia/types";
|
|
7
7
|
import { NodeType } from "../dom/types";
|
8
8
|
|
9
9
|
import { debug, sksgHostConfig } from "./HostConfig";
|
10
|
-
import type { Container } from "./
|
10
|
+
import type { Container } from "./StaticContainer";
|
11
11
|
import { createContainer } from "./Container";
|
12
12
|
|
13
13
|
import "./Elements";
|
@@ -0,0 +1,83 @@
|
|
1
|
+
import type { SharedValue } from "react-native-reanimated";
|
2
|
+
|
3
|
+
import type { Skia, SkCanvas, SkSize } from "../skia/types";
|
4
|
+
|
5
|
+
import type { Node } from "./Node";
|
6
|
+
import type { Recording } from "./Recorder/Recorder";
|
7
|
+
import { Recorder } from "./Recorder/Recorder";
|
8
|
+
import { visit } from "./Recorder/Visitor";
|
9
|
+
import { replay } from "./Recorder/Player";
|
10
|
+
import { createDrawingContext } from "./Recorder/DrawingContext";
|
11
|
+
|
12
|
+
import "../views/api";
|
13
|
+
|
14
|
+
export abstract class Container {
|
15
|
+
private _root: Node[] = [];
|
16
|
+
protected recording: Recording | null = null;
|
17
|
+
protected unmounted = false;
|
18
|
+
|
19
|
+
constructor(protected Skia: Skia) {}
|
20
|
+
|
21
|
+
get root() {
|
22
|
+
return this._root;
|
23
|
+
}
|
24
|
+
|
25
|
+
set root(value: Node[]) {
|
26
|
+
this._root = value;
|
27
|
+
}
|
28
|
+
|
29
|
+
mount() {
|
30
|
+
this.unmounted = false;
|
31
|
+
}
|
32
|
+
|
33
|
+
unmount() {
|
34
|
+
this.unmounted = true;
|
35
|
+
}
|
36
|
+
|
37
|
+
drawOnCanvas(canvas: SkCanvas) {
|
38
|
+
if (!this.recording) {
|
39
|
+
throw new Error("No recording to draw");
|
40
|
+
}
|
41
|
+
const ctx = createDrawingContext(
|
42
|
+
this.Skia,
|
43
|
+
this.recording.paintPool,
|
44
|
+
canvas
|
45
|
+
);
|
46
|
+
replay(ctx, this.recording.commands);
|
47
|
+
}
|
48
|
+
|
49
|
+
abstract redraw(): void;
|
50
|
+
}
|
51
|
+
|
52
|
+
export class StaticContainer extends Container {
|
53
|
+
constructor(
|
54
|
+
Skia: Skia,
|
55
|
+
private nativeId: number,
|
56
|
+
private onSize?: SharedValue<SkSize>
|
57
|
+
) {
|
58
|
+
super(Skia);
|
59
|
+
}
|
60
|
+
|
61
|
+
redraw() {
|
62
|
+
const recorder = new Recorder();
|
63
|
+
visit(recorder, this.root);
|
64
|
+
this.recording = recorder.getRecording();
|
65
|
+
const isOnScreen = this.nativeId !== -1;
|
66
|
+
if (isOnScreen) {
|
67
|
+
if (this.onSize) {
|
68
|
+
const size = SkiaViewApi.size(this.nativeId);
|
69
|
+
if (
|
70
|
+
size.width !== this.onSize.value.width ||
|
71
|
+
size.height !== this.onSize.value.height
|
72
|
+
) {
|
73
|
+
this.onSize.value = size;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
const rec = this.Skia.PictureRecorder();
|
77
|
+
const canvas = rec.beginRecording();
|
78
|
+
this.drawOnCanvas(canvas);
|
79
|
+
const picture = rec.finishRecordingAsPicture();
|
80
|
+
SkiaViewApi.setJsiProperty(this.nativeId, "picture", picture);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|