@shopify/react-native-skia 0.1.145 → 0.1.146

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  import type { ViewProps } from "react-native";
2
- import type { SkImage, SkRect, SkCanvas } from "../skia/types";
2
+ import type { SkCanvas, SkImage, SkRect } from "../skia/types";
3
3
  import type { SkiaValue } from "../values";
4
4
  export declare type DrawMode = "continuous" | "default";
5
5
  export declare type NativeSkiaViewProps = ViewProps & {
@@ -45,11 +45,11 @@ export interface ValueListener {
45
45
  removeListener: (id: number) => void;
46
46
  }
47
47
  export interface ISkiaViewApi {
48
- invalidateSkiaView: (nativeId: number) => void;
49
- makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;
50
- setDrawCallback: (nativeId: number, callback: RNSkiaDrawCallback | undefined) => void;
51
- setDrawMode: (nativeId: number, mode: DrawMode) => void;
48
+ setJsiProperty: <T>(nativeId: number, name: string, value: T) => void;
49
+ callJsiMethod: <T extends Array<unknown>>(nativeId: number, name: string, ...args: T) => void;
52
50
  registerValuesInView: (nativeId: number, values: SkiaValue<unknown>[]) => () => void;
51
+ requestRedraw: (nativeId: number) => void;
52
+ makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;
53
53
  }
54
54
  export interface SkiaViewProps extends ViewProps {
55
55
  /**
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.145",
10
+ "version": "0.1.146",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "files": [
@@ -265,7 +265,17 @@ export const skHostConfig: SkiaHostConfig = {
265
265
  return;
266
266
  }
267
267
  bustBranchMemoization(instance);
268
- instance.props = nextProps;
268
+ if (instance instanceof DrawingNode) {
269
+ const { onDraw, skipProcessing, ...props } = nextProps;
270
+ instance.props = props;
271
+ } else if (instance instanceof DeclarationNode) {
272
+ const { onDeclare, ...props } = nextProps;
273
+ instance.props = props;
274
+ } else {
275
+ throw new Error(
276
+ "Unsupported instance commitUpdate " + instance.constructor.name
277
+ );
278
+ }
269
279
  },
270
280
 
271
281
  commitTextUpdate: (
@@ -5,7 +5,7 @@ import type { SkRect } from "../skia/types";
5
5
  import type { SkiaValue } from "../values";
6
6
 
7
7
  import { SkiaViewApi } from "./api";
8
- import type { DrawMode, NativeSkiaViewProps, SkiaViewProps } from "./types";
8
+ import type { NativeSkiaViewProps, SkiaViewProps } from "./types";
9
9
 
10
10
  let SkiaViewNativeId = 1000;
11
11
 
@@ -19,8 +19,8 @@ export class SkiaView extends React.Component<SkiaViewProps> {
19
19
  this._nativeId = SkiaViewNativeId++;
20
20
  const { onDraw } = props;
21
21
  if (onDraw) {
22
- assertDrawCallbacksEnabled();
23
- SkiaViewApi.setDrawCallback(this._nativeId, onDraw);
22
+ assertSkiaViewApi();
23
+ SkiaViewApi.setJsiProperty(this._nativeId, "drawCallback", onDraw);
24
24
  }
25
25
  }
26
26
 
@@ -33,8 +33,8 @@ export class SkiaView extends React.Component<SkiaViewProps> {
33
33
  componentDidUpdate(prevProps: SkiaViewProps) {
34
34
  const { onDraw } = this.props;
35
35
  if (onDraw !== prevProps.onDraw) {
36
- assertDrawCallbacksEnabled();
37
- SkiaViewApi.setDrawCallback(this._nativeId, onDraw);
36
+ assertSkiaViewApi();
37
+ SkiaViewApi.setJsiProperty(this._nativeId, "drawCallback", onDraw);
38
38
  }
39
39
  }
40
40
 
@@ -44,7 +44,7 @@ export class SkiaView extends React.Component<SkiaViewProps> {
44
44
  * @returns An Image object.
45
45
  */
46
46
  public makeImageSnapshot(rect?: SkRect) {
47
- assertDrawCallbacksEnabled();
47
+ assertSkiaViewApi();
48
48
  return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);
49
49
  }
50
50
 
@@ -52,22 +52,8 @@ export class SkiaView extends React.Component<SkiaViewProps> {
52
52
  * Sends a redraw request to the native SkiaView.
53
53
  */
54
54
  public redraw() {
55
- assertDrawCallbacksEnabled();
56
- SkiaViewApi.invalidateSkiaView(this._nativeId);
57
- }
58
-
59
- /**
60
- * Updates the drawing mode for the skia view. This is the same
61
- * as declaratively setting the mode property on the SkiaView.
62
- * There are two drawing modes, "continuous" and "default",
63
- * where the continuous mode will continuously redraw the view and
64
- * the default mode will only redraw when any of the regular react
65
- * properties are changed like size and margins.
66
- * @param mode Drawing mode to use.
67
- */
68
- public setDrawMode(mode: DrawMode) {
69
- assertDrawCallbacksEnabled();
70
- SkiaViewApi.setDrawMode(this._nativeId, mode);
55
+ assertSkiaViewApi();
56
+ SkiaViewApi.requestRedraw(this._nativeId);
71
57
  }
72
58
 
73
59
  /**
@@ -75,8 +61,8 @@ export class SkiaView extends React.Component<SkiaViewProps> {
75
61
  * The view will redraw itself when any of the values change.
76
62
  * @param values Values to register
77
63
  */
78
- public registerValues(values: SkiaValue<unknown>[]) {
79
- assertDrawCallbacksEnabled();
64
+ public registerValues(values: SkiaValue<unknown>[]): () => void {
65
+ assertSkiaViewApi();
80
66
  return SkiaViewApi.registerValuesInView(this._nativeId, values);
81
67
  }
82
68
 
@@ -94,12 +80,15 @@ export class SkiaView extends React.Component<SkiaViewProps> {
94
80
  }
95
81
  }
96
82
 
97
- const assertDrawCallbacksEnabled = () => {
83
+ const assertSkiaViewApi = () => {
98
84
  if (
99
85
  SkiaViewApi === null ||
100
- SkiaViewApi.setDrawCallback == null ||
101
- SkiaViewApi.invalidateSkiaView == null
86
+ SkiaViewApi.setJsiProperty === null ||
87
+ SkiaViewApi.callJsiMethod === null ||
88
+ SkiaViewApi.registerValuesInView === null ||
89
+ SkiaViewApi.requestRedraw === null ||
90
+ SkiaViewApi.makeImageSnapshot === null
102
91
  ) {
103
- throw Error("Skia Api is not enabled.");
92
+ throw Error("Skia View Api was not found.");
104
93
  }
105
94
  };
@@ -1,6 +1,6 @@
1
1
  import type { ViewProps } from "react-native";
2
2
 
3
- import type { SkImage, SkRect, SkCanvas } from "../skia/types";
3
+ import type { SkCanvas, SkImage, SkRect } from "../skia/types";
4
4
  import type { SkiaValue } from "../values";
5
5
 
6
6
  export type DrawMode = "continuous" | "default";
@@ -58,17 +58,18 @@ export interface ValueListener {
58
58
  }
59
59
 
60
60
  export interface ISkiaViewApi {
61
- invalidateSkiaView: (nativeId: number) => void;
62
- makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;
63
- setDrawCallback: (
61
+ setJsiProperty: <T>(nativeId: number, name: string, value: T) => void;
62
+ callJsiMethod: <T extends Array<unknown>>(
64
63
  nativeId: number,
65
- callback: RNSkiaDrawCallback | undefined
64
+ name: string,
65
+ ...args: T
66
66
  ) => void;
67
- setDrawMode: (nativeId: number, mode: DrawMode) => void;
68
67
  registerValuesInView: (
69
68
  nativeId: number,
70
69
  values: SkiaValue<unknown>[]
71
70
  ) => () => void;
71
+ requestRedraw: (nativeId: number) => void;
72
+ makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;
72
73
  }
73
74
 
74
75
  export interface SkiaViewProps extends ViewProps {