@shopify/react-native-skia 0.1.136 → 0.1.139
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -47
- package/android/build.gradle +1 -2
- package/cpp/api/JsiSkApi.h +0 -4
- package/cpp/api/JsiSkFont.h +0 -19
- package/cpp/api/JsiSkMatrix.h +12 -0
- package/cpp/api/JsiSkTypeface.h +1 -29
- package/lib/commonjs/mock/index.js +0 -4
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.js +5 -8
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/components/Group.js +1 -1
- package/lib/commonjs/renderer/components/Group.js.map +1 -1
- package/lib/commonjs/renderer/components/text/Glyphs.js +4 -6
- package/lib/commonjs/renderer/components/text/Glyphs.js.map +1 -1
- package/lib/commonjs/renderer/components/text/Text.js +4 -6
- package/lib/commonjs/renderer/components/text/Text.js.map +1 -1
- package/lib/commonjs/renderer/components/text/TextPath.js +3 -4
- package/lib/commonjs/renderer/components/text/TextPath.js.map +1 -1
- package/lib/commonjs/renderer/processors/Font.js +1 -27
- package/lib/commonjs/renderer/processors/Font.js.map +1 -1
- package/lib/commonjs/renderer/processors/Transform.js +8 -15
- package/lib/commonjs/renderer/processors/Transform.js.map +1 -1
- package/lib/commonjs/skia/core/Data.js +3 -1
- package/lib/commonjs/skia/core/Data.js.map +1 -1
- package/lib/commonjs/skia/core/Image.js +4 -1
- package/lib/commonjs/skia/core/Image.js.map +1 -1
- package/lib/commonjs/skia/core/SVG.js +3 -1
- package/lib/commonjs/skia/core/SVG.js.map +1 -1
- package/lib/commonjs/skia/core/Typeface.js +4 -1
- package/lib/commonjs/skia/core/Typeface.js.map +1 -1
- package/lib/commonjs/skia/core/index.js +0 -26
- package/lib/commonjs/skia/core/index.js.map +1 -1
- package/lib/commonjs/skia/types/Font/Font.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix.js +18 -3
- package/lib/commonjs/skia/types/Matrix.js.map +1 -1
- package/lib/commonjs/skia/types/index.js +0 -13
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkFont.js +0 -6
- package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkMatrix.js +4 -0
- package/lib/commonjs/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkTextBlobFactory.js +1 -1
- package/lib/commonjs/skia/web/JsiSkTextBlobFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +0 -3
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/values/hooks/useComputedValue.js +1 -8
- package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -1
- package/lib/commonjs/views/SkiaView.web.js +67 -57
- package/lib/commonjs/views/SkiaView.web.js.map +1 -1
- package/lib/commonjs/web/LoadSkiaWeb.js +29 -0
- package/lib/commonjs/web/LoadSkiaWeb.js.map +1 -0
- package/lib/commonjs/web/WithSkiaWeb.js +39 -0
- package/lib/commonjs/web/WithSkiaWeb.js.map +1 -0
- package/lib/commonjs/web/index.js +22 -12
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/module/mock/index.js +0 -4
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/Canvas.js +5 -6
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/components/Group.js +1 -1
- package/lib/module/renderer/components/Group.js.map +1 -1
- package/lib/module/renderer/components/text/Glyphs.js +4 -5
- package/lib/module/renderer/components/text/Glyphs.js.map +1 -1
- package/lib/module/renderer/components/text/Text.js +4 -5
- package/lib/module/renderer/components/text/Text.js.map +1 -1
- package/lib/module/renderer/components/text/TextPath.js +3 -3
- package/lib/module/renderer/components/text/TextPath.js.map +1 -1
- package/lib/module/renderer/processors/Font.js +0 -23
- package/lib/module/renderer/processors/Font.js.map +1 -1
- package/lib/module/renderer/processors/Transform.js +8 -15
- package/lib/module/renderer/processors/Transform.js.map +1 -1
- package/lib/module/skia/core/Data.js +3 -1
- package/lib/module/skia/core/Data.js.map +1 -1
- package/lib/module/skia/core/Image.js +2 -1
- package/lib/module/skia/core/Image.js.map +1 -1
- package/lib/module/skia/core/SVG.js +2 -1
- package/lib/module/skia/core/SVG.js.map +1 -1
- package/lib/module/skia/core/Typeface.js +2 -1
- package/lib/module/skia/core/Typeface.js.map +1 -1
- package/lib/module/skia/core/index.js +0 -2
- package/lib/module/skia/core/index.js.map +1 -1
- package/lib/module/skia/types/Font/Font.js.map +1 -1
- package/lib/module/skia/types/Matrix.js +12 -2
- package/lib/module/skia/types/Matrix.js.map +1 -1
- package/lib/module/skia/types/index.js +0 -1
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkFont.js +0 -6
- package/lib/module/skia/web/JsiSkFont.js.map +1 -1
- package/lib/module/skia/web/JsiSkMatrix.js +4 -0
- package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/module/skia/web/JsiSkTextBlobFactory.js +1 -1
- package/lib/module/skia/web/JsiSkTextBlobFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +0 -2
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/values/hooks/useComputedValue.js +0 -4
- package/lib/module/values/hooks/useComputedValue.js.map +1 -1
- package/lib/module/views/SkiaView.web.js +67 -58
- package/lib/module/views/SkiaView.web.js.map +1 -1
- package/lib/module/web/LoadSkiaWeb.js +16 -0
- package/lib/module/web/LoadSkiaWeb.js.map +1 -0
- package/lib/module/web/WithSkiaWeb.js +23 -0
- package/lib/module/web/WithSkiaWeb.js.map +1 -0
- package/lib/module/web/index.js +2 -9
- package/lib/module/web/index.js.map +1 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +1 -3
- package/lib/typescript/src/renderer/DrawingContext.d.ts +1 -2
- package/lib/typescript/src/renderer/processors/Font.d.ts +1 -5
- package/lib/typescript/src/renderer/processors/Transform.d.ts +2 -2
- package/lib/typescript/src/skia/core/index.d.ts +0 -2
- package/lib/typescript/src/skia/types/Font/Font.d.ts +0 -12
- package/lib/typescript/src/skia/types/Matrix.d.ts +6 -2
- package/lib/typescript/src/skia/types/Skia.d.ts +0 -2
- package/lib/typescript/src/skia/types/Typeface/Typeface.d.ts +1 -4
- package/lib/typescript/src/skia/types/index.d.ts +0 -1
- package/lib/typescript/src/skia/web/JsiSkFont.d.ts +1 -2
- package/lib/typescript/src/skia/web/JsiSkMatrix.d.ts +1 -0
- package/lib/typescript/src/values/hooks/useComputedValue.d.ts +0 -1
- package/lib/typescript/src/views/SkiaView.web.d.ts +9 -11
- package/lib/typescript/src/web/LoadSkiaWeb.d.ts +6 -0
- package/lib/typescript/src/web/WithSkiaWeb.d.ts +12 -0
- package/lib/typescript/src/web/index.d.ts +2 -5
- package/package.json +5 -1
- package/scripts/setup-canvaskit.js +74 -0
- package/src/mock/index.ts +0 -4
- package/src/renderer/Canvas.tsx +5 -8
- package/src/renderer/DrawingContext.ts +1 -2
- package/src/renderer/components/Group.tsx +1 -1
- package/src/renderer/components/text/Glyphs.tsx +2 -6
- package/src/renderer/components/text/Text.tsx +2 -3
- package/src/renderer/components/text/TextPath.tsx +2 -3
- package/src/renderer/processors/Font.ts +2 -25
- package/src/renderer/processors/Transform.ts +7 -10
- package/src/skia/core/Data.ts +3 -1
- package/src/skia/core/Image.ts +3 -1
- package/src/skia/core/SVG.ts +3 -1
- package/src/skia/core/Typeface.ts +4 -6
- package/src/skia/core/index.ts +0 -2
- package/src/skia/types/Font/Font.ts +0 -13
- package/src/skia/types/Matrix.ts +19 -3
- package/src/skia/types/Skia.ts +0 -2
- package/src/skia/types/Typeface/Typeface.ts +1 -4
- package/src/skia/types/index.ts +0 -1
- package/src/skia/web/JsiSkFont.ts +0 -9
- package/src/skia/web/JsiSkMatrix.ts +4 -0
- package/src/skia/web/JsiSkTextBlobFactory.ts +1 -1
- package/src/skia/web/JsiSkia.ts +0 -2
- package/src/values/hooks/useComputedValue.ts +0 -5
- package/src/views/SkiaView.web.tsx +55 -70
- package/src/web/LoadSkiaWeb.tsx +24 -0
- package/src/web/WithSkiaWeb.tsx +37 -0
- package/src/web/index.ts +2 -15
- package/cpp/api/JsiSkFontMgr.h +0 -84
- package/cpp/api/JsiSkFontMgrFactory.h +0 -48
- package/lib/commonjs/skia/core/Paint.js +0 -28
- package/lib/commonjs/skia/core/Paint.js.map +0 -1
- package/lib/commonjs/skia/core/Path.js +0 -72
- package/lib/commonjs/skia/core/Path.js.map +0 -1
- package/lib/commonjs/skia/types/FontMgr/FontMgr.js +0 -6
- package/lib/commonjs/skia/types/FontMgr/FontMgr.js.map +0 -1
- package/lib/commonjs/skia/types/FontMgr/FontMgrFactory.js +0 -6
- package/lib/commonjs/skia/types/FontMgr/FontMgrFactory.js.map +0 -1
- package/lib/commonjs/skia/types/FontMgr/index.js +0 -32
- package/lib/commonjs/skia/types/FontMgr/index.js.map +0 -1
- package/lib/commonjs/skia/web/JsiSkFontMgr.js +0 -33
- package/lib/commonjs/skia/web/JsiSkFontMgr.js.map +0 -1
- package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js +0 -25
- package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js.map +0 -1
- package/lib/module/skia/core/Paint.js +0 -17
- package/lib/module/skia/core/Paint.js.map +0 -1
- package/lib/module/skia/core/Path.js +0 -53
- package/lib/module/skia/core/Path.js.map +0 -1
- package/lib/module/skia/types/FontMgr/FontMgr.js +0 -2
- package/lib/module/skia/types/FontMgr/FontMgr.js.map +0 -1
- package/lib/module/skia/types/FontMgr/FontMgrFactory.js +0 -2
- package/lib/module/skia/types/FontMgr/FontMgrFactory.js.map +0 -1
- package/lib/module/skia/types/FontMgr/index.js +0 -3
- package/lib/module/skia/types/FontMgr/index.js.map +0 -1
- package/lib/module/skia/web/JsiSkFontMgr.js +0 -23
- package/lib/module/skia/web/JsiSkFontMgr.js.map +0 -1
- package/lib/module/skia/web/JsiSkFontMgrFactory.js +0 -14
- package/lib/module/skia/web/JsiSkFontMgrFactory.js.map +0 -1
- package/lib/typescript/src/skia/core/Paint.d.ts +0 -6
- package/lib/typescript/src/skia/core/Path.d.ts +0 -21
- package/lib/typescript/src/skia/types/FontMgr/FontMgr.d.ts +0 -18
- package/lib/typescript/src/skia/types/FontMgr/FontMgrFactory.d.ts +0 -4
- package/lib/typescript/src/skia/types/FontMgr/index.d.ts +0 -2
- package/lib/typescript/src/skia/web/JsiSkFontMgr.d.ts +0 -9
- package/lib/typescript/src/skia/web/JsiSkFontMgrFactory.d.ts +0 -8
- package/src/skia/core/Paint.ts +0 -22
- package/src/skia/core/Path.ts +0 -60
- package/src/skia/types/FontMgr/FontMgr.ts +0 -24
- package/src/skia/types/FontMgr/FontMgrFactory.ts +0 -12
- package/src/skia/types/FontMgr/index.ts +0 -2
- package/src/skia/web/JsiSkFontMgr.ts +0 -38
- package/src/skia/web/JsiSkFontMgrFactory.ts +0 -18
@@ -3,10 +3,8 @@ import type { PointerEvent } from "react";
|
|
3
3
|
import type { SkRect } from "../skia/types";
|
4
4
|
import type { SkiaValue } from "../values";
|
5
5
|
import type { DrawMode, SkiaViewProps } from "./types";
|
6
|
-
|
7
|
-
|
8
|
-
height: number;
|
9
|
-
}> {
|
6
|
+
import { TouchType } from "./types";
|
7
|
+
export declare class SkiaView extends React.Component<SkiaViewProps> {
|
10
8
|
constructor(props: SkiaViewProps);
|
11
9
|
private _surface;
|
12
10
|
private _unsubscriptions;
|
@@ -15,10 +13,13 @@ export declare class SkiaView extends React.Component<SkiaViewProps, {
|
|
15
13
|
private _canvasRef;
|
16
14
|
private _mode;
|
17
15
|
private _redrawRequests;
|
18
|
-
private
|
16
|
+
private width;
|
17
|
+
private height;
|
18
|
+
private requestId;
|
19
19
|
private unsubscribeAll;
|
20
20
|
private onLayout;
|
21
21
|
componentDidMount(): void;
|
22
|
+
componentDidUpdate(): void;
|
22
23
|
componentWillUnmount(): void;
|
23
24
|
/**
|
24
25
|
* Creates a snapshot from the canvas in the surface
|
@@ -29,8 +30,8 @@ export declare class SkiaView extends React.Component<SkiaViewProps, {
|
|
29
30
|
/**
|
30
31
|
* Sends a redraw request to the native SkiaView.
|
31
32
|
*/
|
32
|
-
private
|
33
|
-
|
33
|
+
private tick;
|
34
|
+
redraw(): void;
|
34
35
|
/**
|
35
36
|
* Updates the drawing mode for the skia view. This is the same
|
36
37
|
* as declaratively setting the mode property on the SkiaView.
|
@@ -48,9 +49,6 @@ export declare class SkiaView extends React.Component<SkiaViewProps, {
|
|
48
49
|
*/
|
49
50
|
registerValues(_values: SkiaValue<unknown>[]): void;
|
50
51
|
private handleTouchEvent;
|
51
|
-
|
52
|
-
handleTouchMove(evt: PointerEvent): void;
|
53
|
-
handleTouchEnd(evt: PointerEvent): void;
|
54
|
-
handleTouchCancel(evt: PointerEvent): void;
|
52
|
+
createTouchHandler(touchType: TouchType): (evt: PointerEvent) => void;
|
55
53
|
render(): JSX.Element;
|
56
54
|
}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import type { CanvasKit as CanvasKitType, CanvasKitInitOptions } from "canvaskit-wasm";
|
2
|
+
declare global {
|
3
|
+
var CanvasKit: CanvasKitType;
|
4
|
+
}
|
5
|
+
export declare const LoadSkiaWeb: (opts?: CanvasKitInitOptions | undefined) => Promise<void>;
|
6
|
+
export declare const LoadSkia: (opts?: CanvasKitInitOptions | undefined) => Promise<void>;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import type { ComponentProps, ComponentType } from "react";
|
2
|
+
import { Suspense } from "react";
|
3
|
+
import { LoadSkiaWeb } from "./LoadSkiaWeb";
|
4
|
+
interface WithSkiaProps {
|
5
|
+
fallback?: ComponentProps<typeof Suspense>["fallback"];
|
6
|
+
getComponent: () => Promise<{
|
7
|
+
default: ComponentType;
|
8
|
+
}>;
|
9
|
+
opts?: Parameters<typeof LoadSkiaWeb>[0];
|
10
|
+
}
|
11
|
+
export declare const WithSkiaWeb: ({ getComponent, fallback, opts, }: WithSkiaProps) => JSX.Element;
|
12
|
+
export {};
|
package/package.json
CHANGED
@@ -3,8 +3,11 @@
|
|
3
3
|
"publishConfig": {
|
4
4
|
"access": "public"
|
5
5
|
},
|
6
|
+
"bin": {
|
7
|
+
"setup-skia-web": "./scripts/setup-canvaskit.js"
|
8
|
+
},
|
6
9
|
"title": "React Native Skia",
|
7
|
-
"version": "0.1.
|
10
|
+
"version": "0.1.139",
|
8
11
|
"description": "High-performance React Native Graphics using Skia",
|
9
12
|
"main": "lib/module/index.js",
|
10
13
|
"files": [
|
@@ -29,6 +32,7 @@
|
|
29
32
|
"libs/ios/libsvg.xcframework",
|
30
33
|
"react-native-skia.podspec",
|
31
34
|
"scripts/install-npm.js",
|
35
|
+
"scripts/setup-canvaskit.js",
|
32
36
|
"dist/**"
|
33
37
|
],
|
34
38
|
"scripts": {
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
/* eslint-disable max-len */
|
3
|
+
|
4
|
+
/**
|
5
|
+
* A script to automate the setup of `@shopify/react-native-skia` for web.
|
6
|
+
* The only requirement is that your project supports a 'static' folder (often named '/public').
|
7
|
+
* In `@expo/webpack-config` this is `./web` (default for now).
|
8
|
+
*
|
9
|
+
* This script does the following:
|
10
|
+
* 1. Resolve the public path relative to wherever the script is being run.
|
11
|
+
* 2. Log out some useful info about the web setup, just in case anything goes wrong.
|
12
|
+
* 3. Resolve the installed wasm file `canvaskit-wasm/bin/full/canvaskit.wasm`
|
13
|
+
* from `@shopify/react-native-skia -> canvaskit`.
|
14
|
+
* 4. Recursively ensure the path exists and copy the file into the desired location.
|
15
|
+
*
|
16
|
+
*
|
17
|
+
* Usage:
|
18
|
+
* $ `npx <script> web`
|
19
|
+
*
|
20
|
+
* -> Copies the file to `<project>/web/static/js/canvaskit.wasm`
|
21
|
+
*
|
22
|
+
* Tooling that uses `/public`:
|
23
|
+
* $ `npx <script> public`
|
24
|
+
*
|
25
|
+
* -> Copies the file to `<project>/public/static/js/canvaskit.wasm`
|
26
|
+
*/
|
27
|
+
const fs = require("fs");
|
28
|
+
const path = require("path");
|
29
|
+
|
30
|
+
const args = process.argv.slice(2);
|
31
|
+
|
32
|
+
const gray = (text) => `\x1b[90m${text}\x1b[0m`;
|
33
|
+
const lime = (text) => `\x1b[32m${text}\x1b[0m`;
|
34
|
+
|
35
|
+
function getWasmFilePath() {
|
36
|
+
try {
|
37
|
+
return require.resolve("canvaskit-wasm/bin/full/canvaskit.wasm");
|
38
|
+
} catch (error) {
|
39
|
+
console.error(
|
40
|
+
`Could not find 'canvaskit-wasm'. Please install '@shopify/react-native-skia' and ensure it can be resolved from your project: ${process.cwd()}`
|
41
|
+
);
|
42
|
+
process.exit(1);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
function getOutputFilePath() {
|
47
|
+
// Default to using `web` public path.
|
48
|
+
const publicFolder = path.resolve(args[0] || "web");
|
49
|
+
const publicLocation = "./static/js/canvaskit.wasm";
|
50
|
+
const output = path.join(publicFolder, publicLocation);
|
51
|
+
|
52
|
+
console.log(
|
53
|
+
`› Copying 'canvaskit.wasm' file to static folder:\n ${gray(output)}\n`
|
54
|
+
);
|
55
|
+
return output;
|
56
|
+
}
|
57
|
+
|
58
|
+
function copyFile(from, to) {
|
59
|
+
const data = fs.readFileSync(from);
|
60
|
+
fs.mkdirSync(path.dirname(to), { recursive: true });
|
61
|
+
fs.writeFileSync(to, data);
|
62
|
+
}
|
63
|
+
|
64
|
+
// Copy the WASM file to `<static>/static/js/canvaskit.wasm`
|
65
|
+
(() => {
|
66
|
+
copyFile(getWasmFilePath(), getOutputFilePath());
|
67
|
+
|
68
|
+
console.log(lime("› Success! You are almost there:"));
|
69
|
+
console.log(
|
70
|
+
gray(
|
71
|
+
"› To load React Native Skia Web, follow these instructions : https://shopify.github.io/react-native-skia/docs/getting-started/web"
|
72
|
+
)
|
73
|
+
);
|
74
|
+
})();
|
package/src/mock/index.ts
CHANGED
@@ -52,12 +52,8 @@ export const Mock: typeof SkiaExports &
|
|
52
52
|
useFont: Noop,
|
53
53
|
useTypeface: Noop,
|
54
54
|
useImage: Noop,
|
55
|
-
usePath: Noop,
|
56
55
|
useSVG: Noop,
|
57
|
-
useTextPath: Noop,
|
58
|
-
usePaint: Noop,
|
59
56
|
usePicture: Noop,
|
60
|
-
useSvgPath: Noop,
|
61
57
|
// 3. Point/Rect/Transform utilities
|
62
58
|
vec,
|
63
59
|
rect: (x: number, y: number, width: number, height: number) => ({
|
package/src/renderer/Canvas.tsx
CHANGED
@@ -18,7 +18,6 @@ import ReactReconciler from "react-reconciler";
|
|
18
18
|
|
19
19
|
import { SkiaView, useDrawCallback } from "../views";
|
20
20
|
import type { TouchHandler } from "../views";
|
21
|
-
import type { SkFontMgr } from "../skia/types";
|
22
21
|
import { useValue } from "../values/hooks/useValue";
|
23
22
|
import { Skia } from "../skia/Skia";
|
24
23
|
|
@@ -50,13 +49,10 @@ export interface CanvasProps extends ComponentProps<typeof SkiaView> {
|
|
50
49
|
ref?: RefObject<SkiaView>;
|
51
50
|
children: ReactNode;
|
52
51
|
onTouch?: TouchHandler;
|
53
|
-
fontMgr?: SkFontMgr;
|
54
52
|
}
|
55
53
|
|
56
|
-
const defaultFontMgr = Skia.FontMgr.RefDefault();
|
57
|
-
|
58
54
|
export const Canvas = forwardRef<SkiaView, CanvasProps>(
|
59
|
-
({ children, style, debug, mode, onTouch
|
55
|
+
({ children, style, debug, mode, onTouch }, forwardedRef) => {
|
60
56
|
const size = useValue({ width: 0, height: 0 });
|
61
57
|
const canvasCtx = useMemo(() => ({ Skia, size }), [size]);
|
62
58
|
const innerRef = useCanvasRef();
|
@@ -106,7 +102,6 @@ export const Canvas = forwardRef<SkiaView, CanvasProps>(
|
|
106
102
|
opacity: 1,
|
107
103
|
ref,
|
108
104
|
center: Skia.Point(width / 2, height / 2),
|
109
|
-
fontMgr: fontMgr ?? defaultFontMgr,
|
110
105
|
Skia,
|
111
106
|
};
|
112
107
|
container.draw(ctx);
|
@@ -116,9 +111,11 @@ export const Canvas = forwardRef<SkiaView, CanvasProps>(
|
|
116
111
|
|
117
112
|
useEffect(() => {
|
118
113
|
return () => {
|
119
|
-
|
114
|
+
skiaReconciler.updateContainer(null, root, null, () => {
|
115
|
+
container.depMgr.unsubscribe();
|
116
|
+
});
|
120
117
|
};
|
121
|
-
}, [container]);
|
118
|
+
}, [container, root]);
|
122
119
|
|
123
120
|
return (
|
124
121
|
<SkiaView
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { RefObject } from "react";
|
2
2
|
|
3
3
|
import type { DrawingInfo, SkiaView } from "../views";
|
4
|
-
import type {
|
4
|
+
import type { SkCanvas, SkPaint, Skia, Vector } from "../skia/types";
|
5
5
|
|
6
6
|
export interface DrawingContext extends Omit<DrawingInfo, "touches"> {
|
7
7
|
canvas: SkCanvas;
|
@@ -9,6 +9,5 @@ export interface DrawingContext extends Omit<DrawingInfo, "touches"> {
|
|
9
9
|
opacity: number;
|
10
10
|
center: Vector;
|
11
11
|
ref: RefObject<SkiaView>;
|
12
|
-
fontMgr: SkFontMgr;
|
13
12
|
Skia: Skia;
|
14
13
|
}
|
@@ -58,7 +58,7 @@ const onDraw = createDrawing<GroupProps>(
|
|
58
58
|
} else {
|
59
59
|
canvas.save();
|
60
60
|
}
|
61
|
-
processCanvasTransform(
|
61
|
+
processCanvasTransform(canvas, groupProps);
|
62
62
|
if (clip) {
|
63
63
|
const op = invertClip ? ClipOp.Difference : ClipOp.Intersect;
|
64
64
|
processClip(Skia, canvas, clip, op);
|
@@ -4,7 +4,6 @@ import type { CustomPaintProps, AnimatedProps } from "../../processors";
|
|
4
4
|
import { createDrawing } from "../../nodes/Drawing";
|
5
5
|
import type { SkPoint } from "../../../skia/types";
|
6
6
|
import type { FontDef } from "../../processors/Font";
|
7
|
-
import { processFont } from "../../processors/Font";
|
8
7
|
|
9
8
|
export interface Glyph {
|
10
9
|
id: number;
|
@@ -24,11 +23,8 @@ interface ProcessedGlyphs {
|
|
24
23
|
}
|
25
24
|
|
26
25
|
const onDraw = createDrawing<GlyphsProps>(
|
27
|
-
(
|
28
|
-
{
|
29
|
-
{ glyphs: rawGlyphs, x, y, ...fontDef }
|
30
|
-
) => {
|
31
|
-
const font = processFont(Skia, fontMgr, fontDef);
|
26
|
+
({ canvas, paint }, { glyphs: rawGlyphs, x, y, ...fontDef }) => {
|
27
|
+
const { font } = fontDef;
|
32
28
|
const { glyphs, positions } = rawGlyphs.reduce<ProcessedGlyphs>(
|
33
29
|
(acc, glyph) => {
|
34
30
|
const { id, pos } = glyph;
|
@@ -6,7 +6,6 @@ import type {
|
|
6
6
|
FontDef,
|
7
7
|
} from "../../processors";
|
8
8
|
import { createDrawing } from "../../nodes/Drawing";
|
9
|
-
import { processFont } from "../../processors";
|
10
9
|
|
11
10
|
type TextProps = CustomPaintProps &
|
12
11
|
FontDef & {
|
@@ -16,8 +15,8 @@ type TextProps = CustomPaintProps &
|
|
16
15
|
};
|
17
16
|
|
18
17
|
const onDraw = createDrawing<TextProps>(
|
19
|
-
({ canvas, paint
|
20
|
-
const font =
|
18
|
+
({ canvas, paint }, { text, x, y, ...fontDef }) => {
|
19
|
+
const { font } = fontDef;
|
21
20
|
canvas.drawText(text, x, y, paint, font);
|
22
21
|
}
|
23
22
|
);
|
@@ -4,7 +4,6 @@ import type { CustomPaintProps, AnimatedProps } from "../../processors";
|
|
4
4
|
import { createDrawing } from "../../nodes";
|
5
5
|
import type { SkPath, SkRSXform } from "../../../skia/types";
|
6
6
|
import type { FontDef } from "../../processors/Font";
|
7
|
-
import { processFont } from "../../processors/Font";
|
8
7
|
|
9
8
|
export type TextPathProps = CustomPaintProps &
|
10
9
|
FontDef & {
|
@@ -15,7 +14,7 @@ export type TextPathProps = CustomPaintProps &
|
|
15
14
|
|
16
15
|
const onDraw = createDrawing<TextPathProps>(
|
17
16
|
(
|
18
|
-
{ canvas, paint,
|
17
|
+
{ canvas, paint, Skia },
|
19
18
|
{ text, initialOffset, path: pathDef, ...fontDef }
|
20
19
|
) => {
|
21
20
|
const path =
|
@@ -25,7 +24,7 @@ const onDraw = createDrawing<TextPathProps>(
|
|
25
24
|
if (path === null) {
|
26
25
|
throw new Error("Invalid path: " + pathDef);
|
27
26
|
}
|
28
|
-
const font =
|
27
|
+
const { font } = fontDef;
|
29
28
|
const ids = font.getGlyphIDs(text);
|
30
29
|
const widths = font.getGlyphWidths(ids, paint);
|
31
30
|
const rsx: SkRSXform[] = [];
|
@@ -1,31 +1,8 @@
|
|
1
|
-
import type {
|
1
|
+
import type { SkFont } from "../../skia/types";
|
2
2
|
|
3
|
-
export type FontDef = { font: SkFont }
|
3
|
+
export type FontDef = { font: SkFont };
|
4
4
|
|
5
5
|
export const isFont = (fontDef: FontDef): fontDef is { font: SkFont } =>
|
6
6
|
// We have an issue to check property existence on JSI backed instances
|
7
7
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8
8
|
(fontDef as any).font !== undefined;
|
9
|
-
|
10
|
-
export const processFont = (
|
11
|
-
Skia: Skia,
|
12
|
-
fontMgr: SkFontMgr,
|
13
|
-
fontDef: FontDef
|
14
|
-
) => {
|
15
|
-
let selectedFont: SkFont;
|
16
|
-
if (isFont(fontDef)) {
|
17
|
-
selectedFont = fontDef.font;
|
18
|
-
} else {
|
19
|
-
console.warn(
|
20
|
-
// eslint-disable-next-line max-len
|
21
|
-
"Using system fonts is deprecated. Please use the font property instead: https://shopify.github.io/react-native-skia/docs/text/fonts"
|
22
|
-
);
|
23
|
-
const { familyName, size } = fontDef;
|
24
|
-
const typeface = fontMgr.matchFamilyStyle(familyName);
|
25
|
-
if (typeface === null) {
|
26
|
-
throw new Error(`No typeface found for ${familyName}`);
|
27
|
-
}
|
28
|
-
selectedFont = Skia.Font(typeface, size);
|
29
|
-
}
|
30
|
-
return selectedFont;
|
31
|
-
};
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import type { DrawingContext } from "../DrawingContext";
|
2
1
|
import type { SkMatrix, Vector, Transforms2d } from "../../skia/types";
|
3
2
|
import { processTransform } from "../../skia/types";
|
3
|
+
import type { SkCanvas } from "../../skia/types/Canvas";
|
4
4
|
|
5
5
|
export interface TransformProps {
|
6
6
|
transform?: Transforms2d;
|
@@ -9,25 +9,22 @@ export interface TransformProps {
|
|
9
9
|
}
|
10
10
|
|
11
11
|
export const processCanvasTransform = (
|
12
|
-
|
12
|
+
canvas: SkCanvas,
|
13
13
|
{ transform, origin, matrix }: TransformProps
|
14
14
|
) => {
|
15
15
|
if (matrix) {
|
16
16
|
if (origin) {
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
m3.translate(-origin.x, -origin.y);
|
21
|
-
canvas.concat(m3);
|
17
|
+
canvas.translate(origin.x, origin.y);
|
18
|
+
canvas.concat(matrix);
|
19
|
+
canvas.translate(-origin.x, -origin.y);
|
22
20
|
} else {
|
23
21
|
canvas.concat(matrix);
|
24
22
|
}
|
25
23
|
} else if (transform) {
|
26
|
-
|
27
|
-
|
24
|
+
processTransform(
|
25
|
+
canvas,
|
28
26
|
origin ? transformOrigin(origin, transform) : transform
|
29
27
|
);
|
30
|
-
canvas.concat(m3);
|
31
28
|
}
|
32
29
|
};
|
33
30
|
|
package/src/skia/core/Data.ts
CHANGED
@@ -37,7 +37,9 @@ const loadData = <T>(
|
|
37
37
|
factory: (data: SkData) => T,
|
38
38
|
onError?: (err: Error) => void
|
39
39
|
): Promise<T | null> => {
|
40
|
-
if (source
|
40
|
+
if (source === null) {
|
41
|
+
return new Promise((resolve) => resolve(null));
|
42
|
+
} else if (source instanceof Uint8Array) {
|
41
43
|
return new Promise((resolve) =>
|
42
44
|
resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))
|
43
45
|
);
|
package/src/skia/core/Image.ts
CHANGED
@@ -3,10 +3,12 @@ import type { DataSource } from "../types";
|
|
3
3
|
|
4
4
|
import { useRawData } from "./Data";
|
5
5
|
|
6
|
+
const imgFactory = Skia.Image.MakeImageFromEncoded.bind(Skia.Image);
|
7
|
+
|
6
8
|
/**
|
7
9
|
* Returns a Skia Image object
|
8
10
|
* */
|
9
11
|
export const useImage = (
|
10
12
|
source: DataSource | null | undefined,
|
11
13
|
onError?: (err: Error) => void
|
12
|
-
) => useRawData(source,
|
14
|
+
) => useRawData(source, imgFactory, onError);
|
package/src/skia/core/SVG.ts
CHANGED
@@ -3,7 +3,9 @@ import type { DataSource } from "../types";
|
|
3
3
|
|
4
4
|
import { useRawData } from "./Data";
|
5
5
|
|
6
|
+
const svgFactory = Skia.SVG.MakeFromData.bind(Skia.SVG);
|
7
|
+
|
6
8
|
export const useSVG = (
|
7
9
|
source: DataSource | null | undefined,
|
8
10
|
onError?: (err: Error) => void
|
9
|
-
) => useRawData(source,
|
11
|
+
) => useRawData(source, svgFactory, onError);
|
@@ -2,15 +2,13 @@ import { Skia } from "../Skia";
|
|
2
2
|
import type { DataSource } from "../types";
|
3
3
|
|
4
4
|
import { useRawData } from "./Data";
|
5
|
+
|
6
|
+
const tfFactory = Skia.Typeface.MakeFreeTypeFaceFromData.bind(Skia.Typeface);
|
7
|
+
|
5
8
|
/**
|
6
9
|
* Returns a Skia Typeface object
|
7
10
|
* */
|
8
11
|
export const useTypeface = (
|
9
12
|
source: DataSource | null | undefined,
|
10
13
|
onError?: (err: Error) => void
|
11
|
-
) =>
|
12
|
-
useRawData(
|
13
|
-
source,
|
14
|
-
Skia.Typeface.MakeFreeTypeFaceFromData.bind(Skia.Typeface),
|
15
|
-
onError
|
16
|
-
);
|
14
|
+
) => useRawData(source, tfFactory, onError);
|
package/src/skia/core/index.ts
CHANGED
@@ -4,9 +4,7 @@ export * from "./Typeface";
|
|
4
4
|
export * from "./Image";
|
5
5
|
export * from "./Picture";
|
6
6
|
export * from "./SVG";
|
7
|
-
export * from "./Path";
|
8
7
|
export * from "./Vector";
|
9
8
|
export * from "./Rect";
|
10
9
|
export * from "./RRect";
|
11
10
|
export * from "./Matrix";
|
12
|
-
export * from "./Paint";
|
@@ -28,19 +28,6 @@ export interface SkFont extends SkJSIInstance<"Font"> {
|
|
28
28
|
*/
|
29
29
|
getGlyphWidths(glyphs: number[], paint?: SkPaint): number[];
|
30
30
|
|
31
|
-
/** Returns the advance width of text.
|
32
|
-
The advance is the normal distance to move before drawing additional text.
|
33
|
-
Returns the bounding box of text if bounds is not nullptr. The paint
|
34
|
-
stroke settings, mask filter, or path effect may modify the bounds.
|
35
|
-
|
36
|
-
@param text character storage encoded with SkTextEncoding
|
37
|
-
@param byteLength length of character storage in bytes
|
38
|
-
@param bounds returns bounding box relative to (0, 0) if not nullptr
|
39
|
-
@param paint optional; may be nullptr
|
40
|
-
@return number of glyphs represented by text of length byteLength
|
41
|
-
*/
|
42
|
-
measureText: (text: string, paint?: SkPaint) => SkRect;
|
43
|
-
|
44
31
|
/**
|
45
32
|
* Returns the FontMetrics for this font.
|
46
33
|
*/
|
package/src/skia/types/Matrix.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { SkJSIInstance } from "./JsiInstance";
|
2
|
+
import type { SkCanvas } from "./Canvas";
|
2
3
|
export enum MatrixIndex {
|
3
4
|
ScaleX = 0,
|
4
5
|
SkewX = 1,
|
@@ -8,15 +9,19 @@ export enum MatrixIndex {
|
|
8
9
|
TransY = 5,
|
9
10
|
Persp0 = 6,
|
10
11
|
Persp1 = 7,
|
11
|
-
|
12
|
+
Persp2 = 8,
|
12
13
|
}
|
13
14
|
|
15
|
+
export const isMatrix = (obj: unknown): obj is SkMatrix =>
|
16
|
+
obj !== null && (obj as SkJSIInstance<string>).__typename__ === "Matrix";
|
17
|
+
|
14
18
|
export interface SkMatrix extends SkJSIInstance<"Matrix"> {
|
15
19
|
concat: (matrix: SkMatrix) => void;
|
16
20
|
translate: (x: number, y: number) => void;
|
17
21
|
scale: (x: number, y?: number) => void;
|
18
22
|
skew: (x: number, y: number) => void;
|
19
23
|
rotate: (theta: number) => void;
|
24
|
+
identity: () => void;
|
20
25
|
}
|
21
26
|
|
22
27
|
type Transform2dName =
|
@@ -49,7 +54,10 @@ export interface TransformProp {
|
|
49
54
|
transform?: Transforms2d;
|
50
55
|
}
|
51
56
|
|
52
|
-
export const processTransform =
|
57
|
+
export const processTransform = <T extends SkMatrix | SkCanvas>(
|
58
|
+
m: T,
|
59
|
+
transforms: Transforms2d
|
60
|
+
) => {
|
53
61
|
for (const transform of transforms) {
|
54
62
|
const key = Object.keys(transform)[0] as Transform2dName;
|
55
63
|
const value = (transform as Pick<Transformations, typeof key>)[key];
|
@@ -82,7 +90,11 @@ export const processTransform = (m: SkMatrix, transforms: Transforms2d) => {
|
|
82
90
|
continue;
|
83
91
|
}
|
84
92
|
if (key === "rotate" || key === "rotateZ") {
|
85
|
-
m
|
93
|
+
if (isMatrix(m)) {
|
94
|
+
m.rotate(value);
|
95
|
+
} else {
|
96
|
+
m.rotate(toDegrees(value), 0, 0);
|
97
|
+
}
|
86
98
|
continue;
|
87
99
|
}
|
88
100
|
exhaustiveCheck(key);
|
@@ -93,3 +105,7 @@ export const processTransform = (m: SkMatrix, transforms: Transforms2d) => {
|
|
93
105
|
const exhaustiveCheck = (a: never): never => {
|
94
106
|
throw new Error(`Unknown transformation: ${a}`);
|
95
107
|
};
|
108
|
+
|
109
|
+
export const toDegrees = (rad: number) => {
|
110
|
+
return (rad * 180) / Math.PI;
|
111
|
+
};
|
package/src/skia/types/Skia.ts
CHANGED
@@ -21,7 +21,6 @@ import type { SkVertices, VertexMode } from "./Vertices/Vertices";
|
|
21
21
|
import type { DataFactory } from "./Data";
|
22
22
|
import type { SVGFactory } from "./SVG";
|
23
23
|
import type { TextBlobFactory } from "./TextBlob";
|
24
|
-
import type { FontMgrFactory } from "./FontMgr/FontMgrFactory";
|
25
24
|
import type { SurfaceFactory } from "./Surface";
|
26
25
|
import type { SkRSXform } from "./RSXform";
|
27
26
|
import type { SkPath } from "./Path/Path";
|
@@ -78,7 +77,6 @@ export interface Skia {
|
|
78
77
|
Data: DataFactory;
|
79
78
|
Image: ImageFactory;
|
80
79
|
SVG: SVGFactory;
|
81
|
-
FontMgr: FontMgrFactory;
|
82
80
|
TextBlob: TextBlobFactory;
|
83
81
|
Surface: SurfaceFactory;
|
84
82
|
}
|
package/src/skia/types/index.ts
CHANGED
@@ -6,7 +6,6 @@ import type {
|
|
6
6
|
SkFont,
|
7
7
|
SkPaint,
|
8
8
|
SkPoint,
|
9
|
-
SkRect,
|
10
9
|
SkTypeface,
|
11
10
|
} from "../types";
|
12
11
|
|
@@ -19,14 +18,6 @@ export class JsiSkFont extends HostObject<Font, "Font"> implements SkFont {
|
|
19
18
|
super(CanvasKit, ref, "Font");
|
20
19
|
}
|
21
20
|
|
22
|
-
measureText(_text: string, _paint?: SkPaint): SkRect {
|
23
|
-
console.warn(
|
24
|
-
`measureText() is deprecated an returns an empty rectangle on React Native Web.
|
25
|
-
Clients should use "Font.getGlyphWidths" instead (the latter does no shaping)`
|
26
|
-
);
|
27
|
-
return new JsiSkRect(this.CanvasKit, this.CanvasKit.XYWHRect(0, 0, 0, 0));
|
28
|
-
}
|
29
|
-
|
30
21
|
getTextWidth(text: string, paint?: SkPaint | undefined) {
|
31
22
|
const ids = this.getGlyphIDs(text);
|
32
23
|
const widths = this.getGlyphWidths(ids, paint);
|
@@ -30,7 +30,7 @@ export class JsiSkTextBlobFactory extends Host implements TextBlobFactory {
|
|
30
30
|
this.CanvasKit,
|
31
31
|
this.CanvasKit.TextBlob.MakeFromRSXform(
|
32
32
|
str,
|
33
|
-
rsxforms.map((f) => toValue(f)),
|
33
|
+
rsxforms.map((f) => Array.from(toValue<Float32Array>(f))).flat(),
|
34
34
|
toValue(font)
|
35
35
|
)
|
36
36
|
);
|
package/src/skia/web/JsiSkia.ts
CHANGED
@@ -34,7 +34,6 @@ import { JsiSkDataFactory } from "./JsiSkDataFactory";
|
|
34
34
|
import { JsiSkImageFactory } from "./JsiSkImageFactory";
|
35
35
|
import { JsiSkSVGFactory } from "./JsiSkSVGFactory";
|
36
36
|
import { JsiSkTextBlobFactory } from "./JsiSkTextBlobFactory";
|
37
|
-
import { JsiSkFontMgrFactory } from "./JsiSkFontMgrFactory";
|
38
37
|
import { JsiSkFont } from "./JsiSkFont";
|
39
38
|
import { MakeVertices } from "./JsiSkVerticesFactory";
|
40
39
|
|
@@ -90,7 +89,6 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
|
|
90
89
|
Image: new JsiSkImageFactory(CanvasKit),
|
91
90
|
SVG: new JsiSkSVGFactory(CanvasKit),
|
92
91
|
TextBlob: new JsiSkTextBlobFactory(CanvasKit),
|
93
|
-
FontMgr: new JsiSkFontMgrFactory(CanvasKit),
|
94
92
|
XYWHRect: (x: number, y: number, width: number, height: number) => {
|
95
93
|
return new JsiSkRect(CanvasKit, CanvasKit.XYWHRect(x, y, width, height));
|
96
94
|
},
|
@@ -16,8 +16,3 @@ export const useComputedValue = <R>(cb: () => R, values: unknown[]) =>
|
|
16
16
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
17
17
|
values
|
18
18
|
);
|
19
|
-
|
20
|
-
export const useDerivedValue = <R>(cb: () => R, values: unknown[]) => {
|
21
|
-
console.warn("useDerivedValue is deprecated. Use useComputedValue instead.");
|
22
|
-
return useComputedValue(cb, values);
|
23
|
-
};
|