@shopify/react-native-skia 0.1.166 → 0.1.167

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.
Files changed (58) hide show
  1. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +0 -5
  2. package/cpp/api/JsiSkPath.h +20 -3
  3. package/cpp/rnskia/dom/nodes/JsiBoxNode.h +4 -12
  4. package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +30 -9
  5. package/cpp/rnskia/dom/props/ImageProps.h +9 -6
  6. package/cpp/rnskia/dom/props/PointProp.h +4 -13
  7. package/cpp/rnskia/dom/props/PointsProp.h +1 -7
  8. package/cpp/rnskia/dom/props/RRectProp.h +53 -0
  9. package/cpp/rnskia/dom/props/RadiusProp.h +7 -9
  10. package/cpp/rnskia/dom/props/TransformProp.h +2 -2
  11. package/lib/commonjs/dom/nodes/datatypes/Transform.js +0 -3
  12. package/lib/commonjs/dom/nodes/datatypes/Transform.js.map +1 -1
  13. package/lib/commonjs/dom/nodes/paint/Shaders.js +1 -1
  14. package/lib/commonjs/dom/nodes/paint/Shaders.js.map +1 -1
  15. package/lib/commonjs/renderer/Canvas.js +8 -39
  16. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  17. package/lib/commonjs/renderer/DrawingContext.js.map +1 -1
  18. package/lib/commonjs/renderer/Reconciler.js +64 -0
  19. package/lib/commonjs/renderer/Reconciler.js.map +1 -0
  20. package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
  21. package/lib/commonjs/skia/web/JsiSkPath.js +7 -0
  22. package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
  23. package/lib/commonjs/skia/web/JsiSkRRect.js +14 -1
  24. package/lib/commonjs/skia/web/JsiSkRRect.js.map +1 -1
  25. package/lib/commonjs/skia/web/JsiSkia.js +1 -1
  26. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  27. package/lib/module/dom/nodes/datatypes/Transform.js +0 -3
  28. package/lib/module/dom/nodes/datatypes/Transform.js.map +1 -1
  29. package/lib/module/dom/nodes/paint/Shaders.js +1 -1
  30. package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
  31. package/lib/module/renderer/Canvas.js +7 -33
  32. package/lib/module/renderer/Canvas.js.map +1 -1
  33. package/lib/module/renderer/DrawingContext.js.map +1 -1
  34. package/lib/module/renderer/Reconciler.js +48 -0
  35. package/lib/module/renderer/Reconciler.js.map +1 -0
  36. package/lib/module/skia/types/Path/Path.js.map +1 -1
  37. package/lib/module/skia/web/JsiSkPath.js +7 -0
  38. package/lib/module/skia/web/JsiSkPath.js.map +1 -1
  39. package/lib/module/skia/web/JsiSkRRect.js +14 -1
  40. package/lib/module/skia/web/JsiSkRRect.js.map +1 -1
  41. package/lib/module/skia/web/JsiSkia.js +1 -1
  42. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  43. package/lib/typescript/src/renderer/Canvas.d.ts +4 -7
  44. package/lib/typescript/src/renderer/DrawingContext.d.ts +2 -5
  45. package/lib/typescript/src/renderer/Reconciler.d.ts +13 -0
  46. package/lib/typescript/src/skia/types/Path/Path.d.ts +13 -0
  47. package/lib/typescript/src/skia/web/JsiSkPath.d.ts +1 -0
  48. package/lib/typescript/src/skia/web/JsiSkRRect.d.ts +2 -2
  49. package/package.json +1 -1
  50. package/src/dom/nodes/datatypes/Transform.ts +0 -2
  51. package/src/dom/nodes/paint/Shaders.ts +1 -1
  52. package/src/renderer/Canvas.tsx +12 -61
  53. package/src/renderer/DrawingContext.ts +2 -6
  54. package/src/renderer/Reconciler.tsx +66 -0
  55. package/src/skia/types/Path/Path.ts +14 -0
  56. package/src/skia/web/JsiSkPath.ts +10 -0
  57. package/src/skia/web/JsiSkRRect.ts +13 -2
  58. package/src/skia/web/JsiSkia.ts +1 -4
@@ -1,13 +1,9 @@
1
- import type { RefObject } from "react";
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, ref: RRect) {
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
 
@@ -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,