@shopify/react-native-skia 0.1.157 → 0.1.158
Sign up to get free protection for your applications and to get access to all the features.
- package/android/build.gradle +10 -5
- package/cpp/api/JsiSkContourMeasure.h +7 -5
- package/lib/commonjs/dom/nodes/DrawingNode.js +1 -5
- package/lib/commonjs/dom/nodes/DrawingNode.js.map +1 -1
- package/lib/commonjs/dom/nodes/RenderNode.js +2 -8
- package/lib/commonjs/dom/nodes/RenderNode.js.map +1 -1
- package/lib/commonjs/dom/nodes/drawings/Text.js +4 -9
- package/lib/commonjs/dom/nodes/drawings/Text.js.map +1 -1
- package/lib/commonjs/dom/types/Common.js.map +1 -1
- package/lib/commonjs/dom/types/Drawings.js.map +1 -1
- package/lib/commonjs/mock/index.js +0 -1
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.js +9 -1
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/HostComponents.js.map +1 -1
- package/lib/commonjs/renderer/components/Mask.js +1 -3
- package/lib/commonjs/renderer/components/Mask.js.map +1 -1
- package/lib/commonjs/renderer/components/Paint.js +5 -18
- package/lib/commonjs/renderer/components/Paint.js.map +1 -1
- package/lib/commonjs/renderer/useCanvas.js +18 -2
- package/lib/commonjs/renderer/useCanvas.js.map +1 -1
- package/lib/commonjs/skia/core/Picture.js +1 -24
- package/lib/commonjs/skia/core/Picture.js.map +1 -1
- package/lib/commonjs/skia/core/Rect.js +1 -1
- package/lib/commonjs/skia/core/Rect.js.map +1 -1
- package/lib/commonjs/skia/types/ContourMeasure.js.map +1 -1
- package/lib/commonjs/skia/types/Size.js +2 -0
- package/lib/commonjs/skia/types/Size.js.map +1 -0
- package/lib/commonjs/skia/types/index.js +13 -0
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkColor.js +8 -0
- package/lib/commonjs/skia/web/JsiSkColor.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkContourMeasure.js +4 -7
- package/lib/commonjs/skia/web/JsiSkContourMeasure.js.map +1 -1
- package/lib/commonjs/values/web/RNSkReadonlyValue.js +4 -2
- package/lib/commonjs/values/web/RNSkReadonlyValue.js.map +1 -1
- package/lib/commonjs/views/SkiaBaseWebView.js +2 -2
- package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
- package/lib/module/dom/nodes/DrawingNode.js +2 -6
- package/lib/module/dom/nodes/DrawingNode.js.map +1 -1
- package/lib/module/dom/nodes/RenderNode.js +1 -4
- package/lib/module/dom/nodes/RenderNode.js.map +1 -1
- package/lib/module/dom/nodes/drawings/Text.js +4 -9
- package/lib/module/dom/nodes/drawings/Text.js.map +1 -1
- package/lib/module/dom/types/Common.js.map +1 -1
- package/lib/module/dom/types/Drawings.js.map +1 -1
- package/lib/module/mock/index.js +0 -1
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/Canvas.js +9 -1
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/HostComponents.js.map +1 -1
- package/lib/module/renderer/components/Mask.js +2 -4
- package/lib/module/renderer/components/Mask.js.map +1 -1
- package/lib/module/renderer/components/Paint.js +3 -14
- package/lib/module/renderer/components/Paint.js.map +1 -1
- package/lib/module/renderer/useCanvas.js +13 -0
- package/lib/module/renderer/useCanvas.js.map +1 -1
- package/lib/module/skia/core/Picture.js +0 -18
- package/lib/module/skia/core/Picture.js.map +1 -1
- package/lib/module/skia/core/Rect.js +1 -1
- package/lib/module/skia/core/Rect.js.map +1 -1
- package/lib/module/skia/types/ContourMeasure.js.map +1 -1
- package/lib/module/skia/types/Size.js +2 -0
- package/lib/module/skia/types/Size.js.map +1 -0
- package/lib/module/skia/types/index.js +1 -0
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkColor.js +8 -0
- package/lib/module/skia/web/JsiSkColor.js.map +1 -1
- package/lib/module/skia/web/JsiSkContourMeasure.js +3 -7
- package/lib/module/skia/web/JsiSkContourMeasure.js.map +1 -1
- package/lib/module/values/web/RNSkReadonlyValue.js +4 -2
- package/lib/module/values/web/RNSkReadonlyValue.js.map +1 -1
- package/lib/module/views/SkiaBaseWebView.js +2 -2
- package/lib/module/views/SkiaBaseWebView.js.map +1 -1
- package/lib/typescript/src/dom/nodes/RenderNode.d.ts +1 -3
- package/lib/typescript/src/dom/types/Common.d.ts +2 -3
- package/lib/typescript/src/dom/types/Drawings.d.ts +1 -3
- package/lib/typescript/src/renderer/Canvas.d.ts +4 -1
- package/lib/typescript/src/renderer/HostComponents.d.ts +1 -5
- package/lib/typescript/src/renderer/components/Paint.d.ts +3 -4
- package/lib/typescript/src/renderer/useCanvas.d.ts +1 -0
- package/lib/typescript/src/skia/core/Picture.d.ts +0 -8
- package/lib/typescript/src/skia/types/ContourMeasure.d.ts +3 -2
- package/lib/typescript/src/skia/types/Size.d.ts +4 -0
- package/lib/typescript/src/skia/types/index.d.ts +1 -0
- package/lib/typescript/src/skia/web/JsiSkContourMeasure.d.ts +2 -6
- package/package.json +2 -2
- package/src/dom/nodes/DrawingNode.ts +2 -4
- package/src/dom/nodes/RenderNode.ts +1 -13
- package/src/dom/nodes/drawings/Text.ts +4 -4
- package/src/dom/types/Common.ts +2 -4
- package/src/dom/types/Drawings.ts +1 -4
- package/src/mock/index.ts +0 -1
- package/src/renderer/Canvas.tsx +7 -2
- package/src/renderer/HostComponents.ts +1 -4
- package/src/renderer/components/Mask.tsx +2 -2
- package/src/renderer/components/Paint.tsx +3 -14
- package/src/renderer/useCanvas.ts +14 -0
- package/src/skia/core/Picture.ts +0 -24
- package/src/skia/core/Rect.ts +1 -1
- package/src/skia/types/ContourMeasure.tsx +3 -2
- package/src/skia/types/Size.ts +4 -0
- package/src/skia/types/index.ts +1 -0
- package/src/skia/web/JsiSkColor.ts +11 -0
- package/src/skia/web/JsiSkContourMeasure.ts +7 -3
- package/src/values/web/RNSkReadonlyValue.ts +4 -2
- package/src/views/SkiaBaseWebView.tsx +2 -2
@@ -57,10 +57,10 @@ export class TextPathNode extends JsiDrawingNode<TextPathProps, SkTextBlob> {
|
|
57
57
|
}
|
58
58
|
// Gives us the (x, y) coordinates as well as the cos/sin of the tangent
|
59
59
|
// line at that position.
|
60
|
-
const
|
61
|
-
const adjustedX =
|
62
|
-
const adjustedY =
|
63
|
-
rsx.push(this.Skia.RSXform(
|
60
|
+
const [p, t] = cont.getPosTan(dist);
|
61
|
+
const adjustedX = p.x - (width / 2) * t.x;
|
62
|
+
const adjustedY = p.y - (width / 2) * t.y;
|
63
|
+
rsx.push(this.Skia.RSXform(t.x, t.y, adjustedX, adjustedY));
|
64
64
|
dist += width / 2;
|
65
65
|
}
|
66
66
|
return this.Skia.TextBlob.MakeFromRSXform(text, rsx, font);
|
package/src/dom/types/Common.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { ReactNode
|
1
|
+
import type { ReactNode } from "react";
|
2
2
|
|
3
3
|
import type {
|
4
4
|
BlendMode,
|
@@ -15,8 +15,6 @@ import type {
|
|
15
15
|
Vector,
|
16
16
|
} from "../../skia/types";
|
17
17
|
|
18
|
-
import type { DeclarationNode } from "./Node";
|
19
|
-
|
20
18
|
export type SkEnum<T> = Uncapitalize<keyof T extends string ? keyof T : never>;
|
21
19
|
|
22
20
|
export type PathDef = string | SkPath;
|
@@ -86,5 +84,5 @@ export interface PaintProps extends ChildrenProps {
|
|
86
84
|
export interface GroupProps extends PaintProps, TransformProps {
|
87
85
|
clip?: ClipDef;
|
88
86
|
invertClip?: boolean;
|
89
|
-
layer?:
|
87
|
+
layer?: SkPaint | boolean;
|
90
88
|
}
|
@@ -1,5 +1,3 @@
|
|
1
|
-
import type { RefObject } from "react";
|
2
|
-
|
3
1
|
import type {
|
4
2
|
FillType,
|
5
3
|
SkImage,
|
@@ -29,10 +27,9 @@ import type {
|
|
29
27
|
SkEnum,
|
30
28
|
} from "./Common";
|
31
29
|
import type { DrawingContext } from "./DrawingContext";
|
32
|
-
import type { DeclarationNode } from "./Node";
|
33
30
|
|
34
31
|
export interface DrawingNodeProps extends GroupProps {
|
35
|
-
paint?: SkPaint
|
32
|
+
paint?: SkPaint;
|
36
33
|
}
|
37
34
|
|
38
35
|
export type ImageProps = DrawingNodeProps &
|
package/src/mock/index.ts
CHANGED
package/src/renderer/Canvas.tsx
CHANGED
@@ -20,7 +20,8 @@ import { SkiaView, useDrawCallback } from "../views";
|
|
20
20
|
import type { TouchHandler } from "../views";
|
21
21
|
import { useValue } from "../values/hooks/useValue";
|
22
22
|
import { Skia } from "../skia/Skia";
|
23
|
-
import type { SkiaValue } from "../values";
|
23
|
+
import type { SkiaValue, SkiaMutableValue } from "../values";
|
24
|
+
import type { SkSize } from "../skia/types";
|
24
25
|
|
25
26
|
import { debug as hostDebug, skHostConfig } from "./HostConfig";
|
26
27
|
// import { debugTree } from "./nodes";
|
@@ -49,10 +50,11 @@ export interface CanvasProps extends ComponentProps<typeof SkiaView> {
|
|
49
50
|
ref?: RefObject<SkiaView>;
|
50
51
|
children: ReactNode;
|
51
52
|
onTouch?: TouchHandler;
|
53
|
+
onSize?: SkiaMutableValue<SkSize>;
|
52
54
|
}
|
53
55
|
|
54
56
|
export const Canvas = forwardRef<SkiaView, CanvasProps>(
|
55
|
-
({ children, style, debug, mode, onTouch }, forwardedRef) => {
|
57
|
+
({ children, style, debug, mode, onTouch, onSize }, forwardedRef) => {
|
56
58
|
const size = useValue({ width: 0, height: 0 });
|
57
59
|
const canvasCtx = useMemo(() => ({ Skia, size }), [size]);
|
58
60
|
const innerRef = useCanvasRef();
|
@@ -114,6 +116,9 @@ export const Canvas = forwardRef<SkiaView, CanvasProps>(
|
|
114
116
|
height !== canvasCtx.size.current.height
|
115
117
|
) {
|
116
118
|
canvasCtx.size.current = { width, height };
|
119
|
+
if (onSize) {
|
120
|
+
onSize.current = { width, height };
|
121
|
+
}
|
117
122
|
}
|
118
123
|
paint.reset();
|
119
124
|
const ctx = {
|
@@ -1,5 +1,3 @@
|
|
1
|
-
import type { ForwardedRef } from "react";
|
2
|
-
|
3
1
|
import { NodeType } from "../dom/types";
|
4
2
|
import type {
|
5
3
|
CircleProps,
|
@@ -55,7 +53,6 @@ import type {
|
|
55
53
|
BlendProps,
|
56
54
|
MorphologyImageFilterProps,
|
57
55
|
} from "../dom/types/ImageFilters";
|
58
|
-
import type { PaintNode } from "../dom/nodes/PaintNode";
|
59
56
|
|
60
57
|
import type { Container } from "./Container";
|
61
58
|
import { exhaustiveCheck } from "./typeddash";
|
@@ -67,7 +64,7 @@ declare global {
|
|
67
64
|
interface IntrinsicElements {
|
68
65
|
skGroup: SkiaProps<GroupProps>;
|
69
66
|
skLayer: SkiaProps<ChildrenProps>;
|
70
|
-
skPaint: SkiaProps<PaintProps
|
67
|
+
skPaint: SkiaProps<PaintProps>;
|
71
68
|
|
72
69
|
// Drawings
|
73
70
|
skFill: SkiaProps<DrawingNodeProps>;
|
@@ -2,7 +2,7 @@ import type { ReactNode } from "react";
|
|
2
2
|
import React, { useMemo } from "react";
|
3
3
|
|
4
4
|
import { BlendMode } from "../../skia/types";
|
5
|
-
import {
|
5
|
+
import { useSkiaPrivate } from "../useCanvas";
|
6
6
|
|
7
7
|
import { Group } from "./Group";
|
8
8
|
|
@@ -14,7 +14,7 @@ interface MaskProps {
|
|
14
14
|
}
|
15
15
|
|
16
16
|
export const Mask = ({ children, mask, mode, clip }: MaskProps) => {
|
17
|
-
const
|
17
|
+
const Skia = useSkiaPrivate();
|
18
18
|
const maskPaint = useMemo(() => {
|
19
19
|
const paint = Skia.Paint();
|
20
20
|
paint.setBlendMode(BlendMode.Src);
|
@@ -1,19 +1,8 @@
|
|
1
|
-
|
2
|
-
import React, { useRef, forwardRef } from "react";
|
1
|
+
import React from "react";
|
3
2
|
|
4
3
|
import type { SkiaProps } from "../processors";
|
5
4
|
import type { DrawingNodeProps } from "../../dom/types";
|
6
|
-
import type { PaintNode } from "../../dom/nodes/PaintNode";
|
7
5
|
|
8
|
-
export const
|
9
|
-
|
10
|
-
If you are using the layer property, simply pass the component directly: https://shopify.github.io/react-native-skia/docs/group#layer-effects.
|
11
|
-
If you are using the paint property, please the following paint properties directly: https://shopify.github.io/react-native-skia/docs/paint/overview`);
|
12
|
-
return useRef<PaintNode>(null);
|
6
|
+
export const Paint = (props: SkiaProps<DrawingNodeProps>) => {
|
7
|
+
return <skPaint {...props} />;
|
13
8
|
};
|
14
|
-
|
15
|
-
export const Paint = forwardRef<PaintNode, SkiaProps<DrawingNodeProps>>(
|
16
|
-
(props, ref) => {
|
17
|
-
return <skPaint ref={ref} {...props} />;
|
18
|
-
}
|
19
|
-
);
|
@@ -14,8 +14,22 @@ export const CanvasProvider = CanvasContext.Provider;
|
|
14
14
|
|
15
15
|
export const useCanvas = () => {
|
16
16
|
const ctx = useContext(CanvasContext);
|
17
|
+
console.warn(
|
18
|
+
// eslint-disable-next-line max-len
|
19
|
+
"useCanvas is deprecated. use the onSize property instead: https://shopify.github.io/react-native-skia/docs/canvas/overview"
|
20
|
+
);
|
17
21
|
if (!ctx) {
|
18
22
|
throw new Error("Canvas context is not available");
|
19
23
|
}
|
20
24
|
return ctx;
|
21
25
|
};
|
26
|
+
|
27
|
+
// This private function will be removed once we remove the useCanvas hook and
|
28
|
+
// implement the Mask component as a node (will be faster too)
|
29
|
+
export const useSkiaPrivate = () => {
|
30
|
+
const ctx = useContext(CanvasContext);
|
31
|
+
if (!ctx) {
|
32
|
+
throw new Error("Canvas context is not available");
|
33
|
+
}
|
34
|
+
return ctx.Skia;
|
35
|
+
};
|
package/src/skia/core/Picture.ts
CHANGED
@@ -1,30 +1,6 @@
|
|
1
|
-
import type { DependencyList } from "react";
|
2
|
-
import { useMemo } from "react";
|
3
|
-
|
4
1
|
import { Skia } from "../Skia";
|
5
2
|
import type { SkCanvas, SkRect } from "../types";
|
6
3
|
|
7
|
-
/**
|
8
|
-
* Memoizes and returns an SkPicture that can be drawn to another canvas.
|
9
|
-
* @param rect Picture bounds
|
10
|
-
* @param cb Callback for drawing to the canvas
|
11
|
-
* @returns SkPicture
|
12
|
-
*/
|
13
|
-
export const usePicture = (
|
14
|
-
rect: SkRect,
|
15
|
-
cb: (canvas: SkCanvas) => void,
|
16
|
-
deps: DependencyList = []
|
17
|
-
) => {
|
18
|
-
console.warn("usePicture() is deprecated. Use createPicture() instead.");
|
19
|
-
return useMemo(() => {
|
20
|
-
const recorder = Skia.PictureRecorder();
|
21
|
-
const canvas = recorder.beginRecording(rect);
|
22
|
-
cb(canvas);
|
23
|
-
return recorder.finishRecordingAsPicture();
|
24
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
25
|
-
}, deps);
|
26
|
-
};
|
27
|
-
|
28
4
|
/**
|
29
5
|
* Memoizes and returns an SkPicture that can be drawn to another canvas.
|
30
6
|
* @param rect Picture bounds
|
package/src/skia/core/Rect.ts
CHANGED
@@ -12,7 +12,7 @@ export const bounds = (rects: SkRect[]) => {
|
|
12
12
|
const y = Math.min(...rects.map((r) => r.y));
|
13
13
|
const width = Math.max(...rects.map((r) => r.x + r.width));
|
14
14
|
const height = Math.max(...rects.map((r) => r.y + r.height));
|
15
|
-
return rect(x, y, width, height);
|
15
|
+
return rect(x, y, width - x, height - y);
|
16
16
|
};
|
17
17
|
|
18
18
|
export const topLeft = (r: SkRect | SkRRect) =>
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { SkJSIInstance } from "./JsiInstance";
|
2
2
|
import type { SkPath } from "./Path/Path";
|
3
|
+
import type { SkPoint } from "./Point";
|
3
4
|
|
4
5
|
export interface PosTan {
|
5
6
|
px: number;
|
@@ -11,10 +12,10 @@ export interface PosTan {
|
|
11
12
|
export interface SkContourMeasure extends SkJSIInstance<"ContourMeasure"> {
|
12
13
|
/**
|
13
14
|
* Returns the given position and tangent line for the distance on the given contour.
|
14
|
-
* The return value
|
15
|
+
* The return value an array of 2 vectors: [position, tangent]
|
15
16
|
* @param distance - will be pinned between 0 and length().
|
16
17
|
*/
|
17
|
-
getPosTan(distance: number):
|
18
|
+
getPosTan(distance: number): [position: SkPoint, tangent: SkPoint];
|
18
19
|
|
19
20
|
/**
|
20
21
|
* Returns an Path representing the segment of this contour.
|
package/src/skia/types/index.ts
CHANGED
@@ -241,6 +241,17 @@ const parseCSSColor = (cssStr: string) => {
|
|
241
241
|
return null;
|
242
242
|
} // Covers NaN.
|
243
243
|
return [(iv & 0xff0000) >> 16, (iv & 0xff00) >> 8, iv & 0xff, 1];
|
244
|
+
} else if (str.length === 9) {
|
245
|
+
var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
|
246
|
+
if (!(iv >= 0 && iv <= 0xffffffff)) {
|
247
|
+
return null; // Covers NaN.
|
248
|
+
}
|
249
|
+
return [
|
250
|
+
((iv & 0xff000000) >> 24) & 0xff,
|
251
|
+
(iv & 0xff0000) >> 16,
|
252
|
+
(iv & 0xff00) >> 8,
|
253
|
+
(iv & 0xff) / 255,
|
254
|
+
];
|
244
255
|
}
|
245
256
|
|
246
257
|
return null;
|
@@ -4,6 +4,7 @@ import type { SkContourMeasure } from "../types";
|
|
4
4
|
|
5
5
|
import { HostObject } from "./Host";
|
6
6
|
import { JsiSkPath } from "./JsiSkPath";
|
7
|
+
import { JsiSkPoint } from "./JsiSkPoint";
|
7
8
|
|
8
9
|
export class JsiSkContourMeasure
|
9
10
|
extends HostObject<ContourMeasure, "ContourMeasure">
|
@@ -13,9 +14,12 @@ export class JsiSkContourMeasure
|
|
13
14
|
super(CanvasKit, ref, "ContourMeasure");
|
14
15
|
}
|
15
16
|
|
16
|
-
getPosTan(distance: number) {
|
17
|
-
const
|
18
|
-
return
|
17
|
+
getPosTan(distance: number): [position: JsiSkPoint, tangent: JsiSkPoint] {
|
18
|
+
const posTan = this.ref.getPosTan(distance);
|
19
|
+
return [
|
20
|
+
new JsiSkPoint(this.CanvasKit, posTan.slice(0, 2)),
|
21
|
+
new JsiSkPoint(this.CanvasKit, posTan.slice(2)),
|
22
|
+
];
|
19
23
|
}
|
20
24
|
|
21
25
|
getSegment(startD: number, stopD: number, startWithMoveTo: boolean) {
|
@@ -13,8 +13,10 @@ export class RNSkReadonlyValue<T> implements SkiaValue<T> {
|
|
13
13
|
}
|
14
14
|
|
15
15
|
protected update(nextValue: T): void {
|
16
|
-
this._current
|
17
|
-
|
16
|
+
if (this._current !== nextValue) {
|
17
|
+
this._current = nextValue;
|
18
|
+
this.notifyListeners();
|
19
|
+
}
|
18
20
|
}
|
19
21
|
|
20
22
|
public readonly __typename__ = "RNSkValue";
|
@@ -46,8 +46,8 @@ export abstract class SkiaBaseWebView<
|
|
46
46
|
// Reset canvas / surface on layout change
|
47
47
|
if (this._canvasRef.current) {
|
48
48
|
const canvas = this._canvasRef.current;
|
49
|
-
canvas.width =
|
50
|
-
canvas.height =
|
49
|
+
canvas.width = width * pd;
|
50
|
+
canvas.height = height * pd;
|
51
51
|
const surface = CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current);
|
52
52
|
if (!surface) {
|
53
53
|
throw new Error("Could not create surface");
|