@shopify/react-native-skia 1.12.3 → 2.0.0-next.2
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/build.gradle +1 -1
- package/lib/commonjs/Platform/Platform.web.js +1 -0
- package/lib/commonjs/Platform/Platform.web.js.map +1 -1
- package/lib/commonjs/external/reanimated/textures.js +4 -3
- package/lib/commonjs/external/reanimated/textures.js.map +1 -1
- package/lib/commonjs/headless/index.d.ts +1 -1
- package/lib/commonjs/headless/index.js +2 -2
- package/lib/commonjs/headless/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.d.ts +3 -3
- package/lib/commonjs/renderer/Canvas.js +10 -27
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/Offscreen.d.ts +2 -2
- package/lib/commonjs/renderer/Offscreen.js +4 -4
- package/lib/commonjs/renderer/Offscreen.js.map +1 -1
- package/lib/commonjs/renderer/__tests__/setup.d.ts +6 -5
- package/lib/commonjs/sksg/Container.d.ts +3 -1
- package/lib/commonjs/sksg/Container.js +7 -1
- package/lib/commonjs/sksg/Container.js.map +1 -1
- package/lib/commonjs/sksg/Elements.d.ts +1 -1
- package/lib/commonjs/sksg/Elements.js.map +1 -1
- package/lib/commonjs/sksg/HostConfig.d.ts +2 -2
- package/lib/commonjs/sksg/HostConfig.js +36 -6
- package/lib/commonjs/sksg/HostConfig.js.map +1 -1
- package/lib/commonjs/sksg/Reconciler.d.ts +3 -2
- package/lib/commonjs/sksg/Reconciler.js +15 -6
- package/lib/commonjs/sksg/Reconciler.js.map +1 -1
- package/lib/module/Platform/Platform.web.js +1 -0
- package/lib/module/Platform/Platform.web.js.map +1 -1
- package/lib/module/external/reanimated/textures.js +5 -4
- package/lib/module/external/reanimated/textures.js.map +1 -1
- package/lib/module/headless/index.d.ts +1 -1
- package/lib/module/headless/index.js +2 -2
- package/lib/module/headless/index.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +3 -3
- package/lib/module/renderer/Canvas.js +9 -27
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/Offscreen.d.ts +2 -2
- package/lib/module/renderer/Offscreen.js +4 -4
- package/lib/module/renderer/Offscreen.js.map +1 -1
- package/lib/module/renderer/__tests__/setup.d.ts +6 -5
- package/lib/module/sksg/Container.d.ts +3 -1
- package/lib/module/sksg/Container.js +7 -1
- package/lib/module/sksg/Container.js.map +1 -1
- package/lib/module/sksg/Elements.d.ts +1 -1
- package/lib/module/sksg/Elements.js.map +1 -1
- package/lib/module/sksg/HostConfig.d.ts +2 -2
- package/lib/module/sksg/HostConfig.js +36 -7
- package/lib/module/sksg/HostConfig.js.map +1 -1
- package/lib/module/sksg/Reconciler.d.ts +3 -2
- package/lib/module/sksg/Reconciler.js +15 -6
- package/lib/module/sksg/Reconciler.js.map +1 -1
- package/lib/typescript/lib/commonjs/headless/index.d.ts +1 -1
- package/lib/typescript/lib/commonjs/renderer/Canvas.d.ts +9 -1
- package/lib/typescript/lib/commonjs/renderer/Offscreen.d.ts +2 -2
- package/lib/typescript/lib/commonjs/sksg/Container.d.ts +3 -0
- package/lib/typescript/lib/commonjs/sksg/HostConfig.d.ts +21 -4
- package/lib/typescript/lib/commonjs/sksg/Reconciler.d.ts +9 -2
- package/lib/typescript/lib/module/Platform/Platform.web.d.ts +1 -1
- package/lib/typescript/lib/module/headless/index.d.ts +1 -1
- package/lib/typescript/lib/module/mock/index.d.ts +22 -11
- package/lib/typescript/lib/module/renderer/Canvas.d.ts +10 -2
- package/lib/typescript/lib/module/renderer/Offscreen.d.ts +2 -2
- package/lib/typescript/lib/module/sksg/Container.d.ts +3 -0
- package/lib/typescript/lib/module/sksg/HostConfig.d.ts +20 -4
- package/lib/typescript/lib/module/sksg/Reconciler.d.ts +9 -2
- package/lib/typescript/lib/module/views/SkiaPictureView.d.ts +1 -1
- package/lib/typescript/src/headless/index.d.ts +1 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +3 -3
- package/lib/typescript/src/renderer/Offscreen.d.ts +2 -2
- package/lib/typescript/src/renderer/__tests__/setup.d.ts +6 -5
- package/lib/typescript/src/sksg/Container.d.ts +3 -1
- package/lib/typescript/src/sksg/Elements.d.ts +1 -1
- package/lib/typescript/src/sksg/HostConfig.d.ts +2 -2
- package/lib/typescript/src/sksg/Reconciler.d.ts +3 -2
- package/package.json +11 -10
- package/src/Platform/Platform.web.tsx +2 -1
- package/src/__tests__/snapshots/screens/snapshot2-android-ci.png +0 -0
- package/src/__tests__/snapshots/screens/snapshot3-android-ci.png +0 -0
- package/src/external/reanimated/textures.tsx +5 -4
- package/src/headless/index.ts +2 -2
- package/src/renderer/Canvas.tsx +57 -80
- package/src/renderer/Offscreen.tsx +4 -4
- package/src/renderer/__tests__/Data.spec.tsx +9 -10
- package/src/renderer/__tests__/Drawings.spec.tsx +11 -11
- package/src/renderer/__tests__/FitBox.spec.tsx +10 -10
- package/src/renderer/__tests__/Glyphs.spec.tsx +2 -2
- package/src/renderer/__tests__/Image.spec.tsx +2 -2
- package/src/renderer/__tests__/Paths.spec.tsx +8 -8
- package/src/renderer/__tests__/Picture.spec.tsx +10 -12
- package/src/renderer/__tests__/Simple.spec.tsx +6 -6
- package/src/renderer/__tests__/Surfaces.spec.tsx +2 -2
- package/src/renderer/__tests__/Text.spec.tsx +12 -12
- package/src/renderer/__tests__/Transform.spec.tsx +8 -8
- package/src/renderer/__tests__/documentation/Group.spec.tsx +12 -12
- package/src/renderer/__tests__/documentation/getting-started/HelloWorld.spec.tsx +2 -2
- package/src/renderer/__tests__/documentation/paint/Overview.spec.tsx +8 -8
- package/src/renderer/__tests__/documentation/shapes/Box.spec.tsx +4 -4
- package/src/renderer/__tests__/e2e/Atlas.spec.tsx +3 -3
- package/src/renderer/__tests__/e2e/Offscreen.spec.tsx +1 -1
- package/src/renderer/__tests__/examples/BlendModes.spec.tsx +4 -4
- package/src/renderer/__tests__/setup.tsx +17 -13
- package/src/sksg/Container.ts +9 -1
- package/src/sksg/Elements.tsx +1 -1
- package/src/sksg/HostConfig.ts +37 -7
- package/src/sksg/Reconciler.ts +16 -6
- package/src/sksg/__tests__/Simple.spec.tsx +8 -8
- package/lib/commonjs/sksg/HostConfig2.d.ts +0 -19
- package/lib/commonjs/sksg/HostConfig2.js +0 -159
- package/lib/commonjs/sksg/HostConfig2.js.map +0 -1
- package/lib/module/sksg/HostConfig2.d.ts +0 -19
- package/lib/module/sksg/HostConfig2.js +0 -152
- package/lib/module/sksg/HostConfig2.js.map +0 -1
- package/lib/typescript/lib/commonjs/sksg/HostConfig2.d.ts +0 -44
- package/lib/typescript/lib/module/sksg/HostConfig2.d.ts +0 -43
- package/lib/typescript/src/sksg/HostConfig2.d.ts +0 -19
- package/src/sksg/HostConfig2.ts +0 -247
@@ -7,8 +7,8 @@ export namespace sksgHostConfig {
|
|
7
7
|
let scheduleTimeout: typeof setTimeout;
|
8
8
|
let cancelTimeout: typeof clearTimeout;
|
9
9
|
let noTimeout: number;
|
10
|
-
function getRootHostContext(_rootContainerInstance: any):
|
11
|
-
function getChildHostContext(_parentHostContext: any, _type: any, _rootContainerInstance: any):
|
10
|
+
function getRootHostContext(_rootContainerInstance: any): {};
|
11
|
+
function getChildHostContext(_parentHostContext: any, _type: any, _rootContainerInstance: any): {};
|
12
12
|
function shouldSetTextContent(_type: any, _props: any): boolean;
|
13
13
|
function createTextInstance(_text: any, _rootContainerInstance: any, _hostContext: any, _internalInstanceHandle: any): never;
|
14
14
|
function createInstance(type: any, propsWithChildren: any, _container: any, _hostContext: any, _internalInstanceHandle: any): {
|
@@ -20,13 +20,13 @@ export namespace sksgHostConfig {
|
|
20
20
|
function finalizeInitialChildren(parentInstance: any, _type: any, _props: any, _rootContainerInstance: any, _hostContext: any): boolean;
|
21
21
|
function commitMount(): void;
|
22
22
|
function prepareForCommit(_container: any): null;
|
23
|
-
function resetAfterCommit(
|
23
|
+
function resetAfterCommit(_container: any): void;
|
24
24
|
function getPublicInstance(node: any): any;
|
25
25
|
function commitTextUpdate(_textInstance: any, _oldText: any, _newText: any): void;
|
26
26
|
function clearContainer(_container: any): void;
|
27
27
|
function prepareUpdate(_instance: any, _type: any, oldProps: any, newProps: any, container: any, _hostContext: any): any;
|
28
28
|
function preparePortalMount(): void;
|
29
|
-
function cloneInstance(instance: any,
|
29
|
+
function cloneInstance(instance: any, _type: any, _oldProps: any, newProps: any, _updatePayload: any, _internalInstanceHandle: any, keepChildren: any, _recyclableInstance: any): {
|
30
30
|
type: any;
|
31
31
|
props: any;
|
32
32
|
children: any[];
|
@@ -44,4 +44,20 @@ export namespace sksgHostConfig {
|
|
44
44
|
function getInstanceFromNode(_node: any): never;
|
45
45
|
function prepareScopeUpdate(_scopeInstance: any, _instance: any): never;
|
46
46
|
function getInstanceFromScope(_scopeInstance: any): never;
|
47
|
+
function shouldAttemptEagerTransition(): boolean;
|
48
|
+
function trackSchedulerEvent(): void;
|
49
|
+
function resolveEventType(): null;
|
50
|
+
function resolveEventTimeStamp(): number;
|
51
|
+
function requestPostPaintCallback(): void;
|
52
|
+
function maySuspendCommit(): boolean;
|
53
|
+
function preloadInstance(): boolean;
|
54
|
+
function startSuspendingCommit(): void;
|
55
|
+
function suspendInstance(): void;
|
56
|
+
function waitForCommitToBeReady(): null;
|
57
|
+
let NotPendingTransition: null;
|
58
|
+
let HostTransitionContext: import("react").Context<null>;
|
59
|
+
function setCurrentUpdatePriority(newPriority: any): void;
|
60
|
+
function getCurrentUpdatePriority(): number;
|
61
|
+
function resolveUpdatePriority(): number;
|
62
|
+
function resetFormInstance(): void;
|
47
63
|
}
|
@@ -10,6 +10,8 @@ export class SkiaSGRoot {
|
|
10
10
|
} | undefined;
|
11
11
|
Skia: any;
|
12
12
|
nativeId: any;
|
13
|
+
root: any;
|
14
|
+
_root: any;
|
13
15
|
unmount(): void;
|
14
16
|
unmounted: boolean | undefined;
|
15
17
|
drawOnCanvas(canvas: any): void;
|
@@ -22,6 +24,8 @@ export class SkiaSGRoot {
|
|
22
24
|
mapperId: any;
|
23
25
|
Skia: any;
|
24
26
|
nativeId: any;
|
27
|
+
root: any;
|
28
|
+
_root: any;
|
25
29
|
unmount(): void;
|
26
30
|
unmounted: boolean | undefined;
|
27
31
|
drawOnCanvas(canvas: any): void;
|
@@ -30,6 +34,8 @@ export class SkiaSGRoot {
|
|
30
34
|
mapperId: any;
|
31
35
|
Skia: any;
|
32
36
|
nativeId: any;
|
37
|
+
root: any;
|
38
|
+
_root: any;
|
33
39
|
unmount(): void;
|
34
40
|
unmounted: boolean | undefined;
|
35
41
|
drawOnCanvas(canvas: any): void;
|
@@ -41,8 +47,9 @@ export class SkiaSGRoot {
|
|
41
47
|
children: any;
|
42
48
|
isDeclaration: boolean;
|
43
49
|
};
|
44
|
-
|
50
|
+
updateContainer(element: any): Promise<any>;
|
51
|
+
render(element: any): Promise<void>;
|
45
52
|
drawOnCanvas(canvas: any): void;
|
46
53
|
getPicture(): any;
|
47
|
-
unmount():
|
54
|
+
unmount(): Promise<any>;
|
48
55
|
}
|
@@ -16,6 +16,6 @@ export class SkiaPictureView extends React.Component<any, any, any> {
|
|
16
16
|
* Sends a redraw request to the native SkiaView.
|
17
17
|
*/
|
18
18
|
redraw(): void;
|
19
|
-
render(): React.CElement<object, React.Component<object, {}, any> &
|
19
|
+
render(): React.CElement<object, React.Component<object, {}, any> & import("react-native").NativeMethods>;
|
20
20
|
}
|
21
21
|
import React from "react";
|
@@ -6,4 +6,4 @@ export declare const makeOffscreenSurface: (width: number, height: number) => Sk
|
|
6
6
|
export declare const getSkiaExports: () => {
|
7
7
|
Skia: import("../skia/types").Skia;
|
8
8
|
};
|
9
|
-
export declare const drawOffscreen: (surface: SkSurface, element: ReactNode) => import("../skia").SkImage
|
9
|
+
export declare const drawOffscreen: (surface: SkSurface, element: ReactNode) => Promise<import("../skia").SkImage>;
|
@@ -9,12 +9,12 @@ interface CanvasRef extends FC<CanvasProps> {
|
|
9
9
|
redraw(): void;
|
10
10
|
getNativeId(): number;
|
11
11
|
}
|
12
|
-
export declare const useCanvasRef: () => React.RefObject<CanvasRef>;
|
12
|
+
export declare const useCanvasRef: () => React.RefObject<CanvasRef | null>;
|
13
13
|
export interface CanvasProps extends ViewProps {
|
14
14
|
debug?: boolean;
|
15
15
|
opaque?: boolean;
|
16
16
|
onSize?: SharedValue<SkSize>;
|
17
|
-
|
17
|
+
ref?: React.Ref<CanvasRef>;
|
18
18
|
}
|
19
|
-
export declare const Canvas:
|
19
|
+
export declare const Canvas: ({ debug, opaque, children, onSize, onLayout: _onLayout, ref, ...viewProps }: CanvasProps) => React.JSX.Element;
|
20
20
|
export {};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { ReactElement } from "react";
|
2
2
|
import type { SkPicture, SkRect, SkSize } from "../skia/types";
|
3
3
|
export declare const isOnMainThread: () => boolean;
|
4
|
-
export declare const drawAsPicture: (element: ReactElement, bounds?: SkRect) => SkPicture
|
5
|
-
export declare const drawAsImage: (element: ReactElement, size: SkSize) => import("../skia").SkImage
|
4
|
+
export declare const drawAsPicture: (element: ReactElement, bounds?: SkRect) => Promise<SkPicture>;
|
5
|
+
export declare const drawAsImage: (element: ReactElement, size: SkSize) => Promise<import("../skia").SkImage>;
|
6
6
|
export declare const drawAsImageFromPicture: (picture: SkPicture, size: SkSize) => import("../skia").SkImage;
|
@@ -43,13 +43,14 @@ export declare const center: {
|
|
43
43
|
x: number;
|
44
44
|
y: number;
|
45
45
|
};
|
46
|
-
export declare const drawOnNode: (element: ReactNode) => SkiaExports.SkSurface
|
47
|
-
export declare const mountCanvas: (element: ReactNode) => {
|
46
|
+
export declare const drawOnNode: (element: ReactNode) => Promise<SkiaExports.SkSurface>;
|
47
|
+
export declare const mountCanvas: (element: ReactNode) => Promise<{
|
48
48
|
surface: SkiaExports.SkSurface;
|
49
49
|
root: SkiaSGRoot;
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
render: () => Promise<void>;
|
51
|
+
draw: () => Promise<void>;
|
52
|
+
}>;
|
53
|
+
export declare const serialize: (element: ReactNode) => Promise<string>;
|
53
54
|
export type EvalContext = Record<string, any>;
|
54
55
|
interface TestingSurface {
|
55
56
|
eval<Ctx extends EvalContext = EvalContext, R = any>(fn: (Skia: Skia, ctx: Ctx) => R, ctx?: Ctx): Promise<R>;
|
@@ -5,10 +5,12 @@ import "../views/api";
|
|
5
5
|
export declare abstract class Container {
|
6
6
|
protected Skia: Skia;
|
7
7
|
protected nativeId: number;
|
8
|
-
|
8
|
+
private _root;
|
9
9
|
protected recording: Recording | null;
|
10
10
|
protected unmounted: boolean;
|
11
11
|
constructor(Skia: Skia, nativeId: number);
|
12
|
+
get root(): Node[];
|
13
|
+
set root(value: Node[]);
|
12
14
|
unmount(): void;
|
13
15
|
drawOnCanvas(canvas: SkCanvas): void;
|
14
16
|
abstract redraw(): void;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { FractalNoiseProps, CircleProps, DrawingNodeProps, ImageProps, PaintProps, PathProps, LineProps, OvalProps, DiffRectProps, PointsProps, RectProps, RoundedRectProps, TextProps, VerticesProps, BlurMaskFilterProps, BlendImageFilterProps, BlurImageFilterProps, DisplacementMapImageFilterProps, DropShadowImageFilterProps, OffsetImageFilterProps, RuntimeShaderImageFilterProps, MatrixColorFilterProps, ShaderProps, ImageShaderProps, LinearGradientProps, GroupProps, PatchProps, BlendColorFilterProps, DashPathEffectProps, DiscretePathEffectProps, CornerPathEffectProps, Line2DPathEffectProps, Path1DPathEffectProps, Path2DPathEffectProps, TextPathProps, TextBlobProps, GlyphsProps, TwoPointConicalGradientProps, TurbulenceProps, SweepGradientProps, RadialGradientProps, ColorProps, PictureProps, ImageSVGProps, LerpColorFilterProps, BoxProps, BoxShadowProps, ParagraphProps, AtlasProps, ChildrenProps, MorphologyImageFilterProps, BlendProps } from "../dom/types";
|
2
2
|
import type { SkiaProps } from "../renderer";
|
3
|
-
declare
|
3
|
+
declare module "react" {
|
4
4
|
namespace JSX {
|
5
5
|
interface IntrinsicElements {
|
6
6
|
skGroup: SkiaProps<GroupProps>;
|
@@ -2,14 +2,14 @@ import type { HostConfig } from "react-reconciler";
|
|
2
2
|
import type { NodeType } from "../dom/types";
|
3
3
|
import type { Node } from "./Node";
|
4
4
|
import type { Container } from "./Container";
|
5
|
-
export declare const debug: (
|
5
|
+
export declare const debug: (...args: Parameters<typeof console.log>) => void;
|
6
6
|
type Instance = Node;
|
7
7
|
type Props = object;
|
8
8
|
type TextInstance = Node;
|
9
9
|
type SuspenseInstance = Instance;
|
10
10
|
type HydratableInstance = Instance;
|
11
11
|
type PublicInstance = Instance;
|
12
|
-
type HostContext =
|
12
|
+
type HostContext = object;
|
13
13
|
type UpdatePayload = Container;
|
14
14
|
type ChildSet = Node[];
|
15
15
|
type TimeoutHandle = NodeJS.Timeout;
|
@@ -13,8 +13,9 @@ export declare class SkiaSGRoot {
|
|
13
13
|
children: import("./Node").Node<unknown>[];
|
14
14
|
isDeclaration: boolean;
|
15
15
|
};
|
16
|
-
|
16
|
+
private updateContainer;
|
17
|
+
render(element: ReactNode): Promise<void>;
|
17
18
|
drawOnCanvas(canvas: SkCanvas): void;
|
18
19
|
getPicture(): import("../skia/types").SkPicture;
|
19
|
-
unmount():
|
20
|
+
unmount(): Promise<unknown>;
|
20
21
|
}
|
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": "
|
11
|
+
"version": "2.0.0-next.2",
|
12
12
|
"description": "High-performance React Native Graphics using Skia",
|
13
13
|
"main": "lib/module/index.js",
|
14
14
|
"react-native": "src/index.ts",
|
@@ -76,9 +76,9 @@
|
|
76
76
|
"licenseFilename": "LICENSE.md",
|
77
77
|
"readmeFilename": "README.md",
|
78
78
|
"peerDependencies": {
|
79
|
-
"react": ">=
|
80
|
-
"react-native": ">=0.
|
81
|
-
"react-native-reanimated": ">=
|
79
|
+
"react": ">=19.0",
|
80
|
+
"react-native": ">=0.78",
|
81
|
+
"react-native-reanimated": ">=3.0.0"
|
82
82
|
},
|
83
83
|
"peerDependenciesMeta": {
|
84
84
|
"react-native": {
|
@@ -97,7 +97,7 @@
|
|
97
97
|
"@types/jest": "29.5.6",
|
98
98
|
"@types/pixelmatch": "5.2.4",
|
99
99
|
"@types/pngjs": "6.0.1",
|
100
|
-
"@types/react": "^
|
100
|
+
"@types/react": "^19.0.0",
|
101
101
|
"@types/react-reconciler": "0.28.9",
|
102
102
|
"@types/ws": "8.5.3",
|
103
103
|
"eslint": "8",
|
@@ -109,10 +109,10 @@
|
|
109
109
|
"pixelmatch": "5.3.0",
|
110
110
|
"pngjs": "6.0.0",
|
111
111
|
"prettier": "2.8.7",
|
112
|
-
"react": "
|
113
|
-
"react-native": "0.
|
112
|
+
"react": "19.0.0",
|
113
|
+
"react-native": "0.78.0",
|
114
114
|
"react-native-builder-bob": "0.18.2",
|
115
|
-
"react-native-reanimated": "
|
115
|
+
"react-native-reanimated": "3.17.1",
|
116
116
|
"rimraf": "3.0.2",
|
117
117
|
"semantic-release": "^24.1.0",
|
118
118
|
"semantic-release-yarn": "^3.0.2",
|
@@ -123,7 +123,7 @@
|
|
123
123
|
},
|
124
124
|
"dependencies": {
|
125
125
|
"canvaskit-wasm": "0.40.0",
|
126
|
-
"react-reconciler": "0.
|
126
|
+
"react-reconciler": "0.31.0"
|
127
127
|
},
|
128
128
|
"eslintIgnore": [
|
129
129
|
"node_modules/",
|
@@ -155,5 +155,6 @@
|
|
155
155
|
}
|
156
156
|
]
|
157
157
|
]
|
158
|
-
}
|
158
|
+
},
|
159
|
+
"stableVersion": "0.0.0"
|
159
160
|
}
|
@@ -98,7 +98,8 @@ const useElementLayout = (ref: RefObject<Div>, onLayout: OnLayout) => {
|
|
98
98
|
const View = (({ children, onLayout, style: rawStyle }: ViewProps) => {
|
99
99
|
const style = useMemo(() => (rawStyle ?? {}) as CSSProperties, [rawStyle]);
|
100
100
|
const ref = useRef<Div>(null);
|
101
|
-
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
102
|
+
useElementLayout(ref as any, onLayout);
|
102
103
|
const cssStyles = useMemo(() => {
|
103
104
|
return {
|
104
105
|
alignItems: "stretch" as const,
|
Binary file
|
Binary file
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { useEffect, useMemo } from "react";
|
1
|
+
import { useEffect, useMemo, useState } from "react";
|
2
2
|
import type { ReactElement } from "react";
|
3
3
|
import type { SharedValue } from "react-native-reanimated";
|
4
4
|
|
@@ -27,13 +27,14 @@ const createTexture = (
|
|
27
27
|
|
28
28
|
export const useTexture = (element: ReactElement, size: SkSize) => {
|
29
29
|
const { width, height } = size;
|
30
|
-
const picture =
|
31
|
-
|
30
|
+
const [picture, setPicture] = useState<SkPicture | null>(null);
|
31
|
+
useEffect(() => {
|
32
|
+
drawAsPicture(element, {
|
32
33
|
x: 0,
|
33
34
|
y: 0,
|
34
35
|
width,
|
35
36
|
height,
|
36
|
-
});
|
37
|
+
}).then((pic) => setPicture(pic));
|
37
38
|
}, [element, width, height]);
|
38
39
|
return usePictureAsTexture(picture, size);
|
39
40
|
};
|
package/src/headless/index.ts
CHANGED
@@ -30,9 +30,9 @@ export const getSkiaExports = () => {
|
|
30
30
|
return { Skia };
|
31
31
|
};
|
32
32
|
|
33
|
-
export const drawOffscreen = (surface: SkSurface, element: ReactNode) => {
|
33
|
+
export const drawOffscreen = async (surface: SkSurface, element: ReactNode) => {
|
34
34
|
const root = new SkiaSGRoot(Skia);
|
35
|
-
root.render(element);
|
35
|
+
await root.render(element);
|
36
36
|
const canvas = surface.getCanvas();
|
37
37
|
root.drawOnCanvas(canvas);
|
38
38
|
root.unmount();
|
package/src/renderer/Canvas.tsx
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import type { FC } from "react";
|
2
2
|
import React, {
|
3
|
-
forwardRef,
|
4
3
|
useCallback,
|
5
4
|
useEffect,
|
6
5
|
useImperativeHandle,
|
@@ -27,7 +26,7 @@ interface CanvasRef extends FC<CanvasProps> {
|
|
27
26
|
|
28
27
|
export const useCanvasRef = () => useRef<CanvasRef>(null);
|
29
28
|
|
30
|
-
const NativeSkiaPictureView = SkiaPictureViewNativeComponent;
|
29
|
+
//const NativeSkiaPictureView = SkiaPictureViewNativeComponent;
|
31
30
|
|
32
31
|
// TODO: no need to go through the JS thread for this
|
33
32
|
const useOnSizeEvent = (
|
@@ -53,87 +52,65 @@ export interface CanvasProps extends ViewProps {
|
|
53
52
|
debug?: boolean;
|
54
53
|
opaque?: boolean;
|
55
54
|
onSize?: SharedValue<SkSize>;
|
56
|
-
|
55
|
+
ref?: React.Ref<CanvasRef>;
|
57
56
|
}
|
58
57
|
|
59
|
-
export const Canvas =
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
const onLayout = useOnSizeEvent(onSize, _onLayout);
|
74
|
-
// Native ID
|
75
|
-
const nativeId = useMemo(() => {
|
76
|
-
return SkiaViewNativeId.current++;
|
77
|
-
}, []);
|
58
|
+
export const Canvas = ({
|
59
|
+
debug,
|
60
|
+
opaque,
|
61
|
+
children,
|
62
|
+
onSize,
|
63
|
+
onLayout: _onLayout,
|
64
|
+
ref,
|
65
|
+
...viewProps
|
66
|
+
}: CanvasProps) => {
|
67
|
+
const onLayout = useOnSizeEvent(onSize, _onLayout);
|
68
|
+
// Native ID
|
69
|
+
const nativeId = useMemo(() => {
|
70
|
+
return SkiaViewNativeId.current++;
|
71
|
+
}, []);
|
78
72
|
|
79
|
-
|
80
|
-
|
73
|
+
// Root
|
74
|
+
const root = useMemo(() => new SkiaSGRoot(Skia, nativeId), [nativeId]);
|
81
75
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
76
|
+
// Render effects
|
77
|
+
useLayoutEffect(() => {
|
78
|
+
root.render(children);
|
79
|
+
}, [children, root]);
|
86
80
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
81
|
+
useEffect(() => {
|
82
|
+
return () => {
|
83
|
+
root.unmount();
|
84
|
+
};
|
85
|
+
}, [root]);
|
92
86
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
}
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
},
|
124
|
-
getNativeId: () => {
|
125
|
-
return nativeId;
|
126
|
-
},
|
127
|
-
}));
|
128
|
-
return (
|
129
|
-
<NativeSkiaPictureView
|
130
|
-
collapsable={false}
|
131
|
-
nativeID={`${nativeId}`}
|
132
|
-
debug={debug}
|
133
|
-
opaque={opaque}
|
134
|
-
onLayout={onLayout}
|
135
|
-
{...viewProps}
|
136
|
-
/>
|
137
|
-
);
|
138
|
-
}
|
139
|
-
);
|
87
|
+
// Component methods
|
88
|
+
useImperativeHandle(
|
89
|
+
ref,
|
90
|
+
() =>
|
91
|
+
({
|
92
|
+
makeImageSnapshot: (rect?: SkRect) => {
|
93
|
+
return SkiaViewApi.makeImageSnapshot(nativeId, rect);
|
94
|
+
},
|
95
|
+
makeImageSnapshotAsync: (rect?: SkRect) => {
|
96
|
+
return SkiaViewApi.makeImageSnapshotAsync(nativeId, rect);
|
97
|
+
},
|
98
|
+
redraw: () => {
|
99
|
+
SkiaViewApi.requestRedraw(nativeId);
|
100
|
+
},
|
101
|
+
getNativeId: () => {
|
102
|
+
return nativeId;
|
103
|
+
},
|
104
|
+
} as CanvasRef)
|
105
|
+
);
|
106
|
+
return (
|
107
|
+
<SkiaPictureViewNativeComponent
|
108
|
+
collapsable={false}
|
109
|
+
nativeID={`${nativeId}`}
|
110
|
+
debug={debug}
|
111
|
+
opaque={opaque}
|
112
|
+
onLayout={onLayout}
|
113
|
+
{...viewProps}
|
114
|
+
/>
|
115
|
+
);
|
116
|
+
};
|
@@ -14,19 +14,19 @@ export const isOnMainThread = () => {
|
|
14
14
|
);
|
15
15
|
};
|
16
16
|
|
17
|
-
export const drawAsPicture = (element: ReactElement, bounds?: SkRect) => {
|
17
|
+
export const drawAsPicture = async (element: ReactElement, bounds?: SkRect) => {
|
18
18
|
const recorder = Skia.PictureRecorder();
|
19
19
|
const canvas = recorder.beginRecording(bounds);
|
20
20
|
const root = new SkiaSGRoot(Skia);
|
21
|
-
root.render(element);
|
21
|
+
await root.render(element);
|
22
22
|
root.drawOnCanvas(canvas);
|
23
23
|
const picture = recorder.finishRecordingAsPicture();
|
24
24
|
root.unmount();
|
25
25
|
return picture;
|
26
26
|
};
|
27
27
|
|
28
|
-
export const drawAsImage = (element: ReactElement, size: SkSize) => {
|
29
|
-
return drawAsImageFromPicture(drawAsPicture(element), size);
|
28
|
+
export const drawAsImage = async (element: ReactElement, size: SkSize) => {
|
29
|
+
return drawAsImageFromPicture(await drawAsPicture(element), size);
|
30
30
|
};
|
31
31
|
|
32
32
|
export const drawAsImageFromPicture = (picture: SkPicture, size: SkSize) => {
|
@@ -39,29 +39,28 @@ describe("Data Loading", () => {
|
|
39
39
|
expect(SkiaRenderer).toBeDefined();
|
40
40
|
});
|
41
41
|
it("Should accept null as an argument", async () => {
|
42
|
-
const { surface, draw } = mountCanvas(<CheckData />);
|
43
|
-
draw();
|
42
|
+
const { surface, draw } = await mountCanvas(<CheckData />);
|
43
|
+
await draw();
|
44
44
|
processResult(surface, "snapshots/font/green.png");
|
45
|
-
await
|
46
|
-
draw();
|
45
|
+
await draw();
|
47
46
|
processResult(surface, "snapshots/font/green.png");
|
48
47
|
});
|
49
48
|
|
50
49
|
it("Should load a font file", async () => {
|
51
|
-
const { surface, draw } = mountCanvas(<CheckFont />);
|
52
|
-
draw();
|
50
|
+
const { surface, draw } = await mountCanvas(<CheckFont />);
|
51
|
+
await draw();
|
53
52
|
processResult(surface, "snapshots/font/red.png");
|
54
53
|
await wait(1500);
|
55
|
-
draw();
|
54
|
+
await draw();
|
56
55
|
processResult(surface, "snapshots/font/green.png");
|
57
56
|
});
|
58
57
|
|
59
58
|
it("Should load an image", async () => {
|
60
|
-
const { surface, draw } = mountCanvas(<CheckImage />);
|
61
|
-
draw();
|
59
|
+
const { surface, draw } = await mountCanvas(<CheckImage />);
|
60
|
+
await draw();
|
62
61
|
processResult(surface, "snapshots/font/red.png");
|
63
62
|
await wait(1500);
|
64
|
-
draw();
|
63
|
+
await draw();
|
65
64
|
processResult(surface, "snapshots/font/green.png");
|
66
65
|
});
|
67
66
|
});
|
@@ -30,9 +30,9 @@ const CheckEmptyCanvas = () => {
|
|
30
30
|
};
|
31
31
|
|
32
32
|
describe("Test introductionary examples from our documentation", () => {
|
33
|
-
it("Should blend colors using multiplication", () => {
|
33
|
+
it("Should blend colors using multiplication", async () => {
|
34
34
|
const r = width * 0.33;
|
35
|
-
const surface = drawOnNode(
|
35
|
+
const surface = await drawOnNode(
|
36
36
|
<Group blendMode="multiply">
|
37
37
|
<Circle cx={r} cy={r} r={r} color="cyan" />
|
38
38
|
<Circle cx={width - r} cy={r} r={r} color="magenta" />
|
@@ -42,9 +42,9 @@ describe("Test introductionary examples from our documentation", () => {
|
|
42
42
|
processResult(surface, "snapshots/drawings/blend-mode-multiply.png");
|
43
43
|
});
|
44
44
|
|
45
|
-
it("Should use a blur image filter", () => {
|
45
|
+
it("Should use a blur image filter", async () => {
|
46
46
|
const r = width * 0.33;
|
47
|
-
const surface = drawOnNode(
|
47
|
+
const surface = await drawOnNode(
|
48
48
|
<Group blendMode="multiply">
|
49
49
|
<Blur blur={30} />
|
50
50
|
<Circle cx={r} cy={r} r={r} color="cyan" />
|
@@ -55,10 +55,10 @@ describe("Test introductionary examples from our documentation", () => {
|
|
55
55
|
processResult(surface, "snapshots/drawings/blur-node.png");
|
56
56
|
});
|
57
57
|
|
58
|
-
it("Should use multiple paint definitions for one drawing command", () => {
|
58
|
+
it("Should use multiple paint definitions for one drawing command", async () => {
|
59
59
|
const r = width / 4;
|
60
60
|
const strokeWidth = 50;
|
61
|
-
const surface = drawOnNode(
|
61
|
+
const surface = await drawOnNode(
|
62
62
|
<>
|
63
63
|
<Circle cx={width / 2} cy={width / 2} r={r} color="red">
|
64
64
|
<Paint color="lightblue" />
|
@@ -70,7 +70,7 @@ describe("Test introductionary examples from our documentation", () => {
|
|
70
70
|
processResult(surface, "snapshots/drawings/multiple-paints.png");
|
71
71
|
});
|
72
72
|
|
73
|
-
it("Should draw DRect", () => {
|
73
|
+
it("Should draw DRect", async () => {
|
74
74
|
const { rrect, rect } = importSkia();
|
75
75
|
const padding = 25 * PIXEL_RATIO;
|
76
76
|
const outer = rrect(rect(0, 0, width, width), padding, padding);
|
@@ -79,18 +79,18 @@ describe("Test introductionary examples from our documentation", () => {
|
|
79
79
|
padding * 2,
|
80
80
|
padding * 2
|
81
81
|
);
|
82
|
-
const surface = drawOnNode(
|
82
|
+
const surface = await drawOnNode(
|
83
83
|
<DiffRect inner={inner} outer={outer} color="lightblue" />
|
84
84
|
);
|
85
85
|
processResult(surface, docPath("shapes/drect.png"));
|
86
86
|
});
|
87
87
|
|
88
88
|
it("should clear the canvas even if it's empty", async () => {
|
89
|
-
const { surface, draw } = mountCanvas(<CheckEmptyCanvas />);
|
90
|
-
draw();
|
89
|
+
const { surface, draw } = await mountCanvas(<CheckEmptyCanvas />);
|
90
|
+
await draw();
|
91
91
|
processResult(surface, "snapshots/green.png");
|
92
92
|
await wait(1000);
|
93
|
-
draw();
|
93
|
+
await draw();
|
94
94
|
processResult(surface, "snapshots/transparent.png");
|
95
95
|
});
|
96
96
|
});
|