@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,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,54 +1,67 @@
|
|
1
|
+
var _global;
|
1
2
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
2
|
-
import React, {
|
3
|
+
import React, { useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
|
3
4
|
import { SkiaViewNativeId } from "../views/SkiaViewNativeId";
|
4
5
|
import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeComponent";
|
5
6
|
import { SkiaSGRoot } from "../sksg/Reconciler";
|
6
7
|
import { Skia } from "../skia";
|
7
8
|
export const useCanvasRef = () => useRef(null);
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
resultValue.value = {
|
23
|
-
width,
|
24
|
-
height
|
25
|
-
};
|
9
|
+
export const useCanvasSize = () => {
|
10
|
+
const ref = useCanvasRef();
|
11
|
+
const [size, setSize] = useState({
|
12
|
+
width: 0,
|
13
|
+
height: 0
|
14
|
+
});
|
15
|
+
useLayoutEffect(() => {
|
16
|
+
if (ref.current) {
|
17
|
+
ref.current.measure((_x, _y, width, height) => {
|
18
|
+
setSize({
|
19
|
+
width,
|
20
|
+
height
|
21
|
+
});
|
22
|
+
});
|
26
23
|
}
|
27
|
-
|
24
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
25
|
+
}, []);
|
26
|
+
return {
|
27
|
+
ref,
|
28
|
+
size
|
29
|
+
};
|
28
30
|
};
|
31
|
+
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
33
|
+
export const isFabric = Boolean((_global = global) === null || _global === void 0 ? void 0 : _global.nativeFabricUIManager);
|
29
34
|
export const Canvas = ({
|
30
35
|
debug,
|
31
36
|
opaque,
|
32
37
|
children,
|
33
38
|
onSize,
|
34
|
-
onLayout: _onLayout,
|
35
39
|
colorSpace = "p3",
|
36
40
|
ref,
|
41
|
+
// Here know this is a type error but this is done on purpose to check it at runtime
|
42
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
43
|
+
// @ts-expect-error
|
44
|
+
onLayout,
|
37
45
|
...viewProps
|
38
46
|
}) => {
|
39
|
-
|
47
|
+
if (onLayout && isFabric) {
|
48
|
+
console.error(
|
49
|
+
// eslint-disable-next-line max-len
|
50
|
+
"<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");
|
51
|
+
}
|
52
|
+
const viewRef = useRef(null);
|
40
53
|
// Native ID
|
41
54
|
const nativeId = useMemo(() => {
|
42
55
|
return SkiaViewNativeId.current++;
|
43
56
|
}, []);
|
44
57
|
|
45
58
|
// Root
|
46
|
-
const root = useMemo(() => new SkiaSGRoot(Skia, nativeId), [nativeId]);
|
59
|
+
const root = useMemo(() => new SkiaSGRoot(Skia, nativeId, onSize), [nativeId, onSize]);
|
47
60
|
|
48
61
|
// Render effects
|
49
62
|
useLayoutEffect(() => {
|
50
63
|
root.render(children);
|
51
|
-
}, [children, root]);
|
64
|
+
}, [children, root, nativeId]);
|
52
65
|
useEffect(() => {
|
53
66
|
return () => {
|
54
67
|
root.unmount();
|
@@ -68,15 +81,23 @@ export const Canvas = ({
|
|
68
81
|
},
|
69
82
|
getNativeId: () => {
|
70
83
|
return nativeId;
|
84
|
+
},
|
85
|
+
measure: callback => {
|
86
|
+
var _viewRef$current;
|
87
|
+
(_viewRef$current = viewRef.current) === null || _viewRef$current === void 0 || _viewRef$current.measure(callback);
|
88
|
+
},
|
89
|
+
measureInWindow: callback => {
|
90
|
+
var _viewRef$current2;
|
91
|
+
(_viewRef$current2 = viewRef.current) === null || _viewRef$current2 === void 0 || _viewRef$current2.measureInWindow(callback);
|
71
92
|
}
|
72
93
|
}));
|
73
94
|
return /*#__PURE__*/React.createElement(SkiaPictureViewNativeComponent, _extends({
|
95
|
+
ref: viewRef,
|
74
96
|
collapsable: false,
|
75
97
|
nativeID: `${nativeId}`,
|
76
98
|
debug: debug,
|
77
99
|
opaque: opaque,
|
78
|
-
colorSpace: colorSpace
|
79
|
-
onLayout: onLayout
|
100
|
+
colorSpace: colorSpace
|
80
101
|
}, viewProps));
|
81
102
|
};
|
82
103
|
//# sourceMappingURL=Canvas.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","
|
1
|
+
{"version":3,"names":["React","useEffect","useImperativeHandle","useLayoutEffect","useMemo","useRef","useState","SkiaViewNativeId","SkiaPictureViewNativeComponent","SkiaSGRoot","Skia","useCanvasRef","useCanvasSize","ref","size","setSize","width","height","current","measure","_x","_y","isFabric","Boolean","_global","global","nativeFabricUIManager","Canvas","debug","opaque","children","onSize","colorSpace","onLayout","viewProps","console","error","viewRef","nativeId","root","render","unmount","makeImageSnapshot","rect","SkiaViewApi","makeImageSnapshotAsync","redraw","requestRedraw","getNativeId","callback","_viewRef$current","measureInWindow","_viewRef$current2","createElement","_extends","collapsable","nativeID"],"sources":["Canvas.tsx"],"sourcesContent":["import type { FC } from \"react\";\nimport React, {\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type {\n MeasureInWindowOnSuccessCallback,\n MeasureOnSuccessCallback,\n View,\n ViewProps,\n} from \"react-native\";\nimport { type SharedValue } from \"react-native-reanimated\";\n\nimport { SkiaViewNativeId } from \"../views/SkiaViewNativeId\";\nimport SkiaPictureViewNativeComponent from \"../specs/SkiaPictureViewNativeComponent\";\nimport type { SkImage, SkRect, SkSize } from \"../skia/types\";\nimport { SkiaSGRoot } from \"../sksg/Reconciler\";\nimport { Skia } from \"../skia\";\n\nexport interface CanvasRef extends FC<CanvasProps> {\n makeImageSnapshot(rect?: SkRect): SkImage;\n makeImageSnapshotAsync(rect?: SkRect): Promise<SkImage>;\n redraw(): void;\n getNativeId(): number;\n measure(callback: MeasureOnSuccessCallback): void;\n measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;\n}\n\nexport const useCanvasRef = () => useRef<CanvasRef>(null);\n\nexport const useCanvasSize = () => {\n const ref = useCanvasRef();\n const [size, setSize] = useState<SkSize>({ width: 0, height: 0 });\n useLayoutEffect(() => {\n if (ref.current) {\n ref.current.measure((_x, _y, width, height) => {\n setSize({ width, height });\n });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n return { ref, size };\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const isFabric = Boolean((global as any)?.nativeFabricUIManager);\n\nexport interface CanvasProps extends Omit<ViewProps, \"onLayout\"> {\n debug?: boolean;\n opaque?: boolean;\n onSize?: SharedValue<SkSize>;\n colorSpace?: \"p3\" | \"srgb\";\n ref?: React.Ref<CanvasRef>;\n}\n\nexport const Canvas = ({\n debug,\n opaque,\n children,\n onSize,\n colorSpace = \"p3\",\n ref,\n // Here know this is a type error but this is done on purpose to check it at runtime\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n onLayout,\n ...viewProps\n}: CanvasProps) => {\n if (onLayout && isFabric) {\n console.error(\n // eslint-disable-next-line max-len\n \"<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\"\n );\n }\n const viewRef = useRef<View>(null);\n // Native ID\n const nativeId = useMemo(() => {\n return SkiaViewNativeId.current++;\n }, []);\n\n // Root\n const root = useMemo(\n () => new SkiaSGRoot(Skia, nativeId, onSize),\n [nativeId, onSize]\n );\n\n // Render effects\n useLayoutEffect(() => {\n root.render(children);\n }, [children, root, nativeId]);\n\n useEffect(() => {\n return () => {\n root.unmount();\n };\n }, [root]);\n\n // Component methods\n useImperativeHandle(\n ref,\n () =>\n ({\n makeImageSnapshot: (rect?: SkRect) => {\n return SkiaViewApi.makeImageSnapshot(nativeId, rect);\n },\n makeImageSnapshotAsync: (rect?: SkRect) => {\n return SkiaViewApi.makeImageSnapshotAsync(nativeId, rect);\n },\n redraw: () => {\n SkiaViewApi.requestRedraw(nativeId);\n },\n getNativeId: () => {\n return nativeId;\n },\n measure: (callback) => {\n viewRef.current?.measure(callback);\n },\n measureInWindow: (callback) => {\n viewRef.current?.measureInWindow(callback);\n },\n } as CanvasRef)\n );\n\n return (\n <SkiaPictureViewNativeComponent\n ref={viewRef}\n collapsable={false}\n nativeID={`${nativeId}`}\n debug={debug}\n opaque={opaque}\n colorSpace={colorSpace}\n {...viewProps}\n />\n );\n};\n"],"mappings":";;AACA,OAAOA,KAAK,IACVC,SAAS,EACTC,mBAAmB,EACnBC,eAAe,EACfC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACH,OAAO;AASd,SAASC,gBAAgB,QAAQ,2BAA2B;AAC5D,OAAOC,8BAA8B,MAAM,yCAAyC;AAEpF,SAASC,UAAU,QAAQ,oBAAoB;AAC/C,SAASC,IAAI,QAAQ,SAAS;AAW9B,OAAO,MAAMC,YAAY,GAAGA,CAAA,KAAMN,MAAM,CAAY,IAAI,CAAC;AAEzD,OAAO,MAAMO,aAAa,GAAGA,CAAA,KAAM;EACjC,MAAMC,GAAG,GAAGF,YAAY,CAAC,CAAC;EAC1B,MAAM,CAACG,IAAI,EAAEC,OAAO,CAAC,GAAGT,QAAQ,CAAS;IAAEU,KAAK,EAAE,CAAC;IAAEC,MAAM,EAAE;EAAE,CAAC,CAAC;EACjEd,eAAe,CAAC,MAAM;IACpB,IAAIU,GAAG,CAACK,OAAO,EAAE;MACfL,GAAG,CAACK,OAAO,CAACC,OAAO,CAAC,CAACC,EAAE,EAAEC,EAAE,EAAEL,KAAK,EAAEC,MAAM,KAAK;QAC7CF,OAAO,CAAC;UAAEC,KAAK;UAAEC;QAAO,CAAC,CAAC;MAC5B,CAAC,CAAC;IACJ;IACA;EACF,CAAC,E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AC;IACtD,CAAC;IACDE,sBAAsB,EAAGF,IAAa,IAAK;MACzC,OAAOC,WAAW,CAACC,sBAAsB,CAACP,QAAQ,EAAEK,IAAI,CAAC;IAC3D,CAAC;IACDG,MAAM,EAAEA,CAAA,KAAM;MACZF,WAAW,CAACG,aAAa,CAACT,QAAQ,CAAC;IACrC,CAAC;IACDU,WAAW,EAAEA,CAAA,KAAM;MACjB,OAAOV,QAAQ;IACjB,CAAC;IACDnB,OAAO,EAAG8B,QAAQ,IAAK;MAAA,IAAAC,gBAAA;MACrB,CAAAA,gBAAA,GAAAb,OAAO,CAACnB,OAAO,cAAAgC,gBAAA,eAAfA,gBAAA,CAAiB/B,OAAO,CAAC8B,QAAQ,CAAC;IACpC,CAAC;IACDE,eAAe,EAAGF,QAAQ,IAAK;MAAA,IAAAG,iBAAA;MAC7B,CAAAA,iBAAA,GAAAf,OAAO,CAACnB,OAAO,cAAAkC,iBAAA,eAAfA,iBAAA,CAAiBD,eAAe,CAACF,QAAQ,CAAC;IAC5C;EACF,CAAC,CACL,CAAC;EAED,oBACEjD,KAAA,CAAAqD,aAAA,CAAC7C,8BAA8B,EAAA8C,QAAA;IAC7BzC,GAAG,EAAEwB,OAAQ;IACbkB,WAAW,EAAE,KAAM;IACnBC,QAAQ,EAAE,GAAGlB,QAAQ,EAAG;IACxBV,KAAK,EAAEA,KAAM;IACbC,MAAM,EAAEA,MAAO;IACfG,UAAU,EAAEA;EAAW,GACnBE,SAAS,CACd,CAAC;AAEN,CAAC","ignoreList":[]}
|
@@ -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 {};
|
@@ -9,9 +9,15 @@ import { replay } from "./Recorder/Player";
|
|
9
9
|
import { createDrawingContext } from "./Recorder/DrawingContext";
|
10
10
|
import { ReanimatedRecorder } from "./Recorder/ReanimatedRecorder";
|
11
11
|
import "../views/api";
|
12
|
-
const drawOnscreen = (Skia, nativeId, recording) => {
|
12
|
+
const drawOnscreen = (Skia, nativeId, recording, onSize) => {
|
13
13
|
"worklet";
|
14
14
|
|
15
|
+
if (onSize) {
|
16
|
+
const size = SkiaViewApi.size(nativeId);
|
17
|
+
if (size.width !== onSize.value.width || size.height !== onSize.value.height) {
|
18
|
+
onSize.value = size;
|
19
|
+
}
|
20
|
+
}
|
15
21
|
const rec = Skia.PictureRecorder();
|
16
22
|
const canvas = rec.beginRecording();
|
17
23
|
//const start = performance.now();
|
@@ -23,19 +29,24 @@ const drawOnscreen = (Skia, nativeId, recording) => {
|
|
23
29
|
//console.log("Recording time: ", end - start);
|
24
30
|
SkiaViewApi.setJsiProperty(nativeId, "picture", picture);
|
25
31
|
};
|
26
|
-
const nativeDrawOnscreen = (nativeId, recorder) => {
|
32
|
+
const nativeDrawOnscreen = (nativeId, recorder, onSize) => {
|
27
33
|
"worklet";
|
28
34
|
|
29
35
|
//const start = performance.now();
|
36
|
+
if (onSize) {
|
37
|
+
const size = SkiaViewApi.size(nativeId);
|
38
|
+
if (size.width !== onSize.value.width || size.height !== onSize.value.height) {
|
39
|
+
onSize.value = size;
|
40
|
+
}
|
41
|
+
}
|
30
42
|
const picture = recorder.play();
|
31
43
|
//const end = performance.now();
|
32
44
|
//console.log("Recording time: ", end - start);
|
33
45
|
SkiaViewApi.setJsiProperty(nativeId, "picture", picture);
|
34
46
|
};
|
35
47
|
export class Container {
|
36
|
-
constructor(Skia
|
48
|
+
constructor(Skia) {
|
37
49
|
this.Skia = Skia;
|
38
|
-
this.nativeId = nativeId;
|
39
50
|
_defineProperty(this, "_root", []);
|
40
51
|
_defineProperty(this, "recording", null);
|
41
52
|
_defineProperty(this, "unmounted", false);
|
@@ -61,8 +72,10 @@ export class Container {
|
|
61
72
|
}
|
62
73
|
}
|
63
74
|
class StaticContainer extends Container {
|
64
|
-
constructor(Skia, nativeId) {
|
65
|
-
super(Skia
|
75
|
+
constructor(Skia, nativeId, onSize) {
|
76
|
+
super(Skia);
|
77
|
+
this.nativeId = nativeId;
|
78
|
+
this.onSize = onSize;
|
66
79
|
}
|
67
80
|
redraw() {
|
68
81
|
const recorder = new Recorder();
|
@@ -70,6 +83,12 @@ class StaticContainer extends Container {
|
|
70
83
|
this.recording = recorder.getRecording();
|
71
84
|
const isOnScreen = this.nativeId !== -1;
|
72
85
|
if (isOnScreen) {
|
86
|
+
if (this.onSize) {
|
87
|
+
const size = SkiaViewApi.size(this.nativeId);
|
88
|
+
if (size.width !== this.onSize.value.width || size.height !== this.onSize.value.height) {
|
89
|
+
this.onSize.value = size;
|
90
|
+
}
|
91
|
+
}
|
73
92
|
const rec = this.Skia.PictureRecorder();
|
74
93
|
const canvas = rec.beginRecording();
|
75
94
|
this.drawOnCanvas(canvas);
|
@@ -79,8 +98,10 @@ class StaticContainer extends Container {
|
|
79
98
|
}
|
80
99
|
}
|
81
100
|
class ReanimatedContainer extends Container {
|
82
|
-
constructor(Skia, nativeId) {
|
83
|
-
super(Skia
|
101
|
+
constructor(Skia, nativeId, onSize) {
|
102
|
+
super(Skia);
|
103
|
+
this.nativeId = nativeId;
|
104
|
+
this.onSize = onSize;
|
84
105
|
_defineProperty(this, "mapperId", null);
|
85
106
|
}
|
86
107
|
redraw() {
|
@@ -115,13 +136,15 @@ class ReanimatedContainer extends Container {
|
|
115
136
|
Rea.runOnUI(() => {
|
116
137
|
"worklet";
|
117
138
|
|
118
|
-
drawOnscreen(Skia, nativeId, recording);
|
139
|
+
drawOnscreen(Skia, nativeId, recording, this.onSize);
|
119
140
|
})();
|
120
141
|
}
|
121
142
|
}
|
122
143
|
class NativeReanimatedContainer extends Container {
|
123
|
-
constructor(Skia, nativeId) {
|
124
|
-
super(Skia
|
144
|
+
constructor(Skia, nativeId, onSize) {
|
145
|
+
super(Skia);
|
146
|
+
this.nativeId = nativeId;
|
147
|
+
this.onSize = onSize;
|
125
148
|
_defineProperty(this, "mapperId", null);
|
126
149
|
}
|
127
150
|
redraw() {
|
@@ -139,28 +162,31 @@ class NativeReanimatedContainer extends Container {
|
|
139
162
|
visit(recorder, this.root);
|
140
163
|
const sharedValues = recorder.getSharedValues();
|
141
164
|
const sharedRecorder = recorder.getRecorder();
|
142
|
-
Rea.runOnUI(
|
165
|
+
Rea.runOnUI(onSize => {
|
143
166
|
"worklet";
|
144
167
|
|
145
|
-
nativeDrawOnscreen(nativeId, sharedRecorder);
|
146
|
-
})();
|
168
|
+
nativeDrawOnscreen(nativeId, sharedRecorder, onSize);
|
169
|
+
})(this.onSize);
|
147
170
|
if (sharedValues.length > 0) {
|
171
|
+
const {
|
172
|
+
onSize
|
173
|
+
} = this;
|
148
174
|
this.mapperId = Rea.startMapper(() => {
|
149
175
|
"worklet";
|
150
176
|
|
151
177
|
sharedRecorder.applyUpdates(sharedValues);
|
152
|
-
nativeDrawOnscreen(nativeId, sharedRecorder);
|
178
|
+
nativeDrawOnscreen(nativeId, sharedRecorder, onSize);
|
153
179
|
}, sharedValues);
|
154
180
|
}
|
155
181
|
}
|
156
182
|
}
|
157
|
-
export const createContainer = (Skia, nativeId) => {
|
183
|
+
export const createContainer = (Skia, nativeId, onSize) => {
|
158
184
|
const web = global.SkiaViewApi && global.SkiaViewApi.web;
|
159
185
|
if (HAS_REANIMATED_3 && nativeId !== -1) {
|
160
186
|
if (!web) {
|
161
|
-
return new NativeReanimatedContainer(Skia, nativeId);
|
187
|
+
return new NativeReanimatedContainer(Skia, nativeId, onSize);
|
162
188
|
} else {
|
163
|
-
return new ReanimatedContainer(Skia, nativeId);
|
189
|
+
return new ReanimatedContainer(Skia, nativeId, onSize);
|
164
190
|
}
|
165
191
|
} else {
|
166
192
|
return new StaticContainer(Skia, nativeId);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Rea","HAS_REANIMATED_3","Recorder","visit","replay","createDrawingContext","ReanimatedRecorder","drawOnscreen","Skia","nativeId","recording","rec","PictureRecorder","canvas","beginRecording","ctx","paintPool","commands","picture","finishRecordingAsPicture","SkiaViewApi","setJsiProperty","nativeDrawOnscreen","recorder","play","Container","constructor","_defineProperty","root","_root","value","mount","unmounted","unmount","drawOnCanvas","Error","StaticContainer","redraw","getRecording","isOnScreen","ReanimatedContainer","mapperId","stopMapper","record","animationValues","size","startMapper","Array","from","runOnUI","NativeReanimatedContainer","sharedValues","getSharedValues","sharedRecorder","getRecorder","length","applyUpdates","createContainer","web","global"],"sources":["Container.ts"],"sourcesContent":["import Rea from \"../external/reanimated/ReanimatedProxy\";\nimport type { Skia, SkCanvas } from \"../skia/types\";\nimport { HAS_REANIMATED_3 } from \"../external/reanimated/renderHelpers\";\nimport type { JsiRecorder } from \"../skia/types/Recorder\";\n\nimport type { Node } from \"./Node\";\nimport type { Recording } from \"./Recorder/Recorder\";\nimport { Recorder } from \"./Recorder/Recorder\";\nimport { visit } from \"./Recorder/Visitor\";\nimport { replay } from \"./Recorder/Player\";\nimport { createDrawingContext } from \"./Recorder/DrawingContext\";\nimport { ReanimatedRecorder } from \"./Recorder/ReanimatedRecorder\";\n\nimport \"../views/api\";\n\nconst drawOnscreen = (Skia: Skia, nativeId: number, recording: Recording) => {\n \"worklet\";\n\n const rec = Skia.PictureRecorder();\n const canvas = rec.beginRecording();\n //const start = performance.now();\n\n const ctx = createDrawingContext(Skia, recording.paintPool, canvas);\n replay(ctx, recording.commands);\n const picture = rec.finishRecordingAsPicture();\n //const end = performance.now();\n //console.log(\"Recording time: \", end - start);\n SkiaViewApi.setJsiProperty(nativeId, \"picture\", picture);\n};\n\nconst nativeDrawOnscreen = (nativeId: number, recorder: JsiRecorder) => {\n \"worklet\";\n\n //const start = performance.now();\n\n const picture = recorder.play();\n //const end = performance.now();\n //console.log(\"Recording time: \", end - start);\n SkiaViewApi.setJsiProperty(nativeId, \"picture\", picture);\n};\n\nexport abstract class Container {\n private _root: Node[] = [];\n protected recording: Recording | null = null;\n protected unmounted = false;\n\n constructor(protected Skia: Skia, protected nativeId: number) {}\n\n get root() {\n return this._root;\n }\n\n set root(value: Node[]) {\n this._root = value;\n }\n\n mount() {\n this.unmounted = false;\n }\n\n unmount() {\n this.unmounted = true;\n }\n\n drawOnCanvas(canvas: SkCanvas) {\n if (!this.recording) {\n throw new Error(\"No recording to draw\");\n }\n const ctx = createDrawingContext(\n this.Skia,\n this.recording.paintPool,\n canvas\n );\n replay(ctx, this.recording.commands);\n }\n\n abstract redraw(): void;\n}\n\nclass StaticContainer extends Container {\n constructor(Skia: Skia, nativeId: number) {\n super(Skia, nativeId);\n }\n\n redraw() {\n const recorder = new Recorder();\n visit(recorder, this.root);\n this.recording = recorder.getRecording();\n const isOnScreen = this.nativeId !== -1;\n if (isOnScreen) {\n const rec = this.Skia.PictureRecorder();\n const canvas = rec.beginRecording();\n this.drawOnCanvas(canvas);\n const picture = rec.finishRecordingAsPicture();\n SkiaViewApi.setJsiProperty(this.nativeId, \"picture\", picture);\n }\n }\n}\n\nclass ReanimatedContainer extends Container {\n private mapperId: number | null = null;\n\n constructor(Skia: Skia, nativeId: number) {\n super(Skia, nativeId);\n }\n\n redraw() {\n if (this.mapperId !== null) {\n Rea.stopMapper(this.mapperId);\n }\n if (this.unmounted) {\n return;\n }\n const recorder = new Recorder();\n visit(recorder, this.root);\n const record = recorder.getRecording();\n const { animationValues } = record;\n this.recording = {\n commands: record.commands,\n paintPool: record.paintPool,\n };\n const { nativeId, Skia, recording } = this;\n if (animationValues.size > 0) {\n this.mapperId = Rea.startMapper(() => {\n \"worklet\";\n drawOnscreen(Skia, nativeId, recording!);\n }, Array.from(animationValues));\n }\n Rea.runOnUI(() => {\n \"worklet\";\n drawOnscreen(Skia, nativeId, recording!);\n })();\n }\n}\n\nclass NativeReanimatedContainer extends Container {\n private mapperId: number | null = null;\n\n constructor(Skia: Skia, nativeId: number) {\n super(Skia, nativeId);\n }\n\n redraw() {\n if (this.mapperId !== null) {\n Rea.stopMapper(this.mapperId);\n }\n if (this.unmounted) {\n return;\n }\n const { nativeId, Skia } = this;\n const recorder = new ReanimatedRecorder(Skia);\n visit(recorder, this.root);\n const sharedValues = recorder.getSharedValues();\n const sharedRecorder = recorder.getRecorder();\n Rea.runOnUI(() => {\n \"worklet\";\n nativeDrawOnscreen(nativeId, sharedRecorder);\n })();\n if (sharedValues.length > 0) {\n this.mapperId = Rea.startMapper(() => {\n \"worklet\";\n sharedRecorder.applyUpdates(sharedValues);\n nativeDrawOnscreen(nativeId, sharedRecorder);\n }, sharedValues);\n }\n }\n}\n\nexport const createContainer = (Skia: Skia, nativeId: number) => {\n const web = global.SkiaViewApi && global.SkiaViewApi.web;\n if (HAS_REANIMATED_3 && nativeId !== -1) {\n if (!web) {\n return new NativeReanimatedContainer(Skia, nativeId);\n } else {\n return new ReanimatedContainer(Skia, nativeId);\n }\n } else {\n return new StaticContainer(Skia, nativeId);\n }\n};\n"],"mappings":";;;AAAA,OAAOA,GAAG,MAAM,wCAAwC;AAExD,SAASC,gBAAgB,QAAQ,sCAAsC;AAKvE,SAASC,QAAQ,QAAQ,qBAAqB;AAC9C,SAASC,KAAK,QAAQ,oBAAoB;AAC1C,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,oBAAoB,QAAQ,2BAA2B;AAChE,SAASC,kBAAkB,QAAQ,+BAA+B;AAElE,OAAO,cAAc;AAErB,MAAMC,YAAY,GAAGA,CAACC,IAAU,EAAEC,QAAgB,EAAEC,SAAoB,KAAK;EAC3E,SAAS;;EAET,MAAMC,GAAG,GAAGH,IAAI,CAACI,eAAe,CAAC,CAAC;EAClC,MAAMC,MAAM,GAAGF,GAAG,CAACG,cAAc,CAAC,CAAC;EACnC;;EAEA,MAAMC,GAAG,GAAGV,oBAAoB,CAACG,IAAI,EAAEE,SAAS,CAACM,SAAS,EAAEH,MAAM,CAAC;EACnET,MAAM,CAACW,GAAG,EAAEL,SAAS,CAACO,QAAQ,CAAC;EAC/B,MAAMC,OAAO,GAAGP,GAAG,CAACQ,wBAAwB,CAAC,CAAC;EAC9C;EACA;EACAC,WAAW,CAACC,cAAc,CAACZ,QAAQ,EAAE,SAAS,EAAES,OAAO,CAAC;AAC1D,CAAC;AAED,MAAMI,kBAAkB,GAAGA,CAACb,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AS;;MACT3B,kBAAkB,CAACb,QAAQ,EAAE4C,cAAc,CAAC;IAC9C,CAAC,CAAC,CAAC,CAAC;IACJ,IAAIF,YAAY,CAACI,MAAM,GAAG,CAAC,EAAE;MAC3B,IAAI,CAACd,QAAQ,GAAGzC,GAAG,CAAC8C,WAAW,CAAC,MAAM;QACpC,SAAS;;QACTO,cAAc,CAACG,YAAY,CAACL,YAAY,CAAC;QACzC7B,kBAAkB,CAACb,QAAQ,EAAE4C,cAAc,CAAC;MAC9C,CAAC,EAAEF,YAAY,CAAC;IAClB;EACF;AACF;AAEA,OAAO,MAAMM,eAAe,GAAGA,CAACjD,IAAU,EAAEC,QAAgB,KAAK;EAC/D,MAAMiD,GAAG,GAAGC,MAAM,CAACvC,WAAW,IAAIuC,MAAM,CAACvC,WAAW,CAACsC,GAAG;EACxD,IAAIzD,gBAAgB,IAAIQ,QAAQ,KAAK,CAAC,CAAC,EAAE;IACvC,IAAI,CAACiD,GAAG,EAAE;MACR,OAAO,IAAIR,yBAAyB,CAAC1C,IAAI,EAAEC,QAAQ,CAAC;IACtD,CAAC,MAAM;MACL,OAAO,IAAI+B,mBAAmB,CAAChC,IAAI,EAAEC,QAAQ,CAAC;IAChD;EACF,CAAC,MAAM;IACL,OAAO,IAAI2B,eAAe,CAAC5B,IAAI,EAAEC,QAAQ,CAAC;EAC5C;AACF,CAAC","ignoreList":[]}
|
1
|
+
{"version":3,"names":["Rea","HAS_REANIMATED_3","Recorder","visit","replay","createDrawingContext","ReanimatedRecorder","drawOnscreen","Skia","nativeId","recording","onSize","size","SkiaViewApi","width","value","height","rec","PictureRecorder","canvas","beginRecording","ctx","paintPool","commands","picture","finishRecordingAsPicture","setJsiProperty","nativeDrawOnscreen","recorder","play","Container","constructor","_defineProperty","root","_root","mount","unmounted","unmount","drawOnCanvas","Error","StaticContainer","redraw","getRecording","isOnScreen","ReanimatedContainer","mapperId","stopMapper","record","animationValues","startMapper","Array","from","runOnUI","NativeReanimatedContainer","sharedValues","getSharedValues","sharedRecorder","getRecorder","length","applyUpdates","createContainer","web","global"],"sources":["Container.ts"],"sourcesContent":["import type { SharedValue } from \"react-native-reanimated\";\n\nimport Rea from \"../external/reanimated/ReanimatedProxy\";\nimport type { Skia, SkCanvas, SkSize } from \"../skia/types\";\nimport { HAS_REANIMATED_3 } from \"../external/reanimated/renderHelpers\";\nimport type { JsiRecorder } from \"../skia/types/Recorder\";\n\nimport type { Node } from \"./Node\";\nimport type { Recording } from \"./Recorder/Recorder\";\nimport { Recorder } from \"./Recorder/Recorder\";\nimport { visit } from \"./Recorder/Visitor\";\nimport { replay } from \"./Recorder/Player\";\nimport { createDrawingContext } from \"./Recorder/DrawingContext\";\nimport { ReanimatedRecorder } from \"./Recorder/ReanimatedRecorder\";\n\nimport \"../views/api\";\n\nconst drawOnscreen = (\n Skia: Skia,\n nativeId: number,\n recording: Recording,\n onSize?: SharedValue<SkSize>\n) => {\n \"worklet\";\n if (onSize) {\n const size = SkiaViewApi.size(nativeId);\n if (\n size.width !== onSize.value.width ||\n size.height !== onSize.value.height\n ) {\n onSize.value = size;\n }\n }\n const rec = Skia.PictureRecorder();\n const canvas = rec.beginRecording();\n //const start = performance.now();\n\n const ctx = createDrawingContext(Skia, recording.paintPool, canvas);\n replay(ctx, recording.commands);\n const picture = rec.finishRecordingAsPicture();\n //const end = performance.now();\n //console.log(\"Recording time: \", end - start);\n SkiaViewApi.setJsiProperty(nativeId, \"picture\", picture);\n};\n\nconst nativeDrawOnscreen = (\n nativeId: number,\n recorder: JsiRecorder,\n onSize?: SharedValue<SkSize>\n) => {\n \"worklet\";\n\n //const start = performance.now();\n if (onSize) {\n const size = SkiaViewApi.size(nativeId);\n if (\n size.width !== onSize.value.width ||\n size.height !== onSize.value.height\n ) {\n onSize.value = size;\n }\n }\n const picture = recorder.play();\n //const end = performance.now();\n //console.log(\"Recording time: \", end - start);\n SkiaViewApi.setJsiProperty(nativeId, \"picture\", picture);\n};\n\nexport abstract class Container {\n private _root: Node[] = [];\n protected recording: Recording | null = null;\n protected unmounted = false;\n\n constructor(protected Skia: Skia) {}\n\n get root() {\n return this._root;\n }\n\n set root(value: Node[]) {\n this._root = value;\n }\n\n mount() {\n this.unmounted = false;\n }\n\n unmount() {\n this.unmounted = true;\n }\n\n drawOnCanvas(canvas: SkCanvas) {\n if (!this.recording) {\n throw new Error(\"No recording to draw\");\n }\n const ctx = createDrawingContext(\n this.Skia,\n this.recording.paintPool,\n canvas\n );\n replay(ctx, this.recording.commands);\n }\n\n abstract redraw(): void;\n}\n\nclass StaticContainer extends Container {\n constructor(\n Skia: Skia,\n private nativeId: number,\n private onSize?: SharedValue<SkSize>\n ) {\n super(Skia);\n }\n\n redraw() {\n const recorder = new Recorder();\n visit(recorder, this.root);\n this.recording = recorder.getRecording();\n const isOnScreen = this.nativeId !== -1;\n if (isOnScreen) {\n if (this.onSize) {\n const size = SkiaViewApi.size(this.nativeId);\n if (\n size.width !== this.onSize.value.width ||\n size.height !== this.onSize.value.height\n ) {\n this.onSize.value = size;\n }\n }\n const rec = this.Skia.PictureRecorder();\n const canvas = rec.beginRecording();\n this.drawOnCanvas(canvas);\n const picture = rec.finishRecordingAsPicture();\n SkiaViewApi.setJsiProperty(this.nativeId, \"picture\", picture);\n }\n }\n}\n\nclass ReanimatedContainer extends Container {\n private mapperId: number | null = null;\n\n constructor(\n Skia: Skia,\n private nativeId: number,\n private onSize?: SharedValue<SkSize>\n ) {\n super(Skia);\n }\n\n redraw() {\n if (this.mapperId !== null) {\n Rea.stopMapper(this.mapperId);\n }\n if (this.unmounted) {\n return;\n }\n const recorder = new Recorder();\n visit(recorder, this.root);\n const record = recorder.getRecording();\n const { animationValues } = record;\n this.recording = {\n commands: record.commands,\n paintPool: record.paintPool,\n };\n const { nativeId, Skia, recording } = this;\n if (animationValues.size > 0) {\n this.mapperId = Rea.startMapper(() => {\n \"worklet\";\n drawOnscreen(Skia, nativeId, recording!);\n }, Array.from(animationValues));\n }\n Rea.runOnUI(() => {\n \"worklet\";\n drawOnscreen(Skia, nativeId, recording!, this.onSize);\n })();\n }\n}\n\nclass NativeReanimatedContainer extends Container {\n private mapperId: number | null = null;\n\n constructor(\n Skia: Skia,\n private nativeId: number,\n private onSize?: SharedValue<SkSize>\n ) {\n super(Skia);\n }\n\n redraw() {\n if (this.mapperId !== null) {\n Rea.stopMapper(this.mapperId);\n }\n if (this.unmounted) {\n return;\n }\n const { nativeId, Skia } = this;\n const recorder = new ReanimatedRecorder(Skia);\n visit(recorder, this.root);\n const sharedValues = recorder.getSharedValues();\n const sharedRecorder = recorder.getRecorder();\n Rea.runOnUI((onSize?: SharedValue<SkSize>) => {\n \"worklet\";\n nativeDrawOnscreen(nativeId, sharedRecorder, onSize);\n })(this.onSize);\n if (sharedValues.length > 0) {\n const { onSize } = this;\n this.mapperId = Rea.startMapper(() => {\n \"worklet\";\n sharedRecorder.applyUpdates(sharedValues);\n nativeDrawOnscreen(nativeId, sharedRecorder, onSize);\n }, sharedValues);\n }\n }\n}\n\nexport const createContainer = (\n Skia: Skia,\n nativeId: number,\n onSize?: SharedValue<SkSize>\n) => {\n const web = global.SkiaViewApi && global.SkiaViewApi.web;\n if (HAS_REANIMATED_3 && nativeId !== -1) {\n if (!web) {\n return new NativeReanimatedContainer(Skia, nativeId, onSize);\n } else {\n return new ReanimatedContainer(Skia, nativeId, onSize);\n }\n } else {\n return new StaticContainer(Skia, nativeId);\n }\n};\n"],"mappings":";;;AAEA,OAAOA,GAAG,MAAM,wCAAwC;AAExD,SAASC,gBAAgB,QAAQ,sCAAsC;AAKvE,SAASC,QAAQ,QAAQ,qBAAqB;AAC9C,SAASC,KAAK,QAAQ,oBAAoB;AAC1C,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,oBAAoB,QAAQ,2BAA2B;AAChE,SAASC,kBAAkB,QAAQ,+BAA+B;AAElE,OAAO,cAAc;AAErB,MAAMC,YAAY,GAAGA,CACnBC,IAAU,EACVC,QAAgB,EAChBC,SAAoB,EACpBC,MAA4B,K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C,MAAM;IACL,OAAO,IAAI6B,eAAe,CAAChC,IAAI,EAAEC,QAAQ,CAAC;EAC5C;AACF,CAAC","ignoreList":[]}
|
@@ -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: {};
|
@@ -13,11 +13,11 @@ skiaReconciler.injectIntoDevTools({
|
|
13
13
|
rendererPackageName: "react-native-skia"
|
14
14
|
});
|
15
15
|
export class SkiaSGRoot {
|
16
|
-
constructor(Skia, nativeId = -1) {
|
16
|
+
constructor(Skia, nativeId = -1, onSize) {
|
17
17
|
this.Skia = Skia;
|
18
18
|
_defineProperty(this, "root", void 0);
|
19
19
|
_defineProperty(this, "container", void 0);
|
20
|
-
this.container = createContainer(Skia, nativeId);
|
20
|
+
this.container = createContainer(Skia, nativeId, onSize);
|
21
21
|
this.root = skiaReconciler.createContainer(this.container, 0, null, true, null, "", console.error, null);
|
22
22
|
}
|
23
23
|
get sg() {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["ReactReconciler","NodeType","debug","sksgHostConfig","createContainer","skiaReconciler","injectIntoDevTools","bundleType","version","rendererPackageName","SkiaSGRoot","constructor","Skia","nativeId","_defineProperty","container","root","console","error","sg","children","type","Group","props","isDeclaration","updateContainer","element","Promise","resolve","render","mount","redraw","drawOnCanvas","canvas","getPicture","recorder","PictureRecorder","beginRecording","finishRecordingAsPicture","unmount"],"sources":["Reconciler.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { OpaqueRoot } from \"react-reconciler\";\nimport ReactReconciler from \"react-reconciler\";\n\nimport type { SkCanvas, Skia } from \"../skia/types\";\nimport { NodeType } from \"../dom/types\";\n\nimport { debug, sksgHostConfig } from \"./HostConfig\";\nimport type { Container } from \"./Container\";\nimport { createContainer } from \"./Container\";\nimport \"./Elements\";\n\nconst skiaReconciler = ReactReconciler(sksgHostConfig);\n\nskiaReconciler.injectIntoDevTools({\n bundleType: 1,\n version: \"0.0.1\",\n rendererPackageName: \"react-native-skia\",\n});\n\nexport class SkiaSGRoot {\n private root: OpaqueRoot;\n private container: Container;\n\n constructor(public Skia: Skia, nativeId = -1) {\n this.container = createContainer(Skia, nativeId);\n this.root = skiaReconciler.createContainer(\n this.container,\n 0,\n null,\n true,\n null,\n \"\",\n console.error,\n null\n );\n }\n\n get sg() {\n const children = this.container.root;\n return { type: NodeType.Group, props: {}, children, isDeclaration: false };\n }\n\n private updateContainer(element: ReactNode) {\n return new Promise((resolve) => {\n skiaReconciler.updateContainer(element, this.root, null, () => {\n debug(\"updateContainer\");\n resolve(true);\n });\n });\n }\n\n async render(element: ReactNode) {\n this.container.mount();\n await this.updateContainer(element);\n this.container.redraw();\n }\n\n drawOnCanvas(canvas: SkCanvas) {\n this.container.drawOnCanvas(canvas);\n }\n\n getPicture() {\n const recorder = this.Skia.PictureRecorder();\n const canvas = recorder.beginRecording();\n this.drawOnCanvas(canvas);\n return recorder.finishRecordingAsPicture();\n }\n\n unmount() {\n this.container.unmount();\n return new Promise((resolve) => {\n skiaReconciler.updateContainer(null, this.root, null, () => {\n debug(\"unmountContainer\");\n resolve(true);\n });\n });\n }\n}\n"],"mappings":";;;
|
1
|
+
{"version":3,"names":["ReactReconciler","NodeType","debug","sksgHostConfig","createContainer","skiaReconciler","injectIntoDevTools","bundleType","version","rendererPackageName","SkiaSGRoot","constructor","Skia","nativeId","onSize","_defineProperty","container","root","console","error","sg","children","type","Group","props","isDeclaration","updateContainer","element","Promise","resolve","render","mount","redraw","drawOnCanvas","canvas","getPicture","recorder","PictureRecorder","beginRecording","finishRecordingAsPicture","unmount"],"sources":["Reconciler.ts"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { OpaqueRoot } from \"react-reconciler\";\nimport type { SharedValue } from \"react-native-reanimated\";\nimport ReactReconciler from \"react-reconciler\";\n\nimport type { SkCanvas, Skia, SkSize } from \"../skia/types\";\nimport { NodeType } from \"../dom/types\";\n\nimport { debug, sksgHostConfig } from \"./HostConfig\";\nimport type { Container } from \"./Container\";\nimport { createContainer } from \"./Container\";\n\nimport \"./Elements\";\n\nconst skiaReconciler = ReactReconciler(sksgHostConfig);\n\nskiaReconciler.injectIntoDevTools({\n bundleType: 1,\n version: \"0.0.1\",\n rendererPackageName: \"react-native-skia\",\n});\n\nexport class SkiaSGRoot {\n private root: OpaqueRoot;\n private container: Container;\n\n constructor(public Skia: Skia, nativeId = -1, onSize?: SharedValue<SkSize>) {\n this.container = createContainer(Skia, nativeId, onSize);\n this.root = skiaReconciler.createContainer(\n this.container,\n 0,\n null,\n true,\n null,\n \"\",\n console.error,\n null\n );\n }\n\n get sg() {\n const children = this.container.root;\n return { type: NodeType.Group, props: {}, children, isDeclaration: false };\n }\n\n private updateContainer(element: ReactNode) {\n return new Promise((resolve) => {\n skiaReconciler.updateContainer(element, this.root, null, () => {\n debug(\"updateContainer\");\n resolve(true);\n });\n });\n }\n\n async render(element: ReactNode) {\n this.container.mount();\n await this.updateContainer(element);\n this.container.redraw();\n }\n\n drawOnCanvas(canvas: SkCanvas) {\n this.container.drawOnCanvas(canvas);\n }\n\n getPicture() {\n const recorder = this.Skia.PictureRecorder();\n const canvas = recorder.beginRecording();\n this.drawOnCanvas(canvas);\n return recorder.finishRecordingAsPicture();\n }\n\n unmount() {\n this.container.unmount();\n return new Promise((resolve) => {\n skiaReconciler.updateContainer(null, this.root, null, () => {\n debug(\"unmountContainer\");\n resolve(true);\n });\n });\n }\n}\n"],"mappings":";;;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AAC;MACf,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;EAEA,MAAMC,MAAMA,CAACH,OAAkB,EAAE;IAC/B,IAAI,CAACX,SAAS,CAACe,KAAK,CAAC,CAAC;IACtB,MAAM,IAAI,CAACL,eAAe,CAACC,OAAO,CAAC;IACnC,IAAI,CAACX,SAAS,CAACgB,MAAM,CAAC,CAAC;EACzB;EAEAC,YAAYA,CAACC,MAAgB,EAAE;IAC7B,IAAI,CAAClB,SAAS,CAACiB,YAAY,CAACC,MAAM,CAAC;EACrC;EAEAC,UAAUA,CAAA,EAAG;IACX,MAAMC,QAAQ,GAAG,IAAI,CAACxB,IAAI,CAACyB,eAAe,CAAC,CAAC;IAC5C,MAAMH,MAAM,GAAGE,QAAQ,CAACE,cAAc,CAAC,CAAC;IACxC,IAAI,CAACL,YAAY,CAACC,MAAM,CAAC;IACzB,OAAOE,QAAQ,CAACG,wBAAwB,CAAC,CAAC;EAC5C;EAEAC,OAAOA,CAAA,EAAG;IACR,IAAI,CAACxB,SAAS,CAACwB,OAAO,CAAC,CAAC;IACxB,OAAO,IAAIZ,OAAO,CAAEC,OAAO,IAAK;MAC9BxB,cAAc,CAACqB,eAAe,CAAC,IAAI,EAAE,IAAI,CAACT,IAAI,EAAE,IAAI,EAAE,MAAM;QAC1Df,KAAK,CAAC,kBAAkB,CAAC;QACzB2B,OAAO,CAAC,IAAI,CAAC;MACf,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
|
@@ -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
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { ViewProps } from \"react-native\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport type { Node } from \"../dom/types\";\nimport type { SkImage, SkPicture, SkRect, SkSize } from \"../skia/types\";\n\nexport type NativeSkiaViewProps = ViewProps & {\n debug?: boolean;\n opaque?: boolean;\n};\n\nexport interface ISkiaViewApi {\n web?: boolean;\n setJsiProperty: <T>(nativeId: number, name: string, value: T) => void;\n requestRedraw: (nativeId: number) => void;\n makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;\n makeImageSnapshotAsync: (nativeId: number, rect?: SkRect) => Promise<SkImage>;\n}\n\nexport interface SkiaBaseViewProps extends ViewProps {\n /**\n * When set to true the view will display information about the\n * average time it takes to render.\n */\n debug?: boolean;\n /**\n * Pass an animated value to the onSize property to get updates when\n * the Skia view is resized.\n */\n onSize?: SharedValue<SkSize>;\n\n opaque?: boolean;\n}\n\nexport interface SkiaPictureViewNativeProps extends SkiaBaseViewProps {\n picture?: SkPicture;\n}\n\nexport interface SkiaDomViewNativeProps extends SkiaBaseViewProps {\n root?: Node<unknown>;\n}\n"],"mappings":"","ignoreList":[]}
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { ViewProps } from \"react-native\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport type { Node } from \"../dom/types\";\nimport type { SkImage, SkPicture, SkRect, SkSize } from \"../skia/types\";\n\nexport type NativeSkiaViewProps = ViewProps & {\n debug?: boolean;\n opaque?: boolean;\n};\n\nexport interface ISkiaViewApi {\n web?: boolean;\n setJsiProperty: <T>(nativeId: number, name: string, value: T) => void;\n requestRedraw: (nativeId: number) => void;\n makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;\n makeImageSnapshotAsync: (nativeId: number, rect?: SkRect) => Promise<SkImage>;\n size: (nativeId: number) => SkSize;\n}\n\nexport interface SkiaBaseViewProps extends ViewProps {\n /**\n * When set to true the view will display information about the\n * average time it takes to render.\n */\n debug?: boolean;\n /**\n * Pass an animated value to the onSize property to get updates when\n * the Skia view is resized.\n */\n onSize?: SharedValue<SkSize>;\n\n opaque?: boolean;\n}\n\nexport interface SkiaPictureViewNativeProps extends SkiaBaseViewProps {\n picture?: SkPicture;\n}\n\nexport interface SkiaDomViewNativeProps extends SkiaBaseViewProps {\n root?: Node<unknown>;\n}\n"],"mappings":"","ignoreList":[]}
|
@@ -1,12 +1,17 @@
|
|
1
1
|
export const __esModule: boolean;
|
2
|
+
export const isFabric: boolean;
|
2
3
|
export function useCanvasRef(): any;
|
3
|
-
export function
|
4
|
+
export function useCanvasSize(): {
|
5
|
+
ref: any;
|
6
|
+
size: any;
|
7
|
+
};
|
8
|
+
export function Canvas({ debug, opaque, children, onSize, colorSpace, ref, onLayout, ...viewProps }: {
|
4
9
|
[x: string]: any;
|
5
10
|
debug: any;
|
6
11
|
opaque: any;
|
7
12
|
children: any;
|
8
13
|
onSize: any;
|
9
|
-
onLayout: any;
|
10
14
|
colorSpace?: string | undefined;
|
11
15
|
ref: any;
|
16
|
+
onLayout: any;
|
12
17
|
}): any;
|
@@ -1,8 +1,7 @@
|
|
1
1
|
export const __esModule: boolean;
|
2
2
|
export class Container {
|
3
|
-
constructor(Skia: any
|
3
|
+
constructor(Skia: any);
|
4
4
|
Skia: any;
|
5
|
-
nativeId: any;
|
6
5
|
set root(value: any);
|
7
6
|
get root(): any;
|
8
7
|
_root: any;
|
@@ -11,12 +10,18 @@ export class Container {
|
|
11
10
|
unmount(): void;
|
12
11
|
drawOnCanvas(canvas: any): void;
|
13
12
|
}
|
14
|
-
export function createContainer(Skia: any, nativeId: any): NativeReanimatedContainer | ReanimatedContainer | StaticContainer;
|
13
|
+
export function createContainer(Skia: any, nativeId: any, onSize: any): NativeReanimatedContainer | ReanimatedContainer | StaticContainer;
|
15
14
|
declare class NativeReanimatedContainer extends Container {
|
15
|
+
constructor(Skia: any, nativeId: any, onSize: any);
|
16
|
+
nativeId: any;
|
17
|
+
onSize: any;
|
16
18
|
redraw(): void;
|
17
19
|
mapperId: any;
|
18
20
|
}
|
19
21
|
declare class ReanimatedContainer extends Container {
|
22
|
+
constructor(Skia: any, nativeId: any, onSize: any);
|
23
|
+
nativeId: any;
|
24
|
+
onSize: any;
|
20
25
|
redraw(): void;
|
21
26
|
recording: {
|
22
27
|
commands: any;
|
@@ -25,6 +30,9 @@ declare class ReanimatedContainer extends Container {
|
|
25
30
|
mapperId: any;
|
26
31
|
}
|
27
32
|
declare class StaticContainer extends Container {
|
33
|
+
constructor(Skia: any, nativeId: any, onSize: any);
|
34
|
+
nativeId: any;
|
35
|
+
onSize: any;
|
28
36
|
redraw(): void;
|
29
37
|
recording: {
|
30
38
|
commands: any;
|
@@ -1,12 +1,13 @@
|
|
1
1
|
export const __esModule: boolean;
|
2
2
|
export class SkiaSGRoot {
|
3
|
-
constructor(Skia: any, nativeId
|
3
|
+
constructor(Skia: any, nativeId: number | undefined, onSize: any);
|
4
4
|
Skia: any;
|
5
5
|
container: {
|
6
|
+
nativeId: any;
|
7
|
+
onSize: any;
|
6
8
|
redraw(): void;
|
7
9
|
mapperId: any;
|
8
10
|
Skia: any;
|
9
|
-
nativeId: any;
|
10
11
|
root: any;
|
11
12
|
_root: any;
|
12
13
|
mount(): void;
|
@@ -14,6 +15,8 @@ export class SkiaSGRoot {
|
|
14
15
|
unmount(): void;
|
15
16
|
drawOnCanvas(canvas: any): void;
|
16
17
|
} | {
|
18
|
+
nativeId: any;
|
19
|
+
onSize: any;
|
17
20
|
redraw(): void;
|
18
21
|
recording: {
|
19
22
|
commands: any;
|
@@ -21,7 +24,6 @@ export class SkiaSGRoot {
|
|
21
24
|
} | undefined;
|
22
25
|
mapperId: any;
|
23
26
|
Skia: any;
|
24
|
-
nativeId: any;
|
25
27
|
root: any;
|
26
28
|
_root: any;
|
27
29
|
mount(): void;
|
@@ -29,6 +31,8 @@ export class SkiaSGRoot {
|
|
29
31
|
unmount(): void;
|
30
32
|
drawOnCanvas(canvas: any): void;
|
31
33
|
} | {
|
34
|
+
nativeId: any;
|
35
|
+
onSize: any;
|
32
36
|
redraw(): void;
|
33
37
|
recording: {
|
34
38
|
commands: any;
|
@@ -36,7 +40,6 @@ export class SkiaSGRoot {
|
|
36
40
|
animationValues: any;
|
37
41
|
} | undefined;
|
38
42
|
Skia: any;
|
39
|
-
nativeId: any;
|
40
43
|
root: any;
|
41
44
|
_root: any;
|
42
45
|
mount(): void;
|