@shopify/react-native-skia 1.7.4 → 1.7.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -75,8 +75,6 @@ public abstract class SkiaBaseView extends ReactViewGroup implements SkiaViewAPI
75
75
 
76
76
  protected abstract void surfaceDestroyed();
77
77
 
78
- protected abstract void setMode(String mode);
79
-
80
78
  protected abstract void setDebugMode(boolean show);
81
79
 
82
80
  protected abstract void registerView(int nativeId);
@@ -16,11 +16,6 @@ public abstract class SkiaBaseViewManager<T extends SkiaBaseView> extends ReactV
16
16
  ((SkiaBaseView)view).registerView(nativeIdResolved);
17
17
  }
18
18
 
19
- @ReactProp(name = "mode")
20
- public void setMode(T view, String mode) {
21
- ((SkiaBaseView)view).setMode(mode);
22
- }
23
-
24
19
  @ReactProp(name = "debug")
25
20
  public void setDebug(T view, boolean show) {
26
21
  ((SkiaBaseView)view).setDebugMode(show);
@@ -33,8 +33,6 @@ public class SkiaDomView extends SkiaBaseView {
33
33
 
34
34
  protected native void setBgColor(int color);
35
35
 
36
- protected native void setMode(String mode);
37
-
38
36
  protected native void setDebugMode(boolean show);
39
37
 
40
38
  protected native void registerView(int nativeId);
@@ -32,8 +32,6 @@ public class SkiaPictureView extends SkiaBaseView {
32
32
 
33
33
  protected native void setBgColor(int color);
34
34
 
35
- protected native void setMode(String mode);
36
-
37
35
  protected native void setDebugMode(boolean show);
38
36
 
39
37
  protected native void registerView(int nativeId);
@@ -21,9 +21,6 @@ public class SkiaPictureViewManagerDelegate<T extends View, U extends BaseViewMa
21
21
  @Override
22
22
  public void setProperty(T view, String propName, @Nullable Object value) {
23
23
  switch (propName) {
24
- case "mode":
25
- mViewManager.setMode(view, value == null ? null : (String) value);
26
- break;
27
24
  case "opaque":
28
25
  mViewManager.setOpaque(view, value != null && (boolean) value);
29
26
  case "debug":
@@ -13,7 +13,6 @@ import android.view.View;
13
13
  import androidx.annotation.Nullable;
14
14
 
15
15
  public interface SkiaPictureViewManagerInterface<T extends View> {
16
- void setMode(T view, @Nullable String value);
17
16
  void setDebug(T view, boolean value);
18
17
  void setOpaque(T view, boolean value);
19
18
  }
@@ -377,7 +377,7 @@ public:
377
377
 
378
378
  JSI_HOST_FUNCTION(drawSvg) {
379
379
  auto svgdom = JsiSkSVG::fromValue(runtime, arguments[0]);
380
- if (count == 3) {
380
+ if (count == 3 && arguments[1].isNumber() && arguments[2].isNumber()) {
381
381
  // read size
382
382
  auto w = arguments[1].asNumber();
383
383
  auto h = arguments[2].asNumber();
@@ -503,7 +503,7 @@ public:
503
503
  auto paint = JsiSkPaint::fromValue(runtime, arguments[3]);
504
504
  auto blendMode = count > 5 && !arguments[4].isUndefined()
505
505
  ? static_cast<SkBlendMode>(arguments[4].asNumber())
506
- : SkBlendMode::kSrcOver;
506
+ : SkBlendMode::kDstOver;
507
507
 
508
508
  std::vector<SkRSXform> xforms;
509
509
  int xformsSize = static_cast<int>(transforms.size(runtime));
@@ -522,8 +522,33 @@ public:
522
522
  runtime, rects.getValueAtIndex(runtime, i).asObject(runtime));
523
523
  skRects.push_back(*rect.get());
524
524
  }
525
- SkSamplingOptions sampling;
526
- _canvas->drawAtlas(atlas.get(), xforms.data(), skRects.data(), nullptr,
525
+
526
+ std::vector<SkColor> colors;
527
+ if (count > 5 && !arguments[5].isUndefined()) {
528
+ auto colorsArray = arguments[5].asObject(runtime).asArray(runtime);
529
+ int colorsSize = static_cast<int>(colorsArray.size(runtime));
530
+ colors.reserve(colorsSize);
531
+ for (int i = 0; i < colorsSize; i++) {
532
+ // Convert from [r,g,b,a] in [0,1] to SkColor
533
+ auto val = colorsArray.getValueAtIndex(runtime, i).asObject(runtime);
534
+ float r = val.getProperty(runtime, "0").asNumber();
535
+ float g = val.getProperty(runtime, "1").asNumber();
536
+ float b = val.getProperty(runtime, "2").asNumber();
537
+ float a = val.getProperty(runtime, "3").asNumber();
538
+
539
+ // Convert to 8-bit color channels and pack into SkColor
540
+ uint8_t r8 = static_cast<uint8_t>(r * 255);
541
+ uint8_t g8 = static_cast<uint8_t>(g * 255);
542
+ uint8_t b8 = static_cast<uint8_t>(b * 255);
543
+ uint8_t a8 = static_cast<uint8_t>(a * 255);
544
+
545
+ SkColor color = SkColorSetARGB(a8, r8, g8, b8);
546
+ colors.push_back(color);
547
+ }
548
+ }
549
+
550
+ SkSamplingOptions sampling(SkFilterMode::kLinear, SkMipmapMode::kNone);
551
+ _canvas->drawAtlas(atlas.get(), xforms.data(), skRects.data(), colors.data(),
527
552
  skRects.size(), blendMode, sampling, nullptr,
528
553
  paint.get());
529
554
 
@@ -115,7 +115,7 @@ public:
115
115
  createCtor(std::shared_ptr<RNSkPlatformContext> context) {
116
116
  return JSI_HOST_FUNCTION_LAMBDA {
117
117
  // Set up the rect
118
- auto rect = JsiSkRect::fromValue(runtime, arguments[0]).get();
118
+ auto rect = JsiSkRect::fromValue(runtime, arguments[0]);
119
119
  auto rx = arguments[1].asNumber();
120
120
  auto ry = arguments[2].asNumber();
121
121
  auto rrect = SkRRect::MakeRectXY(*rect, rx, ry);
@@ -23,6 +23,7 @@ export declare class SkiaJSDomView extends React.Component<SkiaJSDomViewProps> {
23
23
  * @returns An Image object.
24
24
  */
25
25
  makeImageSnapshot(rect?: SkRect): import("../skia/types").SkImage;
26
+ makeImageSnapshotAsync(rect?: SkRect): Promise<import("../skia/types").SkImage>;
26
27
  /**
27
28
  * Sends a redraw request to the native SkiaView.
28
29
  */
@@ -72,6 +72,10 @@ class SkiaJSDomView extends _react.default.Component {
72
72
  assertSkiaViewApi();
73
73
  return _api.SkiaViewApi.makeImageSnapshot(this._nativeId, rect);
74
74
  }
75
+ makeImageSnapshotAsync(rect) {
76
+ assertSkiaViewApi();
77
+ return _api.SkiaViewApi.makeImageSnapshotAsync(this._nativeId, rect);
78
+ }
75
79
 
76
80
  /**
77
81
  * Sends a redraw request to the native SkiaView.
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_Platform","_SkiaPictureViewNativeComponent","_types","_api","_SkiaViewNativeId","e","__esModule","default","_extends","Object","assign","bind","n","arguments","length","t","r","hasOwnProperty","call","apply","_defineProperty","_toPropertyKey","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","TypeError","String","Number","NativeSkiaPictureView","Platform","OS","SkiaPictureViewNativeComponent","SkiaJSDomView","React","Component","constructor","props","_nativeId","SkiaViewNativeId","current","root","onSize","assertSkiaViewApi","SkiaViewApi","setJsiProperty","tick","redraw","mode","requestId","requestAnimationFrame","nativeId","componentDidUpdate","prevProps","undefined","draw","makeImageSnapshot","rect","Skia","rec","PictureRecorder","canvas","beginRecording","ctx","JsiDrawingContext","render","picture","finishRecordingAsPicture","componentWillUnmount","cancelAnimationFrame","debug","viewProps","createElement","collapsable","nativeID","exports","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 {\n SkiaPictureViewNativeProps,\n SkiaDomViewNativeProps,\n} from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\nconst NativeSkiaPictureView: HostComponent<SkiaPictureViewNativeProps> =\n Platform.OS !== \"web\"\n ? SkiaPictureViewNativeComponent\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (null as any);\n\ninterface SkiaDomViewProps extends SkiaDomViewNativeProps {\n mode?: \"default\" | \"continuous\";\n}\n\ntype SkiaJSDomViewProps = SkiaDomViewProps & {\n Skia: Skia;\n mode?: \"default\" | \"continuous\";\n};\n\nexport class SkiaJSDomView extends React.Component<SkiaJSDomViewProps> {\n constructor(props: SkiaJSDomViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId.current++;\n const { root, onSize } = props;\n if (root) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"root\", root);\n }\n if (onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n this.tick();\n }\n\n private _nativeId: number;\n private requestId = 0;\n\n private tick() {\n this.redraw();\n if (this.props.mode === \"continuous\") {\n this.requestId = requestAnimationFrame(this.tick.bind(this));\n }\n }\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaDomViewProps & { Skia: Skia }) {\n const { root, onSize } = this.props;\n if (root !== prevProps.root && root !== undefined) {\n assertSkiaViewApi();\n this.draw();\n }\n if (onSize !== prevProps.onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n this.tick();\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 }\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 if (this.requestId) {\n cancelAnimationFrame(this.requestId);\n }\n }\n\n render() {\n const { debug = false, ...viewProps } = this.props;\n return (\n <NativeSkiaPictureView\n collapsable={false}\n nativeID={`${this._nativeId}`}\n debug={debug}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertSkiaViewApi = () => {\n if (\n SkiaViewApi === null ||\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AM,CAACF,GAAG,CAAC;MAChB,MAAMG,OAAO,GAAGP,GAAG,CAACQ,wBAAwB,CAAC,CAAC;MAC9CvB,gBAAW,CAACC,cAAc,CAAC,IAAI,CAACP,SAAS,EAAE,SAAS,EAAE4B,OAAO,CAAC;IAChE;EACF;;EAEA;AACF;AACA;EACEE,oBAAoBA,CAAA,EAAS;IAC3BzB,iBAAiB,CAAC,CAAC;IACnBC,gBAAW,CAACC,cAAc,CAAC,IAAI,CAACP,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC;IAC3D,IAAI,IAAI,CAACW,SAAS,EAAE;MAClBoB,oBAAoB,CAAC,IAAI,CAACpB,SAAS,CAAC;IACtC;EACF;EAEAgB,MAAMA,CAAA,EAAG;IACP,MAAM;MAAEK,KAAK,GAAG,KAAK;MAAE,GAAGC;IAAU,CAAC,GAAG,IAAI,CAAClC,KAAK;IAClD,oBACE7C,MAAA,CAAAU,OAAA,CAAAsE,aAAA,CAAC3C,qBAAqB,EAAA1B,QAAA;MACpBsE,WAAW,EAAE,KAAM;MACnBC,QAAQ,EAAE,GAAG,IAAI,CAACpC,SAAS,EAAG;MAC9BgC,KAAK,EAAEA;IAAM,GACTC,SAAS,CACd,CAAC;EAEN;AACF;AAACI,OAAA,CAAA1C,aAAA,GAAAA,aAAA;AAED,MAAMU,iBAAiB,GAAGA,CAAA,KAAM;EAC9B,IACEC,gBAAW,KAAK,IAAI,IACpBA,gBAAW,CAACC,cAAc,KAAK,IAAI,IACnCD,gBAAW,CAACgC,aAAa,KAAK,IAAI,IAClChC,gBAAW,CAACY,iBAAiB,KAAK,IAAI,EACtC;IACA,MAAMqB,KAAK,CAAC,8BAA8B,CAAC;EAC7C;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","_Platform","_SkiaPictureViewNativeComponent","_types","_api","_SkiaViewNativeId","e","__esModule","default","_extends","Object","assign","bind","n","arguments","length","t","r","hasOwnProperty","call","apply","_defineProperty","_toPropertyKey","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","TypeError","String","Number","NativeSkiaPictureView","Platform","OS","SkiaPictureViewNativeComponent","SkiaJSDomView","React","Component","constructor","props","_nativeId","SkiaViewNativeId","current","root","onSize","assertSkiaViewApi","SkiaViewApi","setJsiProperty","tick","redraw","mode","requestId","requestAnimationFrame","nativeId","componentDidUpdate","prevProps","undefined","draw","makeImageSnapshot","rect","makeImageSnapshotAsync","Skia","rec","PictureRecorder","canvas","beginRecording","ctx","JsiDrawingContext","render","picture","finishRecordingAsPicture","componentWillUnmount","cancelAnimationFrame","debug","viewProps","createElement","collapsable","nativeID","exports","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 {\n SkiaPictureViewNativeProps,\n SkiaDomViewNativeProps,\n} from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\nconst NativeSkiaPictureView: HostComponent<SkiaPictureViewNativeProps> =\n Platform.OS !== \"web\"\n ? SkiaPictureViewNativeComponent\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (null as any);\n\ninterface SkiaDomViewProps extends SkiaDomViewNativeProps {\n mode?: \"default\" | \"continuous\";\n}\n\ntype SkiaJSDomViewProps = SkiaDomViewProps & {\n Skia: Skia;\n mode?: \"default\" | \"continuous\";\n};\n\nexport class SkiaJSDomView extends React.Component<SkiaJSDomViewProps> {\n constructor(props: SkiaJSDomViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId.current++;\n const { root, onSize } = props;\n if (root) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"root\", root);\n }\n if (onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n this.tick();\n }\n\n private _nativeId: number;\n private requestId = 0;\n\n private tick() {\n this.redraw();\n if (this.props.mode === \"continuous\") {\n this.requestId = requestAnimationFrame(this.tick.bind(this));\n }\n }\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaDomViewProps & { Skia: Skia }) {\n const { root, onSize } = this.props;\n if (root !== prevProps.root && root !== undefined) {\n assertSkiaViewApi();\n this.draw();\n }\n if (onSize !== prevProps.onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n this.tick();\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 public makeImageSnapshotAsync(rect?: SkRect) {\n assertSkiaViewApi();\n return SkiaViewApi.makeImageSnapshotAsync(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 }\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 if (this.requestId) {\n cancelAnimationFrame(this.requestId);\n }\n }\n\n render() {\n const { debug = false, ...viewProps } = this.props;\n return (\n <NativeSkiaPictureView\n collapsable={false}\n nativeID={`${this._nativeId}`}\n debug={debug}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertSkiaViewApi = () => {\n if (\n SkiaViewApi === null ||\n SkiaViewApi.setJsiProperty === null ||\n SkiaViewApi.requestRedraw === null ||\n SkiaViewApi.makeImageSnapshot === null\n ) {\n throw Error(\"Skia View Api was not found.\");\n }\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,+BAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEA,IAAAI,IAAA,GAAAJ,OAAA;AAKA,IAAAK,iBAAA,GAAAL,OAAA;AAAsD,SAAAD,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,SAAA,WAAAA,QAAA,GAAAC,MAAA,CAAAC,MAAA,GAAAD,MAAA,CAAAC,MAAA,CAAAC,IAAA,eAAAC,CAAA,aAAAP,CAAA,MAAAA,CAAA,GAAAQ,SAAA,CAAAC,MAAA,EAAAT,CAAA,UAAAU,CAAA,GAAAF,SAAA,CAAAR,CAAA,YAAAW,CAAA,IAAAD,CAAA,OAAAE,cAAA,CAAAC,IAAA,CAAAH,CAAA,EAAAC,CAAA,MAAAJ,CAAA,CAAAI,CAAA,IAAAD,CAAA,CAAAC,CAAA,aAAAJ,CAAA,KAAAJ,QAAA,CAAAW,KAAA,OAAAN,SAAA;AAAA,SAAAO,gBAAAf,CAAA,EAAAW,CAAA,EAAAD,CAAA,YAAAC,CAAA,GAAAK,cAAA,CAAAL,CAAA,MAAAX,CAAA,GAAAI,MAAA,CAAAa,cAAA,CAAAjB,CAAA,EAAAW,CAAA,IAAAO,KAAA,EAAAR,CAAA,EAAAS,UAAA,MAAAC,YAAA,MAAAC,QAAA,UAAArB,CAAA,CAAAW,CAAA,IAAAD,CAAA,EAAAV,CAAA;AAAA,SAAAgB,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AK,CAAC,8BAA8B,CAAC;EAC7C;AACF,CAAC","ignoreList":[]}
@@ -23,6 +23,7 @@ export declare class SkiaJSDomView extends React.Component<SkiaJSDomViewProps> {
23
23
  * @returns An Image object.
24
24
  */
25
25
  makeImageSnapshot(rect?: SkRect): import("../skia/types").SkImage;
26
+ makeImageSnapshotAsync(rect?: SkRect): Promise<import("../skia/types").SkImage>;
26
27
  /**
27
28
  * Sends a redraw request to the native SkiaView.
28
29
  */
@@ -65,6 +65,10 @@ export class SkiaJSDomView extends React.Component {
65
65
  assertSkiaViewApi();
66
66
  return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);
67
67
  }
68
+ makeImageSnapshotAsync(rect) {
69
+ assertSkiaViewApi();
70
+ return SkiaViewApi.makeImageSnapshotAsync(this._nativeId, rect);
71
+ }
68
72
 
69
73
  /**
70
74
  * Sends a redraw request to the native SkiaView.
@@ -1 +1 @@
1
- {"version":3,"names":["React","Platform","SkiaPictureViewNativeComponent","JsiDrawingContext","SkiaViewApi","SkiaViewNativeId","NativeSkiaPictureView","OS","SkiaJSDomView","Component","constructor","props","_defineProperty","_nativeId","current","root","onSize","assertSkiaViewApi","setJsiProperty","tick","redraw","mode","requestId","requestAnimationFrame","bind","nativeId","componentDidUpdate","prevProps","undefined","draw","makeImageSnapshot","rect","Skia","rec","PictureRecorder","canvas","beginRecording","ctx","render","picture","finishRecordingAsPicture","componentWillUnmount","cancelAnimationFrame","debug","viewProps","createElement","_extends","collapsable","nativeID","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 {\n SkiaPictureViewNativeProps,\n SkiaDomViewNativeProps,\n} from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\nconst NativeSkiaPictureView: HostComponent<SkiaPictureViewNativeProps> =\n Platform.OS !== \"web\"\n ? SkiaPictureViewNativeComponent\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (null as any);\n\ninterface SkiaDomViewProps extends SkiaDomViewNativeProps {\n mode?: \"default\" | \"continuous\";\n}\n\ntype SkiaJSDomViewProps = SkiaDomViewProps & {\n Skia: Skia;\n mode?: \"default\" | \"continuous\";\n};\n\nexport class SkiaJSDomView extends React.Component<SkiaJSDomViewProps> {\n constructor(props: SkiaJSDomViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId.current++;\n const { root, onSize } = props;\n if (root) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"root\", root);\n }\n if (onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n this.tick();\n }\n\n private _nativeId: number;\n private requestId = 0;\n\n private tick() {\n this.redraw();\n if (this.props.mode === \"continuous\") {\n this.requestId = requestAnimationFrame(this.tick.bind(this));\n }\n }\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaDomViewProps & { Skia: Skia }) {\n const { root, onSize } = this.props;\n if (root !== prevProps.root && root !== undefined) {\n assertSkiaViewApi();\n this.draw();\n }\n if (onSize !== prevProps.onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n this.tick();\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 }\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 if (this.requestId) {\n cancelAnimationFrame(this.requestId);\n }\n }\n\n render() {\n const { debug = false, ...viewProps } = this.props;\n return (\n <NativeSkiaPictureView\n collapsable={false}\n nativeID={`${this._nativeId}`}\n debug={debug}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertSkiaViewApi = () => {\n if (\n SkiaViewApi === null ||\n SkiaViewApi.setJsiProperty === 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,KAAK,MAAM,OAAO;AAIzB,SAASC,QAAQ,QAAQ,aAAa;AACtC,OAAOC,8BAA8B,MAAM,yCAAyC;AACpF,SAASC,iBAAiB,QAAQ,cAAc;AAEhD,SAASC,WAAW,QAAQ,OAAO;AAKnC,SAASC,gBAAgB,QAAQ,oBAAoB;AAErD,MAAMC,qBAAgE,GACpEL,QAAQ,CAACM,EAAE,KAAK,KAAK,GACjBL,8BAA8B;AAC9B;AACC,IAAY;AAWnB,OAAO,MAAMM,aAAa,SAASR,KAAK,CAACS,SAAS,CAAqB;EACrEC,WAAWA,CAACC,KAAyB,EAAE;IACrC,KAAK,CAACA,KAAK,CAAC;IAACC,eAAA;IAAAA,eAAA,oBAeK,CAAC;IAdnB,IAAI,CAACC,SAAS,GAAGR,gBAAgB,CAACS,OAAO,EAAE;IAC3C,MAAM;MAAEC,IAAI;MAAEC;IAAO,CAAC,GAAGL,KAAK;IAC9B,IAAII,IAAI,EAAE;MACRE,iBAAiB,CAA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B,GAAGA,CAAA,KAAM;EAC9B,IACEb,WAAW,KAAK,IAAI,IACpBA,WAAW,CAACc,cAAc,KAAK,IAAI,IACnCd,WAAW,CAAC6C,aAAa,KAAK,IAAI,IAClC7C,WAAW,CAAC0B,iBAAiB,KAAK,IAAI,EACtC;IACA,MAAMoB,KAAK,CAAC,8BAA8B,CAAC;EAC7C;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","Platform","SkiaPictureViewNativeComponent","JsiDrawingContext","SkiaViewApi","SkiaViewNativeId","NativeSkiaPictureView","OS","SkiaJSDomView","Component","constructor","props","_defineProperty","_nativeId","current","root","onSize","assertSkiaViewApi","setJsiProperty","tick","redraw","mode","requestId","requestAnimationFrame","bind","nativeId","componentDidUpdate","prevProps","undefined","draw","makeImageSnapshot","rect","makeImageSnapshotAsync","Skia","rec","PictureRecorder","canvas","beginRecording","ctx","render","picture","finishRecordingAsPicture","componentWillUnmount","cancelAnimationFrame","debug","viewProps","createElement","_extends","collapsable","nativeID","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 {\n SkiaPictureViewNativeProps,\n SkiaDomViewNativeProps,\n} from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\nconst NativeSkiaPictureView: HostComponent<SkiaPictureViewNativeProps> =\n Platform.OS !== \"web\"\n ? SkiaPictureViewNativeComponent\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (null as any);\n\ninterface SkiaDomViewProps extends SkiaDomViewNativeProps {\n mode?: \"default\" | \"continuous\";\n}\n\ntype SkiaJSDomViewProps = SkiaDomViewProps & {\n Skia: Skia;\n mode?: \"default\" | \"continuous\";\n};\n\nexport class SkiaJSDomView extends React.Component<SkiaJSDomViewProps> {\n constructor(props: SkiaJSDomViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId.current++;\n const { root, onSize } = props;\n if (root) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"root\", root);\n }\n if (onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n this.tick();\n }\n\n private _nativeId: number;\n private requestId = 0;\n\n private tick() {\n this.redraw();\n if (this.props.mode === \"continuous\") {\n this.requestId = requestAnimationFrame(this.tick.bind(this));\n }\n }\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaDomViewProps & { Skia: Skia }) {\n const { root, onSize } = this.props;\n if (root !== prevProps.root && root !== undefined) {\n assertSkiaViewApi();\n this.draw();\n }\n if (onSize !== prevProps.onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n this.tick();\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 public makeImageSnapshotAsync(rect?: SkRect) {\n assertSkiaViewApi();\n return SkiaViewApi.makeImageSnapshotAsync(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 }\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 if (this.requestId) {\n cancelAnimationFrame(this.requestId);\n }\n }\n\n render() {\n const { debug = false, ...viewProps } = this.props;\n return (\n <NativeSkiaPictureView\n collapsable={false}\n nativeID={`${this._nativeId}`}\n debug={debug}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertSkiaViewApi = () => {\n if (\n SkiaViewApi === null ||\n SkiaViewApi.setJsiProperty === 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,KAAK,MAAM,OAAO;AAIzB,SAASC,QAAQ,QAAQ,aAAa;AACtC,OAAOC,8BAA8B,MAAM,yCAAyC;AACpF,SAASC,iBAAiB,QAAQ,cAAc;AAEhD,SAASC,WAAW,QAAQ,OAAO;AAKnC,SAASC,gBAAgB,QAAQ,oBAAoB;AAErD,MAAMC,qBAAgE,GACpEL,QAAQ,CAACM,EAAE,KAAK,KAAK,GACjBL,8BAA8B;AAC9B;AACC,IAAY;AAWnB,OAAO,MAAMM,aAAa,SAASR,KAAK,CAACS,SAAS,CAAqB;EACrEC,WAAWA,CAACC,KAAyB,EAAE;IACrC,KAAK,CAACA,KAAK,CAAC;IAACC,eAAA;IAAAA,eAAA,oBAeK,CAAC;IAdnB,IAAI,CAACC,SAAS,GAAGR,gBAAgB,CAACS,OAAO,EAAE;IAC3C,MAAM;MAAEC,IAAI;MAAEC;IAAO,CAAC,GAAGL,KAAK;IAC9B,IAAII,IAAI,EAAE;MACRE,iBAAiB,CAAC,CAAC;MACnBb,WAAW,CAACc,cAAc,CAAC,IAAI,CAACL,SAAS,EAAE,MAAM,EAAEE,IAAI,CAAC;IAC1D;IACA,IAAIC,MAAM,EAAE;MACVC,iBAAiB,CAAC,CAAC;MACnBb,WAAW,CAACc,cAAc,CAAC,IAAI,CAACL,SAAS,EAAE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AI,IACpBA,WAAW,CAACc,cAAc,KAAK,IAAI,IACnCd,WAAW,CAAC8C,aAAa,KAAK,IAAI,IAClC9C,WAAW,CAAC0B,iBAAiB,KAAK,IAAI,EACtC;IACA,MAAMqB,KAAK,CAAC,8BAA8B,CAAC;EAC7C;AACF,CAAC","ignoreList":[]}
@@ -14,6 +14,7 @@ export class SkiaJSDomView extends SkiaJSDomView_base {
14
14
  * @returns An Image object.
15
15
  */
16
16
  makeImageSnapshot(rect: any): import("../../..").SkImage;
17
+ makeImageSnapshotAsync(rect: any): Promise<import("../../..").SkImage>;
17
18
  /**
18
19
  * Sends a redraw request to the native SkiaView.
19
20
  */
@@ -11,6 +11,7 @@ export class SkiaJSDomView extends React.Component<any, any, any> {
11
11
  * @returns An Image object.
12
12
  */
13
13
  makeImageSnapshot(rect: any): import("../../..").SkImage;
14
+ makeImageSnapshotAsync(rect: any): Promise<import("../../..").SkImage>;
14
15
  /**
15
16
  * Sends a redraw request to the native SkiaView.
16
17
  */
@@ -23,6 +23,7 @@ export declare class SkiaJSDomView extends React.Component<SkiaJSDomViewProps> {
23
23
  * @returns An Image object.
24
24
  */
25
25
  makeImageSnapshot(rect?: SkRect): import("../skia/types").SkImage;
26
+ makeImageSnapshotAsync(rect?: SkRect): Promise<import("../skia/types").SkImage>;
26
27
  /**
27
28
  * Sends a redraw request to the native SkiaView.
28
29
  */
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": "1.7.4",
10
+ "version": "1.7.5",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "react-native": "src/index.ts",
@@ -81,6 +81,11 @@ export class SkiaJSDomView extends React.Component<SkiaJSDomViewProps> {
81
81
  return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);
82
82
  }
83
83
 
84
+ public makeImageSnapshotAsync(rect?: SkRect) {
85
+ assertSkiaViewApi();
86
+ return SkiaViewApi.makeImageSnapshotAsync(this._nativeId, rect);
87
+ }
88
+
84
89
  /**
85
90
  * Sends a redraw request to the native SkiaView.
86
91
  */