@shopify/react-native-skia 0.1.145 → 0.1.147

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 (44) hide show
  1. package/cpp/api/JsiSkContourMeasure.h +4 -4
  2. package/cpp/api/JsiSkDataFactory.h +3 -3
  3. package/cpp/api/JsiSkFont.h +1 -1
  4. package/cpp/api/JsiSkMatrix.h +9 -0
  5. package/cpp/api/JsiSkPath.h +2 -2
  6. package/cpp/api/JsiSkPathFactory.h +1 -1
  7. package/cpp/api/JsiSkPictureFactory.h +1 -1
  8. package/cpp/api/JsiSkRuntimeEffect.h +6 -6
  9. package/cpp/api/JsiSkRuntimeEffectFactory.h +1 -1
  10. package/cpp/jsi/JsiSimpleValueWrapper.h +27 -27
  11. package/cpp/jsi/JsiValueWrapper.h +127 -0
  12. package/cpp/rnskia/RNSkDrawView.cpp +41 -17
  13. package/cpp/rnskia/RNSkDrawView.h +17 -19
  14. package/cpp/rnskia/RNSkJsiViewApi.h +180 -166
  15. package/cpp/rnskia/values/RNSkComputedValue.h +11 -11
  16. package/cpp/rnskia/values/RNSkReadonlyValue.h +19 -19
  17. package/cpp/rnskia/values/RNSkValue.h +13 -13
  18. package/cpp/utils/RNSkLog.h +4 -4
  19. package/lib/commonjs/renderer/HostConfig.js +17 -1
  20. package/lib/commonjs/renderer/HostConfig.js.map +1 -1
  21. package/lib/commonjs/skia/types/Matrix.js.map +1 -1
  22. package/lib/commonjs/skia/web/JsiSkMatrix.js +4 -0
  23. package/lib/commonjs/skia/web/JsiSkMatrix.js.map +1 -1
  24. package/lib/commonjs/views/SkiaView.js +11 -27
  25. package/lib/commonjs/views/SkiaView.js.map +1 -1
  26. package/lib/commonjs/views/types.js.map +1 -1
  27. package/lib/module/renderer/HostConfig.js +17 -1
  28. package/lib/module/renderer/HostConfig.js.map +1 -1
  29. package/lib/module/skia/types/Matrix.js.map +1 -1
  30. package/lib/module/skia/web/JsiSkMatrix.js +4 -0
  31. package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
  32. package/lib/module/views/SkiaView.js +11 -26
  33. package/lib/module/views/SkiaView.js.map +1 -1
  34. package/lib/module/views/types.js.map +1 -1
  35. package/lib/typescript/src/skia/types/Matrix.d.ts +1 -0
  36. package/lib/typescript/src/skia/web/JsiSkMatrix.d.ts +1 -0
  37. package/lib/typescript/src/views/SkiaView.d.ts +1 -11
  38. package/lib/typescript/src/views/types.d.ts +5 -5
  39. package/package.json +1 -1
  40. package/src/renderer/HostConfig.ts +11 -1
  41. package/src/skia/types/Matrix.ts +1 -0
  42. package/src/skia/web/JsiSkMatrix.ts +4 -0
  43. package/src/views/SkiaView.tsx +17 -28
  44. package/src/views/types.ts +7 -6
@@ -19,8 +19,8 @@ export class SkiaView extends React.Component {
19
19
  } = props;
20
20
 
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
 
@@ -34,8 +34,8 @@ export class SkiaView extends React.Component {
34
34
  } = this.props;
35
35
 
36
36
  if (onDraw !== prevProps.onDraw) {
37
- assertDrawCallbacksEnabled();
38
- SkiaViewApi.setDrawCallback(this._nativeId, onDraw);
37
+ assertSkiaViewApi();
38
+ SkiaViewApi.setJsiProperty(this._nativeId, "drawCallback", onDraw);
39
39
  }
40
40
  }
41
41
  /**
@@ -46,7 +46,7 @@ export class SkiaView extends React.Component {
46
46
 
47
47
 
48
48
  makeImageSnapshot(rect) {
49
- assertDrawCallbacksEnabled();
49
+ assertSkiaViewApi();
50
50
  return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);
51
51
  }
52
52
  /**
@@ -55,23 +55,8 @@ export class SkiaView extends React.Component {
55
55
 
56
56
 
57
57
  redraw() {
58
- assertDrawCallbacksEnabled();
59
- SkiaViewApi.invalidateSkiaView(this._nativeId);
60
- }
61
- /**
62
- * Updates the drawing mode for the skia view. This is the same
63
- * as declaratively setting the mode property on the SkiaView.
64
- * There are two drawing modes, "continuous" and "default",
65
- * where the continuous mode will continuously redraw the view and
66
- * the default mode will only redraw when any of the regular react
67
- * properties are changed like size and margins.
68
- * @param mode Drawing mode to use.
69
- */
70
-
71
-
72
- setDrawMode(mode) {
73
- assertDrawCallbacksEnabled();
74
- SkiaViewApi.setDrawMode(this._nativeId, mode);
58
+ assertSkiaViewApi();
59
+ SkiaViewApi.requestRedraw(this._nativeId);
75
60
  }
76
61
  /**
77
62
  * Registers one or move values as a dependant value of the Skia View. The view will
@@ -81,7 +66,7 @@ export class SkiaView extends React.Component {
81
66
 
82
67
 
83
68
  registerValues(values) {
84
- assertDrawCallbacksEnabled();
69
+ assertSkiaViewApi();
85
70
  return SkiaViewApi.registerValuesInView(this._nativeId, values);
86
71
  }
87
72
 
@@ -101,9 +86,9 @@ export class SkiaView extends React.Component {
101
86
 
102
87
  }
103
88
 
104
- const assertDrawCallbacksEnabled = () => {
105
- if (SkiaViewApi === null || SkiaViewApi.setDrawCallback == null || SkiaViewApi.invalidateSkiaView == null) {
106
- throw Error("Skia Api is not enabled.");
89
+ const assertSkiaViewApi = () => {
90
+ if (SkiaViewApi === null || SkiaViewApi.setJsiProperty === null || SkiaViewApi.callJsiMethod === null || SkiaViewApi.registerValuesInView === null || SkiaViewApi.requestRedraw === null || SkiaViewApi.makeImageSnapshot === null) {
91
+ throw Error("Skia View Api was not found.");
107
92
  }
108
93
  };
109
94
  //# sourceMappingURL=SkiaView.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["SkiaView.tsx"],"names":["React","requireNativeComponent","SkiaViewApi","SkiaViewNativeId","NativeSkiaView","SkiaView","Component","constructor","props","_nativeId","onDraw","assertDrawCallbacksEnabled","setDrawCallback","nativeId","componentDidUpdate","prevProps","makeImageSnapshot","rect","redraw","invalidateSkiaView","setDrawMode","mode","registerValues","values","registerValuesInView","render","debug","viewProps","Error"],"mappings":";;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,sBAAT,QAAuC,cAAvC;AAKA,SAASC,WAAT,QAA4B,OAA5B;AAGA,IAAIC,gBAAgB,GAAG,IAAvB;AAEA,MAAMC,cAAc,GAAGH,sBAAsB,CAC3C,qBAD2C,CAA7C;AAIA,OAAO,MAAMI,QAAN,SAAuBL,KAAK,CAACM,SAA7B,CAAsD;AAC3DC,EAAAA,WAAW,CAACC,KAAD,EAAuB;AAChC,UAAMA,KAAN;;AADgC;;AAEhC,SAAKC,SAAL,GAAiBN,gBAAgB,EAAjC;AACA,UAAM;AAAEO,MAAAA;AAAF,QAAaF,KAAnB;;AACA,QAAIE,MAAJ,EAAY;AACVC,MAAAA,0BAA0B;AAC1BT,MAAAA,WAAW,CAACU,eAAZ,CAA4B,KAAKH,SAAjC,EAA4CC,MAA5C;AACD;AACF;;AAIkB,MAARG,QAAQ,GAAG;AACpB,WAAO,KAAKJ,SAAZ;AACD;;AAEDK,EAAAA,kBAAkB,CAACC,SAAD,EAA2B;AAC3C,UAAM;AAAEL,MAAAA;AAAF,QAAa,KAAKF,KAAxB;;AACA,QAAIE,MAAM,KAAKK,SAAS,CAACL,MAAzB,EAAiC;AAC/BC,MAAAA,0BAA0B;AAC1BT,MAAAA,WAAW,CAACU,eAAZ,CAA4B,KAAKH,SAAjC,EAA4CC,MAA5C;AACD;AACF;AAED;AACF;AACA;AACA;AACA;;;AACSM,EAAAA,iBAAiB,CAACC,IAAD,EAAgB;AACtCN,IAAAA,0BAA0B;AAC1B,WAAOT,WAAW,CAACc,iBAAZ,CAA8B,KAAKP,SAAnC,EAA8CQ,IAA9C,CAAP;AACD;AAED;AACF;AACA;;;AACSC,EAAAA,MAAM,GAAG;AACdP,IAAAA,0BAA0B;AAC1BT,IAAAA,WAAW,CAACiB,kBAAZ,CAA+B,KAAKV,SAApC;AACD;AAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACSW,EAAAA,WAAW,CAACC,IAAD,EAAiB;AACjCV,IAAAA,0BAA0B;AAC1BT,IAAAA,WAAW,CAACkB,WAAZ,CAAwB,KAAKX,SAA7B,EAAwCY,IAAxC;AACD;AAED;AACF;AACA;AACA;AACA;;;AACSC,EAAAA,cAAc,CAACC,MAAD,EAA+B;AAClDZ,IAAAA,0BAA0B;AAC1B,WAAOT,WAAW,CAACsB,oBAAZ,CAAiC,KAAKf,SAAtC,EAAiDc,MAAjD,CAAP;AACD;;AAEDE,EAAAA,MAAM,GAAG;AACP,UAAM;AAAEJ,MAAAA,IAAF;AAAQK,MAAAA,KAAK,GAAG,KAAhB;AAAuB,SAAGC;AAA1B,QAAwC,KAAKnB,KAAnD;AACA,wBACE,oBAAC,cAAD;AACE,MAAA,WAAW,EAAE,KADf;AAEE,MAAA,QAAQ,EAAG,GAAE,KAAKC,SAAU,EAF9B;AAGE,MAAA,IAAI,EAAEY,IAHR;AAIE,MAAA,KAAK,EAAEK;AAJT,OAKMC,SALN,EADF;AASD;;AA9E0D;;AAiF7D,MAAMhB,0BAA0B,GAAG,MAAM;AACvC,MACET,WAAW,KAAK,IAAhB,IACAA,WAAW,CAACU,eAAZ,IAA+B,IAD/B,IAEAV,WAAW,CAACiB,kBAAZ,IAAkC,IAHpC,EAIE;AACA,UAAMS,KAAK,CAAC,0BAAD,CAAX;AACD;AACF,CARD","sourcesContent":["import React from \"react\";\nimport { requireNativeComponent } from \"react-native\";\n\nimport type { SkRect } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\n\nimport { SkiaViewApi } from \"./api\";\nimport type { DrawMode, NativeSkiaViewProps, SkiaViewProps } from \"./types\";\n\nlet SkiaViewNativeId = 1000;\n\nconst NativeSkiaView = requireNativeComponent<NativeSkiaViewProps>(\n \"ReactNativeSkiaView\"\n);\n\nexport class SkiaView extends React.Component<SkiaViewProps> {\n constructor(props: SkiaViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId++;\n const { onDraw } = props;\n if (onDraw) {\n assertDrawCallbacksEnabled();\n SkiaViewApi.setDrawCallback(this._nativeId, onDraw);\n }\n }\n\n private _nativeId: number;\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaViewProps) {\n const { onDraw } = this.props;\n if (onDraw !== prevProps.onDraw) {\n assertDrawCallbacksEnabled();\n SkiaViewApi.setDrawCallback(this._nativeId, onDraw);\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 assertDrawCallbacksEnabled();\n return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n public redraw() {\n assertDrawCallbacksEnabled();\n SkiaViewApi.invalidateSkiaView(this._nativeId);\n }\n\n /**\n * Updates the drawing mode for the skia view. This is the same\n * as declaratively setting the mode property on the SkiaView.\n * There are two drawing modes, \"continuous\" and \"default\",\n * where the continuous mode will continuously redraw the view and\n * the default mode will only redraw when any of the regular react\n * properties are changed like size and margins.\n * @param mode Drawing mode to use.\n */\n public setDrawMode(mode: DrawMode) {\n assertDrawCallbacksEnabled();\n SkiaViewApi.setDrawMode(this._nativeId, mode);\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(values: SkiaValue<unknown>[]) {\n assertDrawCallbacksEnabled();\n return SkiaViewApi.registerValuesInView(this._nativeId, values);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <NativeSkiaView\n collapsable={false}\n nativeID={`${this._nativeId}`}\n mode={mode}\n debug={debug}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertDrawCallbacksEnabled = () => {\n if (\n SkiaViewApi === null ||\n SkiaViewApi.setDrawCallback == null ||\n SkiaViewApi.invalidateSkiaView == null\n ) {\n throw Error(\"Skia Api is not enabled.\");\n }\n};\n"]}
1
+ {"version":3,"sources":["SkiaView.tsx"],"names":["React","requireNativeComponent","SkiaViewApi","SkiaViewNativeId","NativeSkiaView","SkiaView","Component","constructor","props","_nativeId","onDraw","assertSkiaViewApi","setJsiProperty","nativeId","componentDidUpdate","prevProps","makeImageSnapshot","rect","redraw","requestRedraw","registerValues","values","registerValuesInView","render","mode","debug","viewProps","callJsiMethod","Error"],"mappings":";;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,sBAAT,QAAuC,cAAvC;AAKA,SAASC,WAAT,QAA4B,OAA5B;AAGA,IAAIC,gBAAgB,GAAG,IAAvB;AAEA,MAAMC,cAAc,GAAGH,sBAAsB,CAC3C,qBAD2C,CAA7C;AAIA,OAAO,MAAMI,QAAN,SAAuBL,KAAK,CAACM,SAA7B,CAAsD;AAC3DC,EAAAA,WAAW,CAACC,KAAD,EAAuB;AAChC,UAAMA,KAAN;;AADgC;;AAEhC,SAAKC,SAAL,GAAiBN,gBAAgB,EAAjC;AACA,UAAM;AAAEO,MAAAA;AAAF,QAAaF,KAAnB;;AACA,QAAIE,MAAJ,EAAY;AACVC,MAAAA,iBAAiB;AACjBT,MAAAA,WAAW,CAACU,cAAZ,CAA2B,KAAKH,SAAhC,EAA2C,cAA3C,EAA2DC,MAA3D;AACD;AACF;;AAIkB,MAARG,QAAQ,GAAG;AACpB,WAAO,KAAKJ,SAAZ;AACD;;AAEDK,EAAAA,kBAAkB,CAACC,SAAD,EAA2B;AAC3C,UAAM;AAAEL,MAAAA;AAAF,QAAa,KAAKF,KAAxB;;AACA,QAAIE,MAAM,KAAKK,SAAS,CAACL,MAAzB,EAAiC;AAC/BC,MAAAA,iBAAiB;AACjBT,MAAAA,WAAW,CAACU,cAAZ,CAA2B,KAAKH,SAAhC,EAA2C,cAA3C,EAA2DC,MAA3D;AACD;AACF;AAED;AACF;AACA;AACA;AACA;;;AACSM,EAAAA,iBAAiB,CAACC,IAAD,EAAgB;AACtCN,IAAAA,iBAAiB;AACjB,WAAOT,WAAW,CAACc,iBAAZ,CAA8B,KAAKP,SAAnC,EAA8CQ,IAA9C,CAAP;AACD;AAED;AACF;AACA;;;AACSC,EAAAA,MAAM,GAAG;AACdP,IAAAA,iBAAiB;AACjBT,IAAAA,WAAW,CAACiB,aAAZ,CAA0B,KAAKV,SAA/B;AACD;AAED;AACF;AACA;AACA;AACA;;;AACSW,EAAAA,cAAc,CAACC,MAAD,EAA2C;AAC9DV,IAAAA,iBAAiB;AACjB,WAAOT,WAAW,CAACoB,oBAAZ,CAAiC,KAAKb,SAAtC,EAAiDY,MAAjD,CAAP;AACD;;AAEDE,EAAAA,MAAM,GAAG;AACP,UAAM;AAAEC,MAAAA,IAAF;AAAQC,MAAAA,KAAK,GAAG,KAAhB;AAAuB,SAAGC;AAA1B,QAAwC,KAAKlB,KAAnD;AACA,wBACE,oBAAC,cAAD;AACE,MAAA,WAAW,EAAE,KADf;AAEE,MAAA,QAAQ,EAAG,GAAE,KAAKC,SAAU,EAF9B;AAGE,MAAA,IAAI,EAAEe,IAHR;AAIE,MAAA,KAAK,EAAEC;AAJT,OAKMC,SALN,EADF;AASD;;AAhE0D;;AAmE7D,MAAMf,iBAAiB,GAAG,MAAM;AAC9B,MACET,WAAW,KAAK,IAAhB,IACAA,WAAW,CAACU,cAAZ,KAA+B,IAD/B,IAEAV,WAAW,CAACyB,aAAZ,KAA8B,IAF9B,IAGAzB,WAAW,CAACoB,oBAAZ,KAAqC,IAHrC,IAIApB,WAAW,CAACiB,aAAZ,KAA8B,IAJ9B,IAKAjB,WAAW,CAACc,iBAAZ,KAAkC,IANpC,EAOE;AACA,UAAMY,KAAK,CAAC,8BAAD,CAAX;AACD;AACF,CAXD","sourcesContent":["import React from \"react\";\nimport { requireNativeComponent } from \"react-native\";\n\nimport type { SkRect } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\n\nimport { SkiaViewApi } from \"./api\";\nimport type { NativeSkiaViewProps, SkiaViewProps } from \"./types\";\n\nlet SkiaViewNativeId = 1000;\n\nconst NativeSkiaView = requireNativeComponent<NativeSkiaViewProps>(\n \"ReactNativeSkiaView\"\n);\n\nexport class SkiaView extends React.Component<SkiaViewProps> {\n constructor(props: SkiaViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId++;\n const { onDraw } = props;\n if (onDraw) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"drawCallback\", onDraw);\n }\n }\n\n private _nativeId: number;\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaViewProps) {\n const { onDraw } = this.props;\n if (onDraw !== prevProps.onDraw) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"drawCallback\", onDraw);\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 SkiaViewApi.requestRedraw(this._nativeId);\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(values: SkiaValue<unknown>[]): () => void {\n assertSkiaViewApi();\n return SkiaViewApi.registerValuesInView(this._nativeId, values);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <NativeSkiaView\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.registerValuesInView === null ||\n SkiaViewApi.requestRedraw === null ||\n SkiaViewApi.makeImageSnapshot === null\n ) {\n throw Error(\"Skia View Api was not found.\");\n }\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["types.ts"],"names":["TouchType"],"mappings":"AAYA,WAAYA,SAAZ;;WAAYA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;GAAAA,S,KAAAA,S","sourcesContent":["import type { ViewProps } from \"react-native\";\n\nimport type { SkImage, SkRect, SkCanvas } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\n\nexport type DrawMode = \"continuous\" | \"default\";\n\nexport type NativeSkiaViewProps = ViewProps & {\n mode?: DrawMode;\n debug?: boolean;\n};\n\nexport enum TouchType {\n Start,\n Active,\n End,\n Cancelled,\n}\n\nexport interface TouchInfo {\n x: number;\n y: number;\n force: number;\n type: TouchType;\n id: number;\n timestamp: number;\n}\n\nexport interface DrawingInfo {\n width: number;\n height: number;\n timestamp: number;\n touches: Array<Array<TouchInfo>>;\n}\n\nexport type ExtendedTouchInfo = TouchInfo & {\n // points per second\n velocityX: number;\n velocityY: number;\n};\n\nexport type TouchHandlers = {\n onStart?: (touchInfo: TouchInfo) => void;\n onActive?: (touchInfo: ExtendedTouchInfo) => void;\n onEnd?: (touchInfo: ExtendedTouchInfo) => void;\n};\n\nexport type TouchHandler = (touchInfo: Array<Array<TouchInfo>>) => void;\n\nexport type RNSkiaDrawCallback = (canvas: SkCanvas, info: DrawingInfo) => void;\n\n/**\n * Listener interface for value changes\n */\nexport interface ValueListener {\n addListener: (callback: () => void) => number;\n removeListener: (id: number) => void;\n}\n\nexport interface ISkiaViewApi {\n invalidateSkiaView: (nativeId: number) => void;\n makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;\n setDrawCallback: (\n nativeId: number,\n callback: RNSkiaDrawCallback | undefined\n ) => void;\n setDrawMode: (nativeId: number, mode: DrawMode) => void;\n registerValuesInView: (\n nativeId: number,\n values: SkiaValue<unknown>[]\n ) => () => void;\n}\n\nexport interface SkiaViewProps extends ViewProps {\n /**\n * Sets the drawing mode for the skia view. There are two drawing\n * modes, \"continuous\" and \"default\", where the continuous mode will\n * continuously redraw the view, and the default mode will only\n * redraw when any of the regular react properties are changed like\n * sizes and margins.\n */\n mode?: DrawMode;\n /**\n * When set to true the view will display information about the\n * average time it takes to render.\n */\n debug?: boolean;\n /**\n * Draw callback. Will be called whenever the view is invalidated and\n * needs to redraw. This is either caused by a change in a react\n * property, a touch event, or a call to redraw. If the view is in\n * continuous mode the callback will be called 60 frames per second\n * by the native view.\n */\n onDraw?: RNSkiaDrawCallback;\n}\n"]}
1
+ {"version":3,"sources":["types.ts"],"names":["TouchType"],"mappings":"AAYA,WAAYA,SAAZ;;WAAYA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;GAAAA,S,KAAAA,S","sourcesContent":["import type { ViewProps } from \"react-native\";\n\nimport type { SkCanvas, SkImage, SkRect } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\n\nexport type DrawMode = \"continuous\" | \"default\";\n\nexport type NativeSkiaViewProps = ViewProps & {\n mode?: DrawMode;\n debug?: boolean;\n};\n\nexport enum TouchType {\n Start,\n Active,\n End,\n Cancelled,\n}\n\nexport interface TouchInfo {\n x: number;\n y: number;\n force: number;\n type: TouchType;\n id: number;\n timestamp: number;\n}\n\nexport interface DrawingInfo {\n width: number;\n height: number;\n timestamp: number;\n touches: Array<Array<TouchInfo>>;\n}\n\nexport type ExtendedTouchInfo = TouchInfo & {\n // points per second\n velocityX: number;\n velocityY: number;\n};\n\nexport type TouchHandlers = {\n onStart?: (touchInfo: TouchInfo) => void;\n onActive?: (touchInfo: ExtendedTouchInfo) => void;\n onEnd?: (touchInfo: ExtendedTouchInfo) => void;\n};\n\nexport type TouchHandler = (touchInfo: Array<Array<TouchInfo>>) => void;\n\nexport type RNSkiaDrawCallback = (canvas: SkCanvas, info: DrawingInfo) => void;\n\n/**\n * Listener interface for value changes\n */\nexport interface ValueListener {\n addListener: (callback: () => void) => number;\n removeListener: (id: number) => void;\n}\n\nexport interface ISkiaViewApi {\n setJsiProperty: <T>(nativeId: number, name: string, value: T) => void;\n callJsiMethod: <T extends Array<unknown>>(\n nativeId: number,\n name: string,\n ...args: T\n ) => void;\n registerValuesInView: (\n nativeId: number,\n values: SkiaValue<unknown>[]\n ) => () => void;\n requestRedraw: (nativeId: number) => void;\n makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;\n}\n\nexport interface SkiaViewProps extends ViewProps {\n /**\n * Sets the drawing mode for the skia view. There are two drawing\n * modes, \"continuous\" and \"default\", where the continuous mode will\n * continuously redraw the view, and the default mode will only\n * redraw when any of the regular react properties are changed like\n * sizes and margins.\n */\n mode?: DrawMode;\n /**\n * When set to true the view will display information about the\n * average time it takes to render.\n */\n debug?: boolean;\n /**\n * Draw callback. Will be called whenever the view is invalidated and\n * needs to redraw. This is either caused by a change in a react\n * property, a touch event, or a call to redraw. If the view is in\n * continuous mode the callback will be called 60 frames per second\n * by the native view.\n */\n onDraw?: RNSkiaDrawCallback;\n}\n"]}
@@ -19,6 +19,7 @@ export interface SkMatrix extends SkJSIInstance<"Matrix"> {
19
19
  skew: (x: number, y: number) => void;
20
20
  rotate: (theta: number) => void;
21
21
  identity: () => void;
22
+ get: () => number[];
22
23
  }
23
24
  declare type Transform2dName = "translateX" | "translateY" | "scale" | "skewX" | "skewY" | "scaleX" | "scaleY" | "rotateZ" | "rotate";
24
25
  declare type Transformations = {
@@ -9,4 +9,5 @@ export declare class JsiSkMatrix extends HostObject<Matrix3x3, "Matrix"> impleme
9
9
  skew(x: number, y: number): void;
10
10
  rotate(value: number): void;
11
11
  identity(): void;
12
+ get(): number[];
12
13
  }
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import type { SkRect } from "../skia/types";
3
3
  import type { SkiaValue } from "../values";
4
- import type { DrawMode, SkiaViewProps } from "./types";
4
+ import type { SkiaViewProps } from "./types";
5
5
  export declare class SkiaView extends React.Component<SkiaViewProps> {
6
6
  constructor(props: SkiaViewProps);
7
7
  private _nativeId;
@@ -17,16 +17,6 @@ export declare class SkiaView extends React.Component<SkiaViewProps> {
17
17
  * Sends a redraw request to the native SkiaView.
18
18
  */
19
19
  redraw(): void;
20
- /**
21
- * Updates the drawing mode for the skia view. This is the same
22
- * as declaratively setting the mode property on the SkiaView.
23
- * There are two drawing modes, "continuous" and "default",
24
- * where the continuous mode will continuously redraw the view and
25
- * the default mode will only redraw when any of the regular react
26
- * properties are changed like size and margins.
27
- * @param mode Drawing mode to use.
28
- */
29
- setDrawMode(mode: DrawMode): void;
30
20
  /**
31
21
  * Registers one or move values as a dependant value of the Skia View. The view will
32
22
  * The view will redraw itself when any of the values change.
@@ -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.147",
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: (
@@ -22,6 +22,7 @@ export interface SkMatrix extends SkJSIInstance<"Matrix"> {
22
22
  skew: (x: number, y: number) => void;
23
23
  rotate: (theta: number) => void;
24
24
  identity: () => void;
25
+ get: () => number[];
25
26
  }
26
27
 
27
28
  type Transform2dName =
@@ -57,4 +57,8 @@ export class JsiSkMatrix
57
57
  identity() {
58
58
  this.ref.set(this.CanvasKit.Matrix.identity());
59
59
  }
60
+
61
+ get() {
62
+ return Array.from(this.ref);
63
+ }
60
64
  }
@@ -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 {