@shopify/react-native-skia 0.1.166 → 0.1.167
Sign up to get free protection for your applications and to get access to all the features.
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +0 -5
- package/cpp/api/JsiSkPath.h +20 -3
- package/cpp/rnskia/dom/nodes/JsiBoxNode.h +4 -12
- package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +30 -9
- package/cpp/rnskia/dom/props/ImageProps.h +9 -6
- package/cpp/rnskia/dom/props/PointProp.h +4 -13
- package/cpp/rnskia/dom/props/PointsProp.h +1 -7
- package/cpp/rnskia/dom/props/RRectProp.h +53 -0
- package/cpp/rnskia/dom/props/RadiusProp.h +7 -9
- package/cpp/rnskia/dom/props/TransformProp.h +2 -2
- package/lib/commonjs/dom/nodes/datatypes/Transform.js +0 -3
- package/lib/commonjs/dom/nodes/datatypes/Transform.js.map +1 -1
- package/lib/commonjs/dom/nodes/paint/Shaders.js +1 -1
- package/lib/commonjs/dom/nodes/paint/Shaders.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.js +8 -39
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/DrawingContext.js.map +1 -1
- package/lib/commonjs/renderer/Reconciler.js +64 -0
- package/lib/commonjs/renderer/Reconciler.js.map +1 -0
- package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPath.js +7 -0
- package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkRRect.js +14 -1
- package/lib/commonjs/skia/web/JsiSkRRect.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/dom/nodes/datatypes/Transform.js +0 -3
- package/lib/module/dom/nodes/datatypes/Transform.js.map +1 -1
- package/lib/module/dom/nodes/paint/Shaders.js +1 -1
- package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
- package/lib/module/renderer/Canvas.js +7 -33
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/DrawingContext.js.map +1 -1
- package/lib/module/renderer/Reconciler.js +48 -0
- package/lib/module/renderer/Reconciler.js.map +1 -0
- package/lib/module/skia/types/Path/Path.js.map +1 -1
- package/lib/module/skia/web/JsiSkPath.js +7 -0
- package/lib/module/skia/web/JsiSkPath.js.map +1 -1
- package/lib/module/skia/web/JsiSkRRect.js +14 -1
- package/lib/module/skia/web/JsiSkRRect.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +1 -1
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +4 -7
- package/lib/typescript/src/renderer/DrawingContext.d.ts +2 -5
- package/lib/typescript/src/renderer/Reconciler.d.ts +13 -0
- package/lib/typescript/src/skia/types/Path/Path.d.ts +13 -0
- package/lib/typescript/src/skia/web/JsiSkPath.d.ts +1 -0
- package/lib/typescript/src/skia/web/JsiSkRRect.d.ts +2 -2
- package/package.json +1 -1
- package/src/dom/nodes/datatypes/Transform.ts +0 -2
- package/src/dom/nodes/paint/Shaders.ts +1 -1
- package/src/renderer/Canvas.tsx +12 -61
- package/src/renderer/DrawingContext.ts +2 -6
- package/src/renderer/Reconciler.tsx +66 -0
- package/src/skia/types/Path/Path.ts +14 -0
- package/src/skia/web/JsiSkPath.ts +10 -0
- package/src/skia/web/JsiSkRRect.ts +13 -2
- package/src/skia/web/JsiSkia.ts +1 -4
@@ -1,13 +1,9 @@
|
|
1
|
-
import type {
|
2
|
-
|
3
|
-
import type { DrawingInfo, SkiaView } from "../views";
|
4
|
-
import type { Skia, Vector } from "../skia/types";
|
1
|
+
import type { DrawingInfo } from "../views";
|
2
|
+
import type { Skia } from "../skia/types";
|
5
3
|
import type { DrawingContext as DOMDrawingContext } from "../dom/types";
|
6
4
|
|
7
5
|
export interface DrawingContext
|
8
6
|
extends Omit<DrawingInfo, "touches">,
|
9
7
|
DOMDrawingContext {
|
10
|
-
center: Vector;
|
11
|
-
ref: RefObject<SkiaView>;
|
12
8
|
Skia: Skia;
|
13
9
|
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import type { ReactNode } from "react";
|
2
|
+
import type { OpaqueRoot } from "react-reconciler";
|
3
|
+
import ReactReconciler from "react-reconciler";
|
4
|
+
|
5
|
+
import type { Skia } from "../skia/types";
|
6
|
+
import type { SkiaValue } from "../values/types";
|
7
|
+
|
8
|
+
import { DependencyManager } from "./DependencyManager";
|
9
|
+
import { skHostConfig, debug as hostDebug } from "./HostConfig";
|
10
|
+
import { Container } from "./Container";
|
11
|
+
|
12
|
+
const skiaReconciler = ReactReconciler(skHostConfig);
|
13
|
+
|
14
|
+
type RegisterValues = (values: Array<SkiaValue<unknown>>) => () => void;
|
15
|
+
|
16
|
+
const createDependencyManager = (registerValues: RegisterValues) =>
|
17
|
+
global.SkiaDomApi && global.SkiaDomApi.DependencyManager
|
18
|
+
? global.SkiaDomApi.DependencyManager(registerValues)
|
19
|
+
: new DependencyManager(registerValues);
|
20
|
+
|
21
|
+
skiaReconciler.injectIntoDevTools({
|
22
|
+
bundleType: 1,
|
23
|
+
version: "0.0.1",
|
24
|
+
rendererPackageName: "react-native-skia",
|
25
|
+
});
|
26
|
+
|
27
|
+
export class SkiaRoot {
|
28
|
+
private root: OpaqueRoot;
|
29
|
+
private container: Container;
|
30
|
+
|
31
|
+
constructor(
|
32
|
+
Skia: Skia,
|
33
|
+
registerValues: RegisterValues = () => () => {},
|
34
|
+
redraw: () => void = () => {}
|
35
|
+
) {
|
36
|
+
const depMgr = createDependencyManager(registerValues);
|
37
|
+
this.container = new Container(Skia, depMgr, redraw);
|
38
|
+
this.root = skiaReconciler.createContainer(
|
39
|
+
this.container,
|
40
|
+
0,
|
41
|
+
null,
|
42
|
+
true,
|
43
|
+
null,
|
44
|
+
"",
|
45
|
+
console.error,
|
46
|
+
null
|
47
|
+
);
|
48
|
+
}
|
49
|
+
|
50
|
+
render(element: ReactNode) {
|
51
|
+
skiaReconciler.updateContainer(element, this.root, null, () => {
|
52
|
+
hostDebug("updateContainer");
|
53
|
+
this.container.depMgr.update();
|
54
|
+
});
|
55
|
+
}
|
56
|
+
|
57
|
+
unmount() {
|
58
|
+
skiaReconciler.updateContainer(null, this.root, null, () => {
|
59
|
+
this.container.depMgr.remove();
|
60
|
+
});
|
61
|
+
}
|
62
|
+
|
63
|
+
get dom() {
|
64
|
+
return this.container.root;
|
65
|
+
}
|
66
|
+
}
|
@@ -441,6 +441,20 @@ export interface SkPath extends SkJSIInstance<"Path"> {
|
|
441
441
|
*/
|
442
442
|
addRRect(rrect: SkRRect, isCCW?: boolean): SkPath;
|
443
443
|
|
444
|
+
/** Appends src to SkPath, transformed by matrix. Transformed curves may have
|
445
|
+
different verbs, SkPoint, and conic weights.
|
446
|
+
|
447
|
+
If mode is kAppend_AddPathMode, src verb array, SkPoint array, and conic
|
448
|
+
weights are added unaltered. If mode is kExtend_AddPathMode, add line
|
449
|
+
before appending verbs, SkPoint, and conic weights.
|
450
|
+
|
451
|
+
@param src SkPath verbs, SkPoint, and conic weights to add
|
452
|
+
@param matrix transform applied to src
|
453
|
+
@param extend extends path with line if true
|
454
|
+
@return reference to SkPath
|
455
|
+
*/
|
456
|
+
addPath(src: SkPath, matrix?: SkMatrix, extend?: boolean): SkPath;
|
457
|
+
|
444
458
|
/**
|
445
459
|
* Returns the Point at index in Point array. Valid range for index is
|
446
460
|
* 0 to countPoints() - 1.
|
@@ -33,6 +33,16 @@ export class JsiSkPath extends HostObject<Path, "Path"> implements SkPath {
|
|
33
33
|
super(CanvasKit, ref, "Path");
|
34
34
|
}
|
35
35
|
|
36
|
+
addPath(src: SkPath, matrix?: SkMatrix, extend = false) {
|
37
|
+
const args = [
|
38
|
+
JsiSkPath.fromValue(src),
|
39
|
+
...(matrix ? JsiSkMatrix.fromValue<Float32Array>(matrix) : []),
|
40
|
+
extend,
|
41
|
+
];
|
42
|
+
this.ref.addPath(...args);
|
43
|
+
return this;
|
44
|
+
}
|
45
|
+
|
36
46
|
addArc(
|
37
47
|
oval: SkRect,
|
38
48
|
startAngleInDegrees: number,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { CanvasKit, RRect } from "canvaskit-wasm";
|
2
2
|
|
3
|
-
import type { SkRRect } from "../types";
|
3
|
+
import type { SkRect, SkRRect } from "../types";
|
4
4
|
|
5
5
|
import { BaseHostObject } from "./Host";
|
6
6
|
import { JsiSkRect } from "./JsiSkRect";
|
@@ -20,7 +20,18 @@ export class JsiSkRRect
|
|
20
20
|
);
|
21
21
|
}
|
22
22
|
|
23
|
-
constructor(CanvasKit: CanvasKit,
|
23
|
+
constructor(CanvasKit: CanvasKit, rect: SkRect, rx: number, ry: number) {
|
24
|
+
// based on https://github.com/google/skia/blob/main/src/core/SkRRect.cpp#L51
|
25
|
+
if (rx === Infinity || ry === Infinity) {
|
26
|
+
rx = ry = 0;
|
27
|
+
}
|
28
|
+
if (rect.width < rx + rx || rect.height < ry + ry) {
|
29
|
+
// At most one of these two divides will be by zero, and neither numerator is zero.
|
30
|
+
const scale = Math.min(rect.width / (rx + rx), rect.height / (ry + ry));
|
31
|
+
rx *= scale;
|
32
|
+
ry *= scale;
|
33
|
+
}
|
34
|
+
const ref = CanvasKit.RRectXY(JsiSkRect.fromValue(CanvasKit, rect), rx, ry);
|
24
35
|
super(CanvasKit, ref, "RRect");
|
25
36
|
}
|
26
37
|
|
package/src/skia/web/JsiSkia.ts
CHANGED
@@ -45,10 +45,7 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
|
|
45
45
|
throw new Error("Not implemented on React Native Web");
|
46
46
|
},
|
47
47
|
RRectXY: (rect: SkRect, rx: number, ry: number) =>
|
48
|
-
new JsiSkRRect(
|
49
|
-
CanvasKit,
|
50
|
-
CanvasKit.RRectXY(JsiSkRect.fromValue(CanvasKit, rect), rx, ry)
|
51
|
-
),
|
48
|
+
new JsiSkRRect(CanvasKit, rect, rx, ry),
|
52
49
|
RSXform: (scos: number, ssin: number, tx: number, ty: number) =>
|
53
50
|
new JsiSkRSXform(CanvasKit, Float32Array.of(scos, ssin, tx, ty)),
|
54
51
|
Color,
|