@shopify/react-native-skia 0.1.232 → 0.1.234

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. package/android/CMakeLists.txt +0 -1
  2. package/android/cpp/jni/JniSkiaManager.cpp +0 -1
  3. package/android/cpp/rnskia-android/RNSkAndroidView.h +0 -1
  4. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +1 -1
  5. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +1 -2
  6. package/lib/commonjs/external/reanimated/interpolators.js +3 -1
  7. package/lib/commonjs/external/reanimated/interpolators.js.map +1 -1
  8. package/lib/commonjs/renderer/Canvas.js +10 -4
  9. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  10. package/lib/commonjs/renderer/HostConfig.js +1 -1
  11. package/lib/commonjs/renderer/HostConfig.js.map +1 -1
  12. package/lib/commonjs/renderer/Reconciler.d.ts +1 -0
  13. package/lib/commonjs/renderer/Reconciler.js +4 -0
  14. package/lib/commonjs/renderer/Reconciler.js.map +1 -1
  15. package/lib/commonjs/skia/types/Shader/Shader.js +1 -1
  16. package/lib/commonjs/skia/types/Shader/Shader.js.map +1 -1
  17. package/lib/commonjs/skia/web/JsiSkPath.d.ts +2 -2
  18. package/lib/commonjs/skia/web/JsiSkPath.js +10 -2
  19. package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
  20. package/lib/commonjs/views/SkiaJSDomView.d.ts +31 -0
  21. package/lib/commonjs/views/SkiaJSDomView.js +161 -0
  22. package/lib/commonjs/views/SkiaJSDomView.js.map +1 -0
  23. package/lib/commonjs/views/SkiaJSDomView.web.d.ts +1 -0
  24. package/lib/commonjs/views/SkiaJSDomView.web.js +14 -0
  25. package/lib/commonjs/views/SkiaJSDomView.web.js.map +1 -0
  26. package/lib/module/external/reanimated/interpolators.js +2 -1
  27. package/lib/module/external/reanimated/interpolators.js.map +1 -1
  28. package/lib/module/renderer/Canvas.js +9 -3
  29. package/lib/module/renderer/Canvas.js.map +1 -1
  30. package/lib/module/renderer/HostConfig.js +1 -1
  31. package/lib/module/renderer/HostConfig.js.map +1 -1
  32. package/lib/module/renderer/Reconciler.d.ts +1 -0
  33. package/lib/module/renderer/Reconciler.js +4 -0
  34. package/lib/module/renderer/Reconciler.js.map +1 -1
  35. package/lib/module/skia/types/Shader/Shader.js +1 -1
  36. package/lib/module/skia/types/Shader/Shader.js.map +1 -1
  37. package/lib/module/skia/web/JsiSkPath.d.ts +2 -2
  38. package/lib/module/skia/web/JsiSkPath.js +10 -2
  39. package/lib/module/skia/web/JsiSkPath.js.map +1 -1
  40. package/lib/module/views/SkiaJSDomView.d.ts +31 -0
  41. package/lib/module/views/SkiaJSDomView.js +136 -0
  42. package/lib/module/views/SkiaJSDomView.js.map +1 -0
  43. package/lib/module/views/SkiaJSDomView.web.d.ts +1 -0
  44. package/lib/module/views/SkiaJSDomView.web.js +2 -0
  45. package/lib/module/views/SkiaJSDomView.web.js.map +1 -0
  46. package/lib/typescript/src/renderer/Reconciler.d.ts +1 -0
  47. package/lib/typescript/src/skia/web/JsiSkPath.d.ts +2 -2
  48. package/lib/typescript/src/views/SkiaJSDomView.d.ts +31 -0
  49. package/lib/typescript/src/views/SkiaJSDomView.web.d.ts +1 -0
  50. package/package.json +1 -1
  51. package/src/external/reanimated/interpolators.ts +2 -1
  52. package/src/renderer/Canvas.tsx +9 -2
  53. package/src/renderer/HostConfig.ts +1 -1
  54. package/src/renderer/Reconciler.tsx +4 -0
  55. package/src/skia/types/Shader/Shader.ts +1 -1
  56. package/src/skia/web/JsiSkPath.ts +23 -3
  57. package/src/views/SkiaJSDomView.tsx +126 -0
  58. package/src/views/SkiaJSDomView.web.tsx +1 -0
  59. package/android/cpp/jni/include/JniSkiaDrawView.h +0 -90
  60. package/cpp/rnskia/RNSkJsView.cpp +0 -236
  61. package/cpp/rnskia/RNSkJsView.h +0 -121
@@ -0,0 +1,31 @@
1
+ import React from "react";
2
+ import type { Skia, SkRect } from "../skia/types";
3
+ import type { SkiaDomViewProps } from "./types";
4
+ export declare class SkiaJSDomView extends React.Component<SkiaDomViewProps & {
5
+ Skia: Skia;
6
+ }> {
7
+ constructor(props: SkiaDomViewProps & {
8
+ Skia: Skia;
9
+ });
10
+ private _nativeId;
11
+ get nativeId(): number;
12
+ componentDidUpdate(prevProps: SkiaDomViewProps & {
13
+ Skia: Skia;
14
+ }): void;
15
+ /**
16
+ * Creates a snapshot from the canvas in the surface
17
+ * @param rect Rect to use as bounds. Optional.
18
+ * @returns An Image object.
19
+ */
20
+ makeImageSnapshot(rect?: SkRect): import("../skia/types").SkImage;
21
+ /**
22
+ * Sends a redraw request to the native SkiaView.
23
+ */
24
+ redraw(): void;
25
+ private draw;
26
+ /**
27
+ * Clear up the dom node when unmounting to release resources.
28
+ */
29
+ componentWillUnmount(): void;
30
+ render(): React.JSX.Element;
31
+ }
@@ -0,0 +1,136 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
+
5
+ import React from "react";
6
+ import { Platform } from "../Platform";
7
+ import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeComponent";
8
+ import { JsiDrawingContext } from "../dom/types";
9
+ import { SkiaViewApi } from "./api";
10
+ import { SkiaViewNativeId } from "./SkiaViewNativeId";
11
+ const NativeSkiaPictureView = Platform.OS !== "web" ? SkiaPictureViewNativeComponent : // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ null;
13
+ export class SkiaJSDomView extends React.Component {
14
+ constructor(props) {
15
+ super(props);
16
+
17
+ _defineProperty(this, "_nativeId", void 0);
18
+
19
+ this._nativeId = SkiaViewNativeId.current++;
20
+ const {
21
+ root,
22
+ onTouch,
23
+ onSize
24
+ } = props;
25
+
26
+ if (root) {
27
+ assertSkiaViewApi();
28
+ SkiaViewApi.setJsiProperty(this._nativeId, "root", root);
29
+ }
30
+
31
+ if (onTouch) {
32
+ assertSkiaViewApi();
33
+ SkiaViewApi.setJsiProperty(this._nativeId, "onTouch", onTouch);
34
+ }
35
+
36
+ if (onSize) {
37
+ assertSkiaViewApi();
38
+ SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
39
+ }
40
+ }
41
+
42
+ get nativeId() {
43
+ return this._nativeId;
44
+ }
45
+
46
+ componentDidUpdate(prevProps) {
47
+ const {
48
+ root,
49
+ onTouch,
50
+ onSize
51
+ } = this.props;
52
+
53
+ if (root !== prevProps.root && root !== undefined) {
54
+ assertSkiaViewApi();
55
+ this.draw();
56
+ }
57
+
58
+ if (onTouch !== prevProps.onTouch) {
59
+ assertSkiaViewApi();
60
+ SkiaViewApi.setJsiProperty(this._nativeId, "onTouch", onTouch);
61
+ }
62
+
63
+ if (onSize !== prevProps.onSize) {
64
+ assertSkiaViewApi();
65
+ SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
66
+ }
67
+ }
68
+ /**
69
+ * Creates a snapshot from the canvas in the surface
70
+ * @param rect Rect to use as bounds. Optional.
71
+ * @returns An Image object.
72
+ */
73
+
74
+
75
+ makeImageSnapshot(rect) {
76
+ assertSkiaViewApi();
77
+ return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);
78
+ }
79
+ /**
80
+ * Sends a redraw request to the native SkiaView.
81
+ */
82
+
83
+
84
+ redraw() {
85
+ assertSkiaViewApi();
86
+ this.draw(); //SkiaViewApi.requestRedraw(this._nativeId);
87
+ }
88
+
89
+ draw() {
90
+ const {
91
+ root,
92
+ Skia
93
+ } = this.props;
94
+
95
+ if (root !== undefined) {
96
+ assertSkiaViewApi();
97
+ const rec = Skia.PictureRecorder();
98
+ const canvas = rec.beginRecording();
99
+ const ctx = new JsiDrawingContext(Skia, canvas);
100
+ root.render(ctx);
101
+ const picture = rec.finishRecordingAsPicture();
102
+ SkiaViewApi.setJsiProperty(this._nativeId, "picture", picture);
103
+ }
104
+ }
105
+ /**
106
+ * Clear up the dom node when unmounting to release resources.
107
+ */
108
+
109
+
110
+ componentWillUnmount() {
111
+ assertSkiaViewApi();
112
+ SkiaViewApi.setJsiProperty(this._nativeId, "picture", null);
113
+ }
114
+
115
+ render() {
116
+ const {
117
+ mode,
118
+ debug = false,
119
+ ...viewProps
120
+ } = this.props;
121
+ return /*#__PURE__*/React.createElement(NativeSkiaPictureView, _extends({
122
+ collapsable: false,
123
+ nativeID: `${this._nativeId}`,
124
+ mode: mode,
125
+ debug: debug
126
+ }, viewProps));
127
+ }
128
+
129
+ }
130
+
131
+ const assertSkiaViewApi = () => {
132
+ if (SkiaViewApi === null || SkiaViewApi.setJsiProperty === null || SkiaViewApi.callJsiMethod === null || SkiaViewApi.requestRedraw === null || SkiaViewApi.makeImageSnapshot === null) {
133
+ throw Error("Skia View Api was not found.");
134
+ }
135
+ };
136
+ //# sourceMappingURL=SkiaJSDomView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","Platform","SkiaPictureViewNativeComponent","JsiDrawingContext","SkiaViewApi","SkiaViewNativeId","NativeSkiaPictureView","OS","SkiaJSDomView","Component","constructor","props","_nativeId","current","root","onTouch","onSize","assertSkiaViewApi","setJsiProperty","nativeId","componentDidUpdate","prevProps","undefined","draw","makeImageSnapshot","rect","redraw","Skia","rec","PictureRecorder","canvas","beginRecording","ctx","render","picture","finishRecordingAsPicture","componentWillUnmount","mode","debug","viewProps","callJsiMethod","requestRedraw","Error"],"sources":["SkiaJSDomView.tsx"],"sourcesContent":["import React from \"react\";\nimport type { HostComponent } from \"react-native\";\n\nimport type { Skia, SkRect } from \"../skia/types\";\nimport { Platform } from \"../Platform\";\nimport SkiaPictureViewNativeComponent from \"../specs/SkiaPictureViewNativeComponent\";\nimport { JsiDrawingContext } from \"../dom/types\";\n\nimport { SkiaViewApi } from \"./api\";\nimport type { SkiaPictureViewProps, SkiaDomViewProps } from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\nconst NativeSkiaPictureView: HostComponent<SkiaPictureViewProps> =\n Platform.OS !== \"web\"\n ? SkiaPictureViewNativeComponent\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (null as any);\n\nexport class SkiaJSDomView extends React.Component<\n SkiaDomViewProps & { Skia: Skia }\n> {\n constructor(props: SkiaDomViewProps & { Skia: Skia }) {\n super(props);\n this._nativeId = SkiaViewNativeId.current++;\n const { root, onTouch, onSize } = props;\n if (root) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"root\", root);\n }\n if (onTouch) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onTouch\", onTouch);\n }\n if (onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n }\n\n private _nativeId: number;\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaDomViewProps & { Skia: Skia }) {\n const { root, onTouch, onSize } = this.props;\n if (root !== prevProps.root && root !== undefined) {\n assertSkiaViewApi();\n this.draw();\n }\n if (onTouch !== prevProps.onTouch) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onTouch\", onTouch);\n }\n if (onSize !== prevProps.onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n assertSkiaViewApi();\n return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n public redraw() {\n assertSkiaViewApi();\n this.draw();\n //SkiaViewApi.requestRedraw(this._nativeId);\n }\n\n private draw() {\n const { root, Skia } = this.props;\n if (root !== undefined) {\n assertSkiaViewApi();\n const rec = Skia.PictureRecorder();\n const canvas = rec.beginRecording();\n const ctx = new JsiDrawingContext(Skia, canvas);\n root.render(ctx);\n const picture = rec.finishRecordingAsPicture();\n SkiaViewApi.setJsiProperty(this._nativeId, \"picture\", picture);\n }\n }\n\n /**\n * Clear up the dom node when unmounting to release resources.\n */\n componentWillUnmount(): void {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"picture\", null);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <NativeSkiaPictureView\n collapsable={false}\n nativeID={`${this._nativeId}`}\n mode={mode}\n debug={debug}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertSkiaViewApi = () => {\n if (\n SkiaViewApi === null ||\n SkiaViewApi.setJsiProperty === null ||\n SkiaViewApi.callJsiMethod === null ||\n SkiaViewApi.requestRedraw === null ||\n SkiaViewApi.makeImageSnapshot === null\n ) {\n throw Error(\"Skia View Api was not found.\");\n }\n};\n"],"mappings":";;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAIA,SAASC,QAAT,QAAyB,aAAzB;AACA,OAAOC,8BAAP,MAA2C,yCAA3C;AACA,SAASC,iBAAT,QAAkC,cAAlC;AAEA,SAASC,WAAT,QAA4B,OAA5B;AAEA,SAASC,gBAAT,QAAiC,oBAAjC;AAEA,MAAMC,qBAA0D,GAC9DL,QAAQ,CAACM,EAAT,KAAgB,KAAhB,GACIL,8BADJ,GAEI;AACC,IAJP;AAMA,OAAO,MAAMM,aAAN,SAA4BR,KAAK,CAACS,SAAlC,CAEL;EACAC,WAAW,CAACC,KAAD,EAA2C;IACpD,MAAMA,KAAN;;IADoD;;IAEpD,KAAKC,SAAL,GAAiBP,gBAAgB,CAACQ,OAAjB,EAAjB;IACA,MAAM;MAAEC,IAAF;MAAQC,OAAR;MAAiBC;IAAjB,IAA4BL,KAAlC;;IACA,IAAIG,IAAJ,EAAU;MACRG,iBAAiB;MACjBb,WA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@ -0,0 +1,2 @@
1
+ export { SkiaDomView as SkiaJSDomView } from "./SkiaDomView";
2
+ //# sourceMappingURL=SkiaJSDomView.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["SkiaDomView","SkiaJSDomView"],"sources":["SkiaJSDomView.web.tsx"],"sourcesContent":["export { SkiaDomView as SkiaJSDomView } from \"./SkiaDomView\";\n"],"mappings":"AAAA,SAASA,WAAW,IAAIC,aAAxB,QAA6C,eAA7C"}
@@ -5,5 +5,6 @@ export declare class SkiaRoot {
5
5
  private container;
6
6
  constructor(Skia: Skia, redraw?: () => void, getNativeId?: () => number);
7
7
  render(element: ReactNode): void;
8
+ unmount(): void;
8
9
  get dom(): import("..").RenderNode<import("..").GroupProps>;
9
10
  }
@@ -1,5 +1,5 @@
1
1
  import type { CanvasKit, Path } from "canvaskit-wasm";
2
- import type { FillType, PathCommand, PathOp, SkMatrix, SkPath, SkPoint, SkRect, InputRRect, StrokeOpts } from "../types";
2
+ import type { FillType, PathCommand, PathOp, SkMatrix, SkPath, SkPoint, SkRect, InputRRect, StrokeOpts, InputMatrix } from "../types";
3
3
  import { HostObject } from "./Host";
4
4
  import { JsiSkPoint } from "./JsiSkPoint";
5
5
  import { JsiSkRect } from "./JsiSkRect";
@@ -51,7 +51,7 @@ export declare class JsiSkPath extends HostObject<Path, "Path"> implements SkPat
51
51
  simplify(): boolean;
52
52
  toSVGString(): string;
53
53
  trim(start: number, stop: number, isComplement: boolean): this | null;
54
- transform(m3: SkMatrix): this;
54
+ transform(m: InputMatrix): this;
55
55
  interpolate(end: SkPath, t: number, output?: SkPath): SkPath | JsiSkPath | null;
56
56
  isInterpolatable(path2: SkPath): boolean;
57
57
  toCmds(): PathCommand[];
@@ -0,0 +1,31 @@
1
+ import React from "react";
2
+ import type { Skia, SkRect } from "../skia/types";
3
+ import type { SkiaDomViewProps } from "./types";
4
+ export declare class SkiaJSDomView extends React.Component<SkiaDomViewProps & {
5
+ Skia: Skia;
6
+ }> {
7
+ constructor(props: SkiaDomViewProps & {
8
+ Skia: Skia;
9
+ });
10
+ private _nativeId;
11
+ get nativeId(): number;
12
+ componentDidUpdate(prevProps: SkiaDomViewProps & {
13
+ Skia: Skia;
14
+ }): void;
15
+ /**
16
+ * Creates a snapshot from the canvas in the surface
17
+ * @param rect Rect to use as bounds. Optional.
18
+ * @returns An Image object.
19
+ */
20
+ makeImageSnapshot(rect?: SkRect): import("../skia/types").SkImage;
21
+ /**
22
+ * Sends a redraw request to the native SkiaView.
23
+ */
24
+ redraw(): void;
25
+ private draw;
26
+ /**
27
+ * Clear up the dom node when unmounting to release resources.
28
+ */
29
+ componentWillUnmount(): void;
30
+ render(): React.JSX.Element;
31
+ }
@@ -0,0 +1 @@
1
+ export { SkiaDomView as SkiaJSDomView } from "./SkiaDomView";
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "setup-skia-web": "./scripts/setup-canvaskit.js"
8
8
  },
9
9
  "title": "React Native Skia",
10
- "version": "0.1.232",
10
+ "version": "0.1.234",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "files": [
@@ -8,6 +8,7 @@ import { useCallback, useMemo } from "react";
8
8
  import type { SkPath, SkPoint } from "../../skia/types";
9
9
  import { interpolatePaths, interpolateVector } from "../../animation";
10
10
  import { Skia } from "../../skia";
11
+ import { Platform } from "../../Platform";
11
12
 
12
13
  import {
13
14
  useAnimatedReaction,
@@ -18,7 +19,7 @@ import {
18
19
 
19
20
  export const notifyChange = (value: SharedValue<unknown>) => {
20
21
  "worklet";
21
- if (_WORKLET) {
22
+ if (_WORKLET || Platform.OS === "web") {
22
23
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
24
  (value as any)._value = value.value;
24
25
  }
@@ -15,9 +15,9 @@ import type {
15
15
  import type { LayoutChangeEvent } from "react-native";
16
16
 
17
17
  import { SkiaDomView } from "../views";
18
- import { SkiaDomView as SkiaDomViewWeb } from "../views/SkiaDomView.web";
19
18
  import { Skia } from "../skia/Skia";
20
19
  import type { TouchHandler, SkiaBaseViewProps } from "../views";
20
+ import { SkiaJSDomView } from "../views/SkiaJSDomView";
21
21
 
22
22
  import { SkiaRoot } from "./Reconciler";
23
23
  import { NATIVE_DOM } from "./HostComponents";
@@ -84,6 +84,12 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
84
84
  root.render(children);
85
85
  }, [children, root, redraw]);
86
86
 
87
+ useEffect(() => {
88
+ return () => {
89
+ root.unmount();
90
+ };
91
+ }, [root]);
92
+
87
93
  if (NATIVE_DOM) {
88
94
  return (
89
95
  <SkiaDomView
@@ -99,7 +105,8 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
99
105
  );
100
106
  } else {
101
107
  return (
102
- <SkiaDomViewWeb
108
+ <SkiaJSDomView
109
+ Skia={Skia}
103
110
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
104
111
  ref={ref as any}
105
112
  style={style}
@@ -82,7 +82,7 @@ export const skHostConfig: SkiaHostConfig = {
82
82
  noTimeout: -1,
83
83
 
84
84
  appendChildToContainer(container, child) {
85
- debug("appendChildToContainer", container, child);
85
+ debug("appendChildToContainer");
86
86
  appendNode(container.root, child);
87
87
  },
88
88
 
@@ -44,6 +44,10 @@ export class SkiaRoot {
44
44
  });
45
45
  }
46
46
 
47
+ unmount() {
48
+ skiaReconciler.updateContainer(null, this.root, null, () => {});
49
+ }
50
+
47
51
  get dom() {
48
52
  return this.container.root;
49
53
  }
@@ -40,7 +40,7 @@ export const processUniforms = (
40
40
  for (let i = 0; i < uniformsCount; i++) {
41
41
  const name = source.getUniformName(i);
42
42
  const value = uniforms[name];
43
- if (!value === undefined) {
43
+ if (value === undefined) {
44
44
  throw new Error(
45
45
  // eslint-disable-next-line max-len
46
46
  `The runtime effect has the uniform value "${name}" declared, but it is missing from the uniforms property of the Runtime effect.`
@@ -1,4 +1,4 @@
1
- import type { CanvasKit, Path } from "canvaskit-wasm";
1
+ import type { CanvasKit, Matrix3x3, Path } from "canvaskit-wasm";
2
2
 
3
3
  import { PathVerb } from "../types";
4
4
  import type {
@@ -11,6 +11,7 @@ import type {
11
11
  SkRect,
12
12
  InputRRect,
13
13
  StrokeOpts,
14
+ InputMatrix,
14
15
  } from "../types";
15
16
 
16
17
  import { getEnum, HostObject, optEnum } from "./Host";
@@ -339,8 +340,27 @@ export class JsiSkPath extends HostObject<Path, "Path"> implements SkPath {
339
340
  return result === null ? result : this;
340
341
  }
341
342
 
342
- transform(m3: SkMatrix) {
343
- this.ref.transform(Array.isArray(m3) ? m3 : JsiSkMatrix.fromValue(m3));
343
+ transform(m: InputMatrix) {
344
+ let matrix =
345
+ m instanceof JsiSkMatrix
346
+ ? Array.from(JsiSkMatrix.fromValue<Matrix3x3>(m))
347
+ : (m as Exclude<InputMatrix, SkMatrix>);
348
+ if (matrix.length === 16) {
349
+ matrix = [
350
+ matrix[0],
351
+ matrix[1],
352
+ matrix[3],
353
+ matrix[4],
354
+ matrix[5],
355
+ matrix[7],
356
+ matrix[12],
357
+ matrix[13],
358
+ matrix[15],
359
+ ];
360
+ } else if (matrix.length !== 9) {
361
+ throw new Error(`Invalid matrix length: ${matrix.length}`);
362
+ }
363
+ this.ref.transform(matrix);
344
364
  return this;
345
365
  }
346
366
 
@@ -0,0 +1,126 @@
1
+ import React from "react";
2
+ import type { HostComponent } from "react-native";
3
+
4
+ import type { Skia, SkRect } from "../skia/types";
5
+ import { Platform } from "../Platform";
6
+ import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeComponent";
7
+ import { JsiDrawingContext } from "../dom/types";
8
+
9
+ import { SkiaViewApi } from "./api";
10
+ import type { SkiaPictureViewProps, SkiaDomViewProps } from "./types";
11
+ import { SkiaViewNativeId } from "./SkiaViewNativeId";
12
+
13
+ const NativeSkiaPictureView: HostComponent<SkiaPictureViewProps> =
14
+ Platform.OS !== "web"
15
+ ? SkiaPictureViewNativeComponent
16
+ : // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
+ (null as any);
18
+
19
+ export class SkiaJSDomView extends React.Component<
20
+ SkiaDomViewProps & { Skia: Skia }
21
+ > {
22
+ constructor(props: SkiaDomViewProps & { Skia: Skia }) {
23
+ super(props);
24
+ this._nativeId = SkiaViewNativeId.current++;
25
+ const { root, onTouch, onSize } = props;
26
+ if (root) {
27
+ assertSkiaViewApi();
28
+ SkiaViewApi.setJsiProperty(this._nativeId, "root", root);
29
+ }
30
+ if (onTouch) {
31
+ assertSkiaViewApi();
32
+ SkiaViewApi.setJsiProperty(this._nativeId, "onTouch", onTouch);
33
+ }
34
+ if (onSize) {
35
+ assertSkiaViewApi();
36
+ SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
37
+ }
38
+ }
39
+
40
+ private _nativeId: number;
41
+
42
+ public get nativeId() {
43
+ return this._nativeId;
44
+ }
45
+
46
+ componentDidUpdate(prevProps: SkiaDomViewProps & { Skia: Skia }) {
47
+ const { root, onTouch, onSize } = this.props;
48
+ if (root !== prevProps.root && root !== undefined) {
49
+ assertSkiaViewApi();
50
+ this.draw();
51
+ }
52
+ if (onTouch !== prevProps.onTouch) {
53
+ assertSkiaViewApi();
54
+ SkiaViewApi.setJsiProperty(this._nativeId, "onTouch", onTouch);
55
+ }
56
+ if (onSize !== prevProps.onSize) {
57
+ assertSkiaViewApi();
58
+ SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Creates a snapshot from the canvas in the surface
64
+ * @param rect Rect to use as bounds. Optional.
65
+ * @returns An Image object.
66
+ */
67
+ public makeImageSnapshot(rect?: SkRect) {
68
+ assertSkiaViewApi();
69
+ return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);
70
+ }
71
+
72
+ /**
73
+ * Sends a redraw request to the native SkiaView.
74
+ */
75
+ public redraw() {
76
+ assertSkiaViewApi();
77
+ this.draw();
78
+ //SkiaViewApi.requestRedraw(this._nativeId);
79
+ }
80
+
81
+ private draw() {
82
+ const { root, Skia } = this.props;
83
+ if (root !== undefined) {
84
+ assertSkiaViewApi();
85
+ const rec = Skia.PictureRecorder();
86
+ const canvas = rec.beginRecording();
87
+ const ctx = new JsiDrawingContext(Skia, canvas);
88
+ root.render(ctx);
89
+ const picture = rec.finishRecordingAsPicture();
90
+ SkiaViewApi.setJsiProperty(this._nativeId, "picture", picture);
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Clear up the dom node when unmounting to release resources.
96
+ */
97
+ componentWillUnmount(): void {
98
+ assertSkiaViewApi();
99
+ SkiaViewApi.setJsiProperty(this._nativeId, "picture", null);
100
+ }
101
+
102
+ render() {
103
+ const { mode, debug = false, ...viewProps } = this.props;
104
+ return (
105
+ <NativeSkiaPictureView
106
+ collapsable={false}
107
+ nativeID={`${this._nativeId}`}
108
+ mode={mode}
109
+ debug={debug}
110
+ {...viewProps}
111
+ />
112
+ );
113
+ }
114
+ }
115
+
116
+ const assertSkiaViewApi = () => {
117
+ if (
118
+ SkiaViewApi === null ||
119
+ SkiaViewApi.setJsiProperty === null ||
120
+ SkiaViewApi.callJsiMethod === null ||
121
+ SkiaViewApi.requestRedraw === null ||
122
+ SkiaViewApi.makeImageSnapshot === null
123
+ ) {
124
+ throw Error("Skia View Api was not found.");
125
+ }
126
+ };
@@ -0,0 +1 @@
1
+ export { SkiaDomView as SkiaJSDomView } from "./SkiaDomView";
@@ -1,90 +0,0 @@
1
- #pragma once
2
-
3
- #include <memory>
4
- #include <string>
5
-
6
- #include <fbjni/fbjni.h>
7
- #include <jni.h>
8
- #include <jsi/jsi.h>
9
-
10
- #include <JniSkiaBaseView.h>
11
- #include <JniSkiaManager.h>
12
- #include <RNSkAndroidView.h>
13
- #include <RNSkJsView.h>
14
-
15
- #include <android/native_window.h>
16
- #include <android/native_window_jni.h>
17
- #include <fbjni/detail/Hybrid.h>
18
-
19
- namespace RNSkia {
20
- namespace jsi = facebook::jsi;
21
- namespace jni = facebook::jni;
22
-
23
- class JniSkiaDrawView : public jni::HybridClass<JniSkiaDrawView>,
24
- public JniSkiaBaseView {
25
- public:
26
- static auto constexpr kJavaDescriptor =
27
- "Lcom/shopify/reactnative/skia/SkiaDrawView;";
28
-
29
- static jni::local_ref<jhybriddata>
30
- initHybrid(jni::alias_ref<jhybridobject> jThis,
31
- jni::alias_ref<JniSkiaManager::javaobject> skiaManager) {
32
- return makeCxxInstance(jThis, skiaManager);
33
- }
34
-
35
- static void registerNatives() {
36
- registerHybrid(
37
- {makeNativeMethod("initHybrid", JniSkiaDrawView::initHybrid),
38
- makeNativeMethod("surfaceAvailable",
39
- JniSkiaDrawView::surfaceAvailable),
40
- makeNativeMethod("surfaceDestroyed",
41
- JniSkiaDrawView::surfaceDestroyed),
42
- makeNativeMethod("surfaceSizeChanged",
43
- JniSkiaDrawView::surfaceSizeChanged),
44
- makeNativeMethod("setMode", JniSkiaDrawView::setMode),
45
- makeNativeMethod("setDebugMode", JniSkiaDrawView::setDebugMode),
46
- makeNativeMethod("updateTouchPoints",
47
- JniSkiaDrawView::updateTouchPoints),
48
- makeNativeMethod("registerView", JniSkiaDrawView::registerView),
49
- makeNativeMethod("unregisterView", JniSkiaDrawView::unregisterView)});
50
- }
51
-
52
- protected:
53
- void updateTouchPoints(jni::JArrayDouble touches) override {
54
- JniSkiaBaseView::updateTouchPoints(touches);
55
- }
56
-
57
- void surfaceAvailable(jobject surface, int width, int height) override {
58
- JniSkiaBaseView::surfaceAvailable(surface, width, height);
59
- }
60
-
61
- void surfaceSizeChanged(int width, int height) override {
62
- JniSkiaBaseView::surfaceSizeChanged(width, height);
63
- }
64
-
65
- void surfaceDestroyed() override { JniSkiaBaseView::surfaceDestroyed(); }
66
-
67
- void setMode(std::string mode) override { JniSkiaBaseView::setMode(mode); }
68
-
69
- void setDebugMode(bool show) override { JniSkiaBaseView::setDebugMode(show); }
70
-
71
- void registerView(int nativeId) override {
72
- JniSkiaBaseView::registerView(nativeId);
73
- }
74
-
75
- void unregisterView() override { JniSkiaBaseView::unregisterView(); }
76
-
77
- private:
78
- friend HybridBase;
79
-
80
- explicit JniSkiaDrawView(
81
- jni::alias_ref<jhybridobject> jThis,
82
- jni::alias_ref<JniSkiaManager::javaobject> skiaManager)
83
- : JniSkiaBaseView(skiaManager,
84
- std::make_shared<RNSkAndroidView<RNSkia::RNSkJsView>>(
85
- skiaManager->cthis()->getPlatformContext())) {}
86
-
87
- jni::global_ref<javaobject> javaPart_;
88
- };
89
-
90
- } // namespace RNSkia