@shopify/react-native-skia 2.2.0 → 2.2.1
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/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerInterface.java +1 -0
- package/cpp/rnskia/RNSkJsiViewApi.h +36 -1
- package/cpp/rnskia/RNSkView.h +10 -0
- package/lib/commonjs/renderer/Canvas.d.ts +11 -4
- package/lib/commonjs/renderer/Canvas.js +48 -26
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/sksg/Container.d.ts +13 -7
- package/lib/commonjs/sksg/Container.js +44 -18
- package/lib/commonjs/sksg/Container.js.map +1 -1
- package/lib/commonjs/sksg/Reconciler.d.ts +3 -2
- package/lib/commonjs/sksg/Reconciler.js +2 -2
- package/lib/commonjs/sksg/Reconciler.js.map +1 -1
- package/lib/commonjs/views/types.d.ts +1 -0
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +11 -4
- package/lib/module/renderer/Canvas.js +47 -26
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/sksg/Container.d.ts +13 -7
- package/lib/module/sksg/Container.js +44 -18
- package/lib/module/sksg/Container.js.map +1 -1
- package/lib/module/sksg/Reconciler.d.ts +3 -2
- package/lib/module/sksg/Reconciler.js +2 -2
- package/lib/module/sksg/Reconciler.js.map +1 -1
- package/lib/module/views/types.d.ts +1 -0
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/lib/commonjs/renderer/Canvas.d.ts +7 -2
- package/lib/typescript/lib/commonjs/sksg/Container.d.ts +11 -3
- package/lib/typescript/lib/commonjs/sksg/Reconciler.d.ts +7 -4
- package/lib/typescript/lib/module/renderer/Canvas.d.ts +10 -2
- package/lib/typescript/lib/module/sksg/Container.d.ts +11 -3
- package/lib/typescript/lib/module/sksg/Reconciler.d.ts +7 -4
- package/lib/typescript/src/renderer/Canvas.d.ts +11 -4
- package/lib/typescript/src/sksg/Container.d.ts +13 -7
- package/lib/typescript/src/sksg/Reconciler.d.ts +3 -2
- package/lib/typescript/src/views/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/renderer/Canvas.tsx +50 -30
- package/src/sksg/Container.ts +73 -20
- package/src/sksg/Reconciler.ts +5 -3
- package/src/views/types.ts +1 -0
@@ -1,12 +1,20 @@
|
|
1
1
|
export function useCanvasRef(): React.RefObject<null>;
|
2
|
-
export function
|
2
|
+
export function useCanvasSize(): {
|
3
|
+
ref: React.RefObject<null>;
|
4
|
+
size: {
|
5
|
+
width: number;
|
6
|
+
height: number;
|
7
|
+
};
|
8
|
+
};
|
9
|
+
export const isFabric: boolean;
|
10
|
+
export function Canvas({ debug, opaque, children, onSize, colorSpace, ref, onLayout, ...viewProps }: {
|
3
11
|
[x: string]: any;
|
4
12
|
debug: any;
|
5
13
|
opaque: any;
|
6
14
|
children: any;
|
7
15
|
onSize: any;
|
8
|
-
onLayout: any;
|
9
16
|
colorSpace?: string | undefined;
|
10
17
|
ref: any;
|
18
|
+
onLayout: any;
|
11
19
|
}): React.CElement<object, React.Component<object, {}, any> & import("react-native").NativeMethods>;
|
12
20
|
import React from "react";
|
@@ -1,7 +1,6 @@
|
|
1
1
|
export class Container {
|
2
|
-
constructor(Skia: any
|
2
|
+
constructor(Skia: any);
|
3
3
|
Skia: any;
|
4
|
-
nativeId: any;
|
5
4
|
set root(value: any);
|
6
5
|
get root(): any;
|
7
6
|
_root: any;
|
@@ -10,8 +9,11 @@ export class Container {
|
|
10
9
|
unmount(): void;
|
11
10
|
drawOnCanvas(canvas: any): void;
|
12
11
|
}
|
13
|
-
export function createContainer(Skia: any, nativeId: any): StaticContainer | ReanimatedContainer | NativeReanimatedContainer;
|
12
|
+
export function createContainer(Skia: any, nativeId: any, onSize: any): StaticContainer | ReanimatedContainer | NativeReanimatedContainer;
|
14
13
|
declare class StaticContainer extends Container {
|
14
|
+
constructor(Skia: any, nativeId: any, onSize: any);
|
15
|
+
nativeId: any;
|
16
|
+
onSize: any;
|
15
17
|
redraw(): void;
|
16
18
|
recording: {
|
17
19
|
commands: any;
|
@@ -20,6 +22,9 @@ declare class StaticContainer extends Container {
|
|
20
22
|
} | undefined;
|
21
23
|
}
|
22
24
|
declare class ReanimatedContainer extends Container {
|
25
|
+
constructor(Skia: any, nativeId: any, onSize: any);
|
26
|
+
nativeId: any;
|
27
|
+
onSize: any;
|
23
28
|
redraw(): void;
|
24
29
|
recording: {
|
25
30
|
commands: any;
|
@@ -28,6 +33,9 @@ declare class ReanimatedContainer extends Container {
|
|
28
33
|
mapperId: any;
|
29
34
|
}
|
30
35
|
declare class NativeReanimatedContainer extends Container {
|
36
|
+
constructor(Skia: any, nativeId: any, onSize: any);
|
37
|
+
nativeId: any;
|
38
|
+
onSize: any;
|
31
39
|
redraw(): void;
|
32
40
|
mapperId: any;
|
33
41
|
}
|
@@ -1,7 +1,9 @@
|
|
1
1
|
export class SkiaSGRoot {
|
2
|
-
constructor(Skia: any, nativeId
|
2
|
+
constructor(Skia: any, nativeId: number | undefined, onSize: any);
|
3
3
|
Skia: any;
|
4
4
|
container: {
|
5
|
+
nativeId: any;
|
6
|
+
onSize: any;
|
5
7
|
redraw(): void;
|
6
8
|
recording: {
|
7
9
|
commands: any;
|
@@ -9,7 +11,6 @@ export class SkiaSGRoot {
|
|
9
11
|
animationValues: any;
|
10
12
|
} | undefined;
|
11
13
|
Skia: any;
|
12
|
-
nativeId: any;
|
13
14
|
root: any;
|
14
15
|
_root: any;
|
15
16
|
mount(): void;
|
@@ -17,6 +18,8 @@ export class SkiaSGRoot {
|
|
17
18
|
unmount(): void;
|
18
19
|
drawOnCanvas(canvas: any): void;
|
19
20
|
} | {
|
21
|
+
nativeId: any;
|
22
|
+
onSize: any;
|
20
23
|
redraw(): void;
|
21
24
|
recording: {
|
22
25
|
commands: any;
|
@@ -24,7 +27,6 @@ export class SkiaSGRoot {
|
|
24
27
|
} | undefined;
|
25
28
|
mapperId: any;
|
26
29
|
Skia: any;
|
27
|
-
nativeId: any;
|
28
30
|
root: any;
|
29
31
|
_root: any;
|
30
32
|
mount(): void;
|
@@ -32,10 +34,11 @@ export class SkiaSGRoot {
|
|
32
34
|
unmount(): void;
|
33
35
|
drawOnCanvas(canvas: any): void;
|
34
36
|
} | {
|
37
|
+
nativeId: any;
|
38
|
+
onSize: any;
|
35
39
|
redraw(): void;
|
36
40
|
mapperId: any;
|
37
41
|
Skia: any;
|
38
|
-
nativeId: any;
|
39
42
|
root: any;
|
40
43
|
_root: any;
|
41
44
|
mount(): void;
|
@@ -1,20 +1,27 @@
|
|
1
1
|
import type { FC } from "react";
|
2
2
|
import React from "react";
|
3
|
-
import type { ViewProps } from "react-native";
|
4
|
-
import type
|
3
|
+
import type { MeasureInWindowOnSuccessCallback, MeasureOnSuccessCallback, ViewProps } from "react-native";
|
4
|
+
import { type SharedValue } from "react-native-reanimated";
|
5
5
|
import type { SkImage, SkRect, SkSize } from "../skia/types";
|
6
6
|
export interface CanvasRef extends FC<CanvasProps> {
|
7
7
|
makeImageSnapshot(rect?: SkRect): SkImage;
|
8
8
|
makeImageSnapshotAsync(rect?: SkRect): Promise<SkImage>;
|
9
9
|
redraw(): void;
|
10
10
|
getNativeId(): number;
|
11
|
+
measure(callback: MeasureOnSuccessCallback): void;
|
12
|
+
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;
|
11
13
|
}
|
12
14
|
export declare const useCanvasRef: () => React.RefObject<CanvasRef | null>;
|
13
|
-
export
|
15
|
+
export declare const useCanvasSize: () => {
|
16
|
+
ref: React.RefObject<CanvasRef | null>;
|
17
|
+
size: SkSize;
|
18
|
+
};
|
19
|
+
export declare const isFabric: boolean;
|
20
|
+
export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
|
14
21
|
debug?: boolean;
|
15
22
|
opaque?: boolean;
|
16
23
|
onSize?: SharedValue<SkSize>;
|
17
24
|
colorSpace?: "p3" | "srgb";
|
18
25
|
ref?: React.Ref<CanvasRef>;
|
19
26
|
}
|
20
|
-
export declare const Canvas: ({ debug, opaque, children, onSize,
|
27
|
+
export declare const Canvas: ({ debug, opaque, children, onSize, colorSpace, ref, onLayout, ...viewProps }: CanvasProps) => React.JSX.Element;
|
@@ -1,14 +1,14 @@
|
|
1
|
-
import type {
|
1
|
+
import type { SharedValue } from "react-native-reanimated";
|
2
|
+
import type { Skia, SkCanvas, SkSize } from "../skia/types";
|
2
3
|
import type { Node } from "./Node";
|
3
4
|
import type { Recording } from "./Recorder/Recorder";
|
4
5
|
import "../views/api";
|
5
6
|
export declare abstract class Container {
|
6
7
|
protected Skia: Skia;
|
7
|
-
protected nativeId: number;
|
8
8
|
private _root;
|
9
9
|
protected recording: Recording | null;
|
10
10
|
protected unmounted: boolean;
|
11
|
-
constructor(Skia: Skia
|
11
|
+
constructor(Skia: Skia);
|
12
12
|
get root(): Node[];
|
13
13
|
set root(value: Node[]);
|
14
14
|
mount(): void;
|
@@ -17,18 +17,24 @@ export declare abstract class Container {
|
|
17
17
|
abstract redraw(): void;
|
18
18
|
}
|
19
19
|
declare class StaticContainer extends Container {
|
20
|
-
|
20
|
+
private nativeId;
|
21
|
+
private onSize?;
|
22
|
+
constructor(Skia: Skia, nativeId: number, onSize?: SharedValue<SkSize> | undefined);
|
21
23
|
redraw(): void;
|
22
24
|
}
|
23
25
|
declare class ReanimatedContainer extends Container {
|
26
|
+
private nativeId;
|
27
|
+
private onSize?;
|
24
28
|
private mapperId;
|
25
|
-
constructor(Skia: Skia, nativeId: number);
|
29
|
+
constructor(Skia: Skia, nativeId: number, onSize?: SharedValue<SkSize> | undefined);
|
26
30
|
redraw(): void;
|
27
31
|
}
|
28
32
|
declare class NativeReanimatedContainer extends Container {
|
33
|
+
private nativeId;
|
34
|
+
private onSize?;
|
29
35
|
private mapperId;
|
30
|
-
constructor(Skia: Skia, nativeId: number);
|
36
|
+
constructor(Skia: Skia, nativeId: number, onSize?: SharedValue<SkSize> | undefined);
|
31
37
|
redraw(): void;
|
32
38
|
}
|
33
|
-
export declare const createContainer: (Skia: Skia, nativeId: number) => StaticContainer | ReanimatedContainer | NativeReanimatedContainer;
|
39
|
+
export declare const createContainer: (Skia: Skia, nativeId: number, onSize?: SharedValue<SkSize>) => StaticContainer | ReanimatedContainer | NativeReanimatedContainer;
|
34
40
|
export {};
|
@@ -1,12 +1,13 @@
|
|
1
1
|
import type { ReactNode } from "react";
|
2
|
-
import type {
|
2
|
+
import type { SharedValue } from "react-native-reanimated";
|
3
|
+
import type { SkCanvas, Skia, SkSize } from "../skia/types";
|
3
4
|
import { NodeType } from "../dom/types";
|
4
5
|
import "./Elements";
|
5
6
|
export declare class SkiaSGRoot {
|
6
7
|
Skia: Skia;
|
7
8
|
private root;
|
8
9
|
private container;
|
9
|
-
constructor(Skia: Skia, nativeId?: number);
|
10
|
+
constructor(Skia: Skia, nativeId?: number, onSize?: SharedValue<SkSize>);
|
10
11
|
get sg(): {
|
11
12
|
type: NodeType;
|
12
13
|
props: {};
|
@@ -12,6 +12,7 @@ export interface ISkiaViewApi {
|
|
12
12
|
requestRedraw: (nativeId: number) => void;
|
13
13
|
makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;
|
14
14
|
makeImageSnapshotAsync: (nativeId: number, rect?: SkRect) => Promise<SkImage>;
|
15
|
+
size: (nativeId: number) => SkSize;
|
15
16
|
}
|
16
17
|
export interface SkiaBaseViewProps extends ViewProps {
|
17
18
|
/**
|
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.1",
|
12
12
|
"description": "High-performance React Native Graphics using Skia",
|
13
13
|
"main": "lib/module/index.js",
|
14
14
|
"react-native": "src/index.ts",
|
package/src/renderer/Canvas.tsx
CHANGED
@@ -1,54 +1,55 @@
|
|
1
1
|
import type { FC } from "react";
|
2
2
|
import React, {
|
3
|
-
useCallback,
|
4
3
|
useEffect,
|
5
4
|
useImperativeHandle,
|
6
5
|
useLayoutEffect,
|
7
6
|
useMemo,
|
8
7
|
useRef,
|
8
|
+
useState,
|
9
9
|
} from "react";
|
10
|
-
import type {
|
11
|
-
|
10
|
+
import type {
|
11
|
+
MeasureInWindowOnSuccessCallback,
|
12
|
+
MeasureOnSuccessCallback,
|
13
|
+
View,
|
14
|
+
ViewProps,
|
15
|
+
} from "react-native";
|
16
|
+
import { type SharedValue } from "react-native-reanimated";
|
12
17
|
|
13
18
|
import { SkiaViewNativeId } from "../views/SkiaViewNativeId";
|
14
19
|
import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeComponent";
|
15
20
|
import type { SkImage, SkRect, SkSize } from "../skia/types";
|
16
21
|
import { SkiaSGRoot } from "../sksg/Reconciler";
|
17
22
|
import { Skia } from "../skia";
|
18
|
-
import type { SkiaBaseViewProps } from "../views";
|
19
23
|
|
20
24
|
export interface CanvasRef extends FC<CanvasProps> {
|
21
25
|
makeImageSnapshot(rect?: SkRect): SkImage;
|
22
26
|
makeImageSnapshotAsync(rect?: SkRect): Promise<SkImage>;
|
23
27
|
redraw(): void;
|
24
28
|
getNativeId(): number;
|
29
|
+
measure(callback: MeasureOnSuccessCallback): void;
|
30
|
+
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;
|
25
31
|
}
|
26
32
|
|
27
33
|
export const useCanvasRef = () => useRef<CanvasRef>(null);
|
28
34
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
const { width, height } = event.nativeEvent.layout;
|
42
|
-
|
43
|
-
if (resultValue) {
|
44
|
-
resultValue.value = { width, height };
|
45
|
-
}
|
46
|
-
},
|
47
|
-
[onLayout, resultValue]
|
48
|
-
);
|
35
|
+
export const useCanvasSize = () => {
|
36
|
+
const ref = useCanvasRef();
|
37
|
+
const [size, setSize] = useState<SkSize>({ width: 0, height: 0 });
|
38
|
+
useLayoutEffect(() => {
|
39
|
+
if (ref.current) {
|
40
|
+
ref.current.measure((_x, _y, width, height) => {
|
41
|
+
setSize({ width, height });
|
42
|
+
});
|
43
|
+
}
|
44
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
45
|
+
}, []);
|
46
|
+
return { ref, size };
|
49
47
|
};
|
50
48
|
|
51
|
-
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
50
|
+
export const isFabric = Boolean((global as any)?.nativeFabricUIManager);
|
51
|
+
|
52
|
+
export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
|
52
53
|
debug?: boolean;
|
53
54
|
opaque?: boolean;
|
54
55
|
onSize?: SharedValue<SkSize>;
|
@@ -61,24 +62,36 @@ export const Canvas = ({
|
|
61
62
|
opaque,
|
62
63
|
children,
|
63
64
|
onSize,
|
64
|
-
onLayout: _onLayout,
|
65
65
|
colorSpace = "p3",
|
66
66
|
ref,
|
67
|
+
// Here know this is a type error but this is done on purpose to check it at runtime
|
68
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
69
|
+
// @ts-expect-error
|
70
|
+
onLayout,
|
67
71
|
...viewProps
|
68
72
|
}: CanvasProps) => {
|
69
|
-
|
73
|
+
if (onLayout && isFabric) {
|
74
|
+
console.error(
|
75
|
+
// eslint-disable-next-line max-len
|
76
|
+
"<Canvas onLayout={onLayout} /> is not supported on the new architecture, to fix the issue, see: https://shopify.github.io/react-native-skia/docs/canvas/overview/#getting-the-canvas-size"
|
77
|
+
);
|
78
|
+
}
|
79
|
+
const viewRef = useRef<View>(null);
|
70
80
|
// Native ID
|
71
81
|
const nativeId = useMemo(() => {
|
72
82
|
return SkiaViewNativeId.current++;
|
73
83
|
}, []);
|
74
84
|
|
75
85
|
// Root
|
76
|
-
const root = useMemo(
|
86
|
+
const root = useMemo(
|
87
|
+
() => new SkiaSGRoot(Skia, nativeId, onSize),
|
88
|
+
[nativeId, onSize]
|
89
|
+
);
|
77
90
|
|
78
91
|
// Render effects
|
79
92
|
useLayoutEffect(() => {
|
80
93
|
root.render(children);
|
81
|
-
}, [children, root]);
|
94
|
+
}, [children, root, nativeId]);
|
82
95
|
|
83
96
|
useEffect(() => {
|
84
97
|
return () => {
|
@@ -103,16 +116,23 @@ export const Canvas = ({
|
|
103
116
|
getNativeId: () => {
|
104
117
|
return nativeId;
|
105
118
|
},
|
119
|
+
measure: (callback) => {
|
120
|
+
viewRef.current?.measure(callback);
|
121
|
+
},
|
122
|
+
measureInWindow: (callback) => {
|
123
|
+
viewRef.current?.measureInWindow(callback);
|
124
|
+
},
|
106
125
|
} as CanvasRef)
|
107
126
|
);
|
127
|
+
|
108
128
|
return (
|
109
129
|
<SkiaPictureViewNativeComponent
|
130
|
+
ref={viewRef}
|
110
131
|
collapsable={false}
|
111
132
|
nativeID={`${nativeId}`}
|
112
133
|
debug={debug}
|
113
134
|
opaque={opaque}
|
114
135
|
colorSpace={colorSpace}
|
115
|
-
onLayout={onLayout}
|
116
136
|
{...viewProps}
|
117
137
|
/>
|
118
138
|
);
|
package/src/sksg/Container.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
import type { SharedValue } from "react-native-reanimated";
|
2
|
+
|
1
3
|
import Rea from "../external/reanimated/ReanimatedProxy";
|
2
|
-
import type { Skia, SkCanvas } from "../skia/types";
|
4
|
+
import type { Skia, SkCanvas, SkSize } from "../skia/types";
|
3
5
|
import { HAS_REANIMATED_3 } from "../external/reanimated/renderHelpers";
|
4
6
|
import type { JsiRecorder } from "../skia/types/Recorder";
|
5
7
|
|
@@ -13,9 +15,22 @@ import { ReanimatedRecorder } from "./Recorder/ReanimatedRecorder";
|
|
13
15
|
|
14
16
|
import "../views/api";
|
15
17
|
|
16
|
-
const drawOnscreen = (
|
18
|
+
const drawOnscreen = (
|
19
|
+
Skia: Skia,
|
20
|
+
nativeId: number,
|
21
|
+
recording: Recording,
|
22
|
+
onSize?: SharedValue<SkSize>
|
23
|
+
) => {
|
17
24
|
"worklet";
|
18
|
-
|
25
|
+
if (onSize) {
|
26
|
+
const size = SkiaViewApi.size(nativeId);
|
27
|
+
if (
|
28
|
+
size.width !== onSize.value.width ||
|
29
|
+
size.height !== onSize.value.height
|
30
|
+
) {
|
31
|
+
onSize.value = size;
|
32
|
+
}
|
33
|
+
}
|
19
34
|
const rec = Skia.PictureRecorder();
|
20
35
|
const canvas = rec.beginRecording();
|
21
36
|
//const start = performance.now();
|
@@ -28,11 +43,23 @@ const drawOnscreen = (Skia: Skia, nativeId: number, recording: Recording) => {
|
|
28
43
|
SkiaViewApi.setJsiProperty(nativeId, "picture", picture);
|
29
44
|
};
|
30
45
|
|
31
|
-
const nativeDrawOnscreen = (
|
46
|
+
const nativeDrawOnscreen = (
|
47
|
+
nativeId: number,
|
48
|
+
recorder: JsiRecorder,
|
49
|
+
onSize?: SharedValue<SkSize>
|
50
|
+
) => {
|
32
51
|
"worklet";
|
33
52
|
|
34
53
|
//const start = performance.now();
|
35
|
-
|
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
|
+
}
|
36
63
|
const picture = recorder.play();
|
37
64
|
//const end = performance.now();
|
38
65
|
//console.log("Recording time: ", end - start);
|
@@ -44,7 +71,7 @@ export abstract class Container {
|
|
44
71
|
protected recording: Recording | null = null;
|
45
72
|
protected unmounted = false;
|
46
73
|
|
47
|
-
constructor(protected Skia: Skia
|
74
|
+
constructor(protected Skia: Skia) {}
|
48
75
|
|
49
76
|
get root() {
|
50
77
|
return this._root;
|
@@ -78,8 +105,12 @@ export abstract class Container {
|
|
78
105
|
}
|
79
106
|
|
80
107
|
class StaticContainer extends Container {
|
81
|
-
constructor(
|
82
|
-
|
108
|
+
constructor(
|
109
|
+
Skia: Skia,
|
110
|
+
private nativeId: number,
|
111
|
+
private onSize?: SharedValue<SkSize>
|
112
|
+
) {
|
113
|
+
super(Skia);
|
83
114
|
}
|
84
115
|
|
85
116
|
redraw() {
|
@@ -88,6 +119,15 @@ class StaticContainer extends Container {
|
|
88
119
|
this.recording = recorder.getRecording();
|
89
120
|
const isOnScreen = this.nativeId !== -1;
|
90
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
|
+
}
|
91
131
|
const rec = this.Skia.PictureRecorder();
|
92
132
|
const canvas = rec.beginRecording();
|
93
133
|
this.drawOnCanvas(canvas);
|
@@ -100,8 +140,12 @@ class StaticContainer extends Container {
|
|
100
140
|
class ReanimatedContainer extends Container {
|
101
141
|
private mapperId: number | null = null;
|
102
142
|
|
103
|
-
constructor(
|
104
|
-
|
143
|
+
constructor(
|
144
|
+
Skia: Skia,
|
145
|
+
private nativeId: number,
|
146
|
+
private onSize?: SharedValue<SkSize>
|
147
|
+
) {
|
148
|
+
super(Skia);
|
105
149
|
}
|
106
150
|
|
107
151
|
redraw() {
|
@@ -128,7 +172,7 @@ class ReanimatedContainer extends Container {
|
|
128
172
|
}
|
129
173
|
Rea.runOnUI(() => {
|
130
174
|
"worklet";
|
131
|
-
drawOnscreen(Skia, nativeId, recording
|
175
|
+
drawOnscreen(Skia, nativeId, recording!, this.onSize);
|
132
176
|
})();
|
133
177
|
}
|
134
178
|
}
|
@@ -136,8 +180,12 @@ class ReanimatedContainer extends Container {
|
|
136
180
|
class NativeReanimatedContainer extends Container {
|
137
181
|
private mapperId: number | null = null;
|
138
182
|
|
139
|
-
constructor(
|
140
|
-
|
183
|
+
constructor(
|
184
|
+
Skia: Skia,
|
185
|
+
private nativeId: number,
|
186
|
+
private onSize?: SharedValue<SkSize>
|
187
|
+
) {
|
188
|
+
super(Skia);
|
141
189
|
}
|
142
190
|
|
143
191
|
redraw() {
|
@@ -152,27 +200,32 @@ class NativeReanimatedContainer extends Container {
|
|
152
200
|
visit(recorder, this.root);
|
153
201
|
const sharedValues = recorder.getSharedValues();
|
154
202
|
const sharedRecorder = recorder.getRecorder();
|
155
|
-
Rea.runOnUI(() => {
|
203
|
+
Rea.runOnUI((onSize?: SharedValue<SkSize>) => {
|
156
204
|
"worklet";
|
157
|
-
nativeDrawOnscreen(nativeId, sharedRecorder);
|
158
|
-
})();
|
205
|
+
nativeDrawOnscreen(nativeId, sharedRecorder, onSize);
|
206
|
+
})(this.onSize);
|
159
207
|
if (sharedValues.length > 0) {
|
208
|
+
const { onSize } = this;
|
160
209
|
this.mapperId = Rea.startMapper(() => {
|
161
210
|
"worklet";
|
162
211
|
sharedRecorder.applyUpdates(sharedValues);
|
163
|
-
nativeDrawOnscreen(nativeId, sharedRecorder);
|
212
|
+
nativeDrawOnscreen(nativeId, sharedRecorder, onSize);
|
164
213
|
}, sharedValues);
|
165
214
|
}
|
166
215
|
}
|
167
216
|
}
|
168
217
|
|
169
|
-
export const createContainer = (
|
218
|
+
export const createContainer = (
|
219
|
+
Skia: Skia,
|
220
|
+
nativeId: number,
|
221
|
+
onSize?: SharedValue<SkSize>
|
222
|
+
) => {
|
170
223
|
const web = global.SkiaViewApi && global.SkiaViewApi.web;
|
171
224
|
if (HAS_REANIMATED_3 && nativeId !== -1) {
|
172
225
|
if (!web) {
|
173
|
-
return new NativeReanimatedContainer(Skia, nativeId);
|
226
|
+
return new NativeReanimatedContainer(Skia, nativeId, onSize);
|
174
227
|
} else {
|
175
|
-
return new ReanimatedContainer(Skia, nativeId);
|
228
|
+
return new ReanimatedContainer(Skia, nativeId, onSize);
|
176
229
|
}
|
177
230
|
} else {
|
178
231
|
return new StaticContainer(Skia, nativeId);
|
package/src/sksg/Reconciler.ts
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
import type { ReactNode } from "react";
|
2
2
|
import type { OpaqueRoot } from "react-reconciler";
|
3
|
+
import type { SharedValue } from "react-native-reanimated";
|
3
4
|
import ReactReconciler from "react-reconciler";
|
4
5
|
|
5
|
-
import type { SkCanvas, Skia } from "../skia/types";
|
6
|
+
import type { SkCanvas, Skia, SkSize } from "../skia/types";
|
6
7
|
import { NodeType } from "../dom/types";
|
7
8
|
|
8
9
|
import { debug, sksgHostConfig } from "./HostConfig";
|
9
10
|
import type { Container } from "./Container";
|
10
11
|
import { createContainer } from "./Container";
|
12
|
+
|
11
13
|
import "./Elements";
|
12
14
|
|
13
15
|
const skiaReconciler = ReactReconciler(sksgHostConfig);
|
@@ -22,8 +24,8 @@ export class SkiaSGRoot {
|
|
22
24
|
private root: OpaqueRoot;
|
23
25
|
private container: Container;
|
24
26
|
|
25
|
-
constructor(public Skia: Skia, nativeId = -1) {
|
26
|
-
this.container = createContainer(Skia, nativeId);
|
27
|
+
constructor(public Skia: Skia, nativeId = -1, onSize?: SharedValue<SkSize>) {
|
28
|
+
this.container = createContainer(Skia, nativeId, onSize);
|
27
29
|
this.root = skiaReconciler.createContainer(
|
28
30
|
this.container,
|
29
31
|
0,
|
package/src/views/types.ts
CHANGED
@@ -15,6 +15,7 @@ export interface ISkiaViewApi {
|
|
15
15
|
requestRedraw: (nativeId: number) => void;
|
16
16
|
makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;
|
17
17
|
makeImageSnapshotAsync: (nativeId: number, rect?: SkRect) => Promise<SkImage>;
|
18
|
+
size: (nativeId: number) => SkSize;
|
18
19
|
}
|
19
20
|
|
20
21
|
export interface SkiaBaseViewProps extends ViewProps {
|