@shopify/react-native-skia 1.5.7 → 1.5.9
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +1 -2
- package/android/cpp/jni/JniPlatformContext.cpp +0 -49
- package/android/cpp/jni/include/JniPlatformContext.h +1 -17
- package/android/cpp/jni/include/JniSkiaBaseView.h +0 -2
- package/android/cpp/jni/include/JniSkiaDomView.h +0 -3
- package/android/cpp/jni/include/JniSkiaManager.h +0 -2
- package/android/cpp/jni/include/JniSkiaPictureView.h +0 -3
- package/android/cpp/rnskia-android/MainThreadDispatcher.h +69 -0
- package/android/cpp/rnskia-android/OpenGLContext.h +3 -1
- package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +1 -1
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +4 -5
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +10 -11
- package/android/cpp/rnskia-android/RNSkAndroidView.h +3 -13
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +0 -1
- package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +0 -85
- package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaModule.java +1 -21
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaManager.java +0 -4
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDomViewManagerDelegate.java +1 -4
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDomViewManagerInterface.java +0 -1
- package/cpp/api/JsiSkImage.h +20 -4
- package/cpp/rnskia/RNSkManager.cpp +2 -3
- package/cpp/rnskia/RNSkPlatformContext.h +6 -114
- package/cpp/rnskia/RNSkView.h +21 -77
- package/ios/RNSkia-iOS/MetalContext.h +2 -0
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +4 -10
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +6 -16
- package/ios/RNSkia-iOS/SkiaDomView.mm +0 -1
- package/ios/RNSkia-iOS/SkiaDomViewManager.mm +0 -6
- package/ios/RNSkia-iOS/SkiaPictureView.mm +0 -1
- package/ios/RNSkia-iOS/SkiaPictureViewManager.mm +0 -6
- package/ios/RNSkia-iOS/SkiaUIView.h +0 -1
- package/ios/RNSkia-iOS/SkiaUIView.mm +1 -14
- package/lib/commonjs/renderer/Canvas.d.ts +1 -0
- package/lib/commonjs/renderer/Canvas.js +5 -5
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +0 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/commonjs/views/SkiaBaseWebView.d.ts +1 -12
- package/lib/commonjs/views/SkiaBaseWebView.js +1 -19
- package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
- package/lib/commonjs/views/SkiaDomView.d.ts +8 -1
- package/lib/commonjs/views/SkiaDomView.js +14 -2
- package/lib/commonjs/views/SkiaDomView.js.map +1 -1
- package/lib/commonjs/views/SkiaDomView.web.d.ts +3 -3
- package/lib/commonjs/views/SkiaDomView.web.js.map +1 -1
- package/lib/commonjs/views/SkiaJSDomView.d.ts +12 -6
- package/lib/commonjs/views/SkiaJSDomView.js +12 -3
- package/lib/commonjs/views/SkiaJSDomView.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.d.ts +8 -1
- package/lib/commonjs/views/SkiaPictureView.js +14 -1
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.web.d.ts +3 -3
- package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
- package/lib/commonjs/views/types.d.ts +2 -12
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +1 -0
- package/lib/module/renderer/Canvas.js +5 -5
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +0 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/module/views/SkiaBaseWebView.d.ts +1 -12
- package/lib/module/views/SkiaBaseWebView.js +1 -19
- package/lib/module/views/SkiaBaseWebView.js.map +1 -1
- package/lib/module/views/SkiaDomView.d.ts +8 -1
- package/lib/module/views/SkiaDomView.js +14 -2
- package/lib/module/views/SkiaDomView.js.map +1 -1
- package/lib/module/views/SkiaDomView.web.d.ts +3 -3
- package/lib/module/views/SkiaDomView.web.js.map +1 -1
- package/lib/module/views/SkiaJSDomView.d.ts +12 -6
- package/lib/module/views/SkiaJSDomView.js +12 -3
- package/lib/module/views/SkiaJSDomView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.d.ts +8 -1
- package/lib/module/views/SkiaPictureView.js +14 -1
- package/lib/module/views/SkiaPictureView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.web.d.ts +3 -3
- package/lib/module/views/SkiaPictureView.web.js.map +1 -1
- package/lib/module/views/types.d.ts +2 -12
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/lib/commonjs/views/SkiaBaseWebView.d.ts +0 -11
- package/lib/typescript/lib/commonjs/views/SkiaDomView.d.ts +3 -0
- package/lib/typescript/lib/commonjs/views/SkiaJSDomView.d.ts +2 -0
- package/lib/typescript/lib/commonjs/views/SkiaPictureView.d.ts +3 -0
- package/lib/typescript/lib/module/views/SkiaBaseWebView.d.ts +0 -11
- package/lib/typescript/lib/module/views/SkiaDomView.d.ts +3 -0
- package/lib/typescript/lib/module/views/SkiaJSDomView.d.ts +2 -0
- package/lib/typescript/lib/module/views/SkiaPictureView.d.ts +3 -0
- package/lib/typescript/src/renderer/Canvas.d.ts +1 -0
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +0 -1
- package/lib/typescript/src/views/SkiaBaseWebView.d.ts +1 -12
- package/lib/typescript/src/views/SkiaDomView.d.ts +8 -1
- package/lib/typescript/src/views/SkiaDomView.web.d.ts +3 -3
- package/lib/typescript/src/views/SkiaJSDomView.d.ts +12 -6
- package/lib/typescript/src/views/SkiaPictureView.d.ts +8 -1
- package/lib/typescript/src/views/SkiaPictureView.web.d.ts +3 -3
- package/lib/typescript/src/views/types.d.ts +2 -12
- package/package.json +1 -1
- package/react-native-skia.podspec +2 -2
- package/src/renderer/Canvas.tsx +4 -3
- package/src/renderer/__tests__/e2e/Image.spec.tsx +2 -64
- package/src/skia/__tests__/assets/oslo-mini.jpg +0 -0
- package/src/specs/SkiaPictureViewNativeComponent.ts +0 -1
- package/src/views/SkiaBaseWebView.tsx +3 -19
- package/src/views/SkiaDomView.tsx +23 -4
- package/src/views/SkiaDomView.web.tsx +3 -3
- package/src/views/SkiaJSDomView.tsx +30 -9
- package/src/views/SkiaPictureView.tsx +22 -2
- package/src/views/SkiaPictureView.web.tsx +3 -3
- package/src/views/types.ts +2 -13
- package/cpp/rnskia/RNSkDispatchQueue.cpp +0 -73
- package/cpp/rnskia/RNSkDispatchQueue.h +0 -49
- package/ios/RNSkia-iOS/DisplayLink.h +0 -17
- package/ios/RNSkia-iOS/DisplayLink.mm +0 -41
@@ -15,19 +15,16 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
|
|
15
15
|
const pd = _Platform.Platform.PixelRatio;
|
16
16
|
class SkiaBaseWebView extends _react.default.Component {
|
17
17
|
constructor(props) {
|
18
|
-
var _props$mode;
|
19
18
|
super(props);
|
20
19
|
_defineProperty(this, "_surface", null);
|
21
20
|
_defineProperty(this, "_unsubscriptions", []);
|
22
21
|
_defineProperty(this, "_canvas", null);
|
23
22
|
_defineProperty(this, "_canvasRef", /*#__PURE__*/_react.default.createRef());
|
24
|
-
_defineProperty(this, "_mode", void 0);
|
25
23
|
_defineProperty(this, "_redrawRequests", 0);
|
26
24
|
_defineProperty(this, "requestId", 0);
|
27
25
|
_defineProperty(this, "width", 0);
|
28
26
|
_defineProperty(this, "height", 0);
|
29
27
|
_defineProperty(this, "onLayout", this.onLayoutEvent.bind(this));
|
30
|
-
this._mode = (_props$mode = props.mode) !== null && _props$mode !== void 0 ? _props$mode : "default";
|
31
28
|
}
|
32
29
|
unsubscribeAll() {
|
33
30
|
this._unsubscriptions.forEach(u => u());
|
@@ -104,7 +101,7 @@ class SkiaBaseWebView extends _react.default.Component {
|
|
104
101
|
* Sends a redraw request to the native SkiaView.
|
105
102
|
*/
|
106
103
|
tick() {
|
107
|
-
if (this.
|
104
|
+
if (this._redrawRequests > 0) {
|
108
105
|
this._redrawRequests = 0;
|
109
106
|
if (this._canvas) {
|
110
107
|
var _this$_surface3;
|
@@ -122,23 +119,8 @@ class SkiaBaseWebView extends _react.default.Component {
|
|
122
119
|
redraw() {
|
123
120
|
this._redrawRequests++;
|
124
121
|
}
|
125
|
-
|
126
|
-
/**
|
127
|
-
* Updates the drawing mode for the skia view. This is the same
|
128
|
-
* as declaratively setting the mode property on the SkiaView.
|
129
|
-
* There are two drawing modes, "continuous" and "default",
|
130
|
-
* where the continuous mode will continuously redraw the view and
|
131
|
-
* the default mode will only redraw when any of the regular react
|
132
|
-
* properties are changed like size and margins.
|
133
|
-
* @param mode Drawing mode to use.
|
134
|
-
*/
|
135
|
-
setDrawMode(mode) {
|
136
|
-
this._mode = mode;
|
137
|
-
this.tick();
|
138
|
-
}
|
139
122
|
render() {
|
140
123
|
const {
|
141
|
-
mode,
|
142
124
|
debug = false,
|
143
125
|
...viewProps
|
144
126
|
} = this.props;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireDefault","require","_JsiSkSurface","_Platform","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","pd","Platform","PixelRatio","SkiaBaseWebView","React","Component","constructor","props","_props$mode","createRef","onLayoutEvent","_mode","mode","unsubscribeAll","_unsubscriptions","forEach","u","evt","CanvasKit","global","canvas","_canvasRef","current","width","clientWidth","height","clientHeight","surface","MakeWebGLCanvasSurface","Error","_surface","JsiSkSurface","_canvas","getCanvas","redraw","onLayout","getSize","componentDidMount","tick","componentDidUpdate","componentWillUnmount","cancelAnimationFrame","requestId","_this$_canvasRef$curr","getContext","getExtension","loseContext","makeImageSnapshot","rect","_this$_surface","_this$_surface2","clear","TRANSPARENT","renderInCanvas","ref","flush","_redrawRequests","_this$_surface3","Float32Array","of","save","scale","restore","requestAnimationFrame","setDrawMode","render","debug","viewProps","createElement","View","style","display","flex","exports"],"sources":["SkiaBaseWebView.tsx"],"sourcesContent":["/* global HTMLCanvasElement */\nimport React from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\n\nimport type { SkRect, SkCanvas } from \"../skia/types\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\nimport { Platform } from \"../Platform\";\n\nimport type { DrawMode, SkiaBaseViewProps } from \"./types\";\n\nconst pd = Platform.PixelRatio;\n\nexport abstract class SkiaBaseWebView<\n TProps extends SkiaBaseViewProps\n> extends React.Component<TProps> {\n constructor(props: TProps) {\n super(props);\n this._mode = props.mode ?? \"default\";\n }\n\n private _surface: JsiSkSurface | null = null;\n private _unsubscriptions: Array<() => void> = [];\n private _canvas: SkCanvas | null = null;\n private _canvasRef = React.createRef<HTMLCanvasElement>();\n private _mode: DrawMode;\n private _redrawRequests = 0;\n private requestId = 0;\n\n protected width = 0;\n protected height = 0;\n\n private unsubscribeAll() {\n this._unsubscriptions.forEach((u) => u());\n this._unsubscriptions = [];\n }\n\n private onLayoutEvent(evt: LayoutChangeEvent) {\n const { CanvasKit } = global;\n // Reset canvas / surface on layout change\n const canvas = this._canvasRef.current;\n if (canvas) {\n this.width = canvas.clientWidth;\n this.height = canvas.clientHeight;\n canvas.width = this.width * pd;\n canvas.height = this.height * pd;\n const surface = CanvasKit.MakeWebGLCanvasSurface(canvas);\n if (!surface) {\n throw new Error(\"Could not create surface\");\n }\n this._surface = new JsiSkSurface(CanvasKit, surface);\n this._canvas = this._surface.getCanvas();\n this.redraw();\n }\n // Call onLayout callback if it exists\n if (this.props.onLayout) {\n this.props.onLayout(evt);\n }\n }\n\n protected getSize() {\n return { width: this.width, height: this.height };\n }\n\n componentDidMount() {\n // Start render loop\n this.tick();\n }\n\n componentDidUpdate() {\n this.redraw();\n }\n\n componentWillUnmount() {\n this.unsubscribeAll();\n cancelAnimationFrame(this.requestId);\n // eslint-disable-next-line max-len\n // https://stackoverflow.com/questions/23598471/how-do-i-clean-up-and-unload-a-webgl-canvas-context-from-gpu-after-use\n // https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_lose_context\n // We delete the context, only if the context has been intialized\n if (this._surface) {\n this._canvasRef.current\n ?.getContext(\"webgl2\")\n ?.getExtension(\"WEBGL_lose_context\")\n ?.loseContext();\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 this._canvas!.clear(CanvasKit.TRANSPARENT);\n this.renderInCanvas(this._canvas!);\n this._surface?.ref.flush();\n return this._surface?.makeImageSnapshot(rect);\n }\n\n /**\n * Override to render\n */\n protected abstract renderInCanvas(canvas: SkCanvas): void;\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n private tick() {\n if (this._mode === \"continuous\" || this._redrawRequests > 0) {\n this._redrawRequests = 0;\n if (this._canvas) {\n const canvas = this._canvas!;\n canvas.clear(Float32Array.of(0, 0, 0, 0));\n canvas.save();\n canvas.scale(pd, pd);\n this.renderInCanvas(canvas);\n canvas.restore();\n this._surface?.ref.flush();\n }\n }\n this.requestId = requestAnimationFrame(this.tick.bind(this));\n }\n\n public redraw() {\n this._redrawRequests++;\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 this._mode = mode;\n this.tick();\n }\n\n private onLayout = this.onLayoutEvent.bind(this);\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <Platform.View {...viewProps} onLayout={this.onLayout}>\n <canvas ref={this._canvasRef} style={{ display: \"flex\", flex: 1 }} />\n </Platform.View>\n );\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAAuC,SAAAD,uBAAAI,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,eAAAN,CAAA,QAAAY,CAAA,GAAAC,YAAA,CAAAb,CAAA,uCAAAY,CAAA,GAAAA,CAAA,GAAAA,CAAA;AAAA,SAAAC,aAAAb,CAAA,EAAAC,CAAA,2BAAAD,CAAA,KAAAA,CAAA,SAAAA,C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AAA2B,eAAA,eAAbA,eAAA,CAAeH,GAAG,CAACC,KAAK,CAAC,CAAC;MAC5B;IACF;IACA,IAAI,CAACb,SAAS,GAAGqB,qBAAqB,CAAC,IAAI,CAACzB,IAAI,CAAC7D,IAAI,CAAC,IAAI,CAAC,CAAC;EAC9D;EAEOyD,MAAMA,CAAA,EAAG;IACd,IAAI,CAACsB,eAAe,EAAE;EACxB;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACSQ,WAAWA,CAACpD,IAAc,EAAE;IACjC,IAAI,CAACD,KAAK,GAAGC,IAAI;IACjB,IAAI,CAAC0B,IAAI,CAAC,CAAC;EACb;EAIA2B,MAAMA,CAAA,EAAG;IACP,MAAM;MAAErD,IAAI;MAAEsD,KAAK,GAAG,KAAK;MAAE,GAAGC;IAAU,CAAC,GAAG,IAAI,CAAC5D,KAAK;IACxD,oBACEzC,MAAA,CAAAO,OAAA,CAAA+F,aAAA,CAAClG,SAAA,CAAA+B,QAAQ,CAACoE,IAAI,EAAA/F,QAAA,KAAK6F,SAAS;MAAEhC,QAAQ,EAAE,IAAI,CAACA;IAAS,iBACpDrE,MAAA,CAAAO,OAAA,CAAA+F,aAAA;MAAQd,GAAG,EAAE,IAAI,CAACjC,UAAW;MAACiD,KAAK,EAAE;QAAEC,OAAO,EAAE,MAAM;QAAEC,IAAI,EAAE;MAAE;IAAE,CAAE,CACvD,CAAC;EAEpB;AACF;AAACC,OAAA,CAAAtE,eAAA,GAAAA,eAAA","ignoreList":[]}
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","_JsiSkSurface","_Platform","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","pd","Platform","PixelRatio","SkiaBaseWebView","React","Component","constructor","props","createRef","onLayoutEvent","unsubscribeAll","_unsubscriptions","forEach","u","evt","CanvasKit","global","canvas","_canvasRef","current","width","clientWidth","height","clientHeight","surface","MakeWebGLCanvasSurface","Error","_surface","JsiSkSurface","_canvas","getCanvas","redraw","onLayout","getSize","componentDidMount","tick","componentDidUpdate","componentWillUnmount","cancelAnimationFrame","requestId","_this$_canvasRef$curr","getContext","getExtension","loseContext","makeImageSnapshot","rect","_this$_surface","_this$_surface2","clear","TRANSPARENT","renderInCanvas","ref","flush","_redrawRequests","_this$_surface3","Float32Array","of","save","scale","restore","requestAnimationFrame","render","debug","viewProps","createElement","View","style","display","flex","exports"],"sources":["SkiaBaseWebView.tsx"],"sourcesContent":["/* global HTMLCanvasElement */\nimport React from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\n\nimport type { SkRect, SkCanvas } from \"../skia/types\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\nimport { Platform } from \"../Platform\";\n\nimport type { SkiaBaseViewProps } from \"./types\";\n\nconst pd = Platform.PixelRatio;\n\nexport abstract class SkiaBaseWebView<\n TProps extends SkiaBaseViewProps\n> extends React.Component<TProps> {\n constructor(props: TProps) {\n super(props);\n }\n\n private _surface: JsiSkSurface | null = null;\n private _unsubscriptions: Array<() => void> = [];\n private _canvas: SkCanvas | null = null;\n private _canvasRef = React.createRef<HTMLCanvasElement>();\n private _redrawRequests = 0;\n private requestId = 0;\n\n protected width = 0;\n protected height = 0;\n\n private unsubscribeAll() {\n this._unsubscriptions.forEach((u) => u());\n this._unsubscriptions = [];\n }\n\n private onLayoutEvent(evt: LayoutChangeEvent) {\n const { CanvasKit } = global;\n // Reset canvas / surface on layout change\n const canvas = this._canvasRef.current;\n if (canvas) {\n this.width = canvas.clientWidth;\n this.height = canvas.clientHeight;\n canvas.width = this.width * pd;\n canvas.height = this.height * pd;\n const surface = CanvasKit.MakeWebGLCanvasSurface(canvas);\n if (!surface) {\n throw new Error(\"Could not create surface\");\n }\n this._surface = new JsiSkSurface(CanvasKit, surface);\n this._canvas = this._surface.getCanvas();\n this.redraw();\n }\n // Call onLayout callback if it exists\n if (this.props.onLayout) {\n this.props.onLayout(evt);\n }\n }\n\n protected getSize() {\n return { width: this.width, height: this.height };\n }\n\n componentDidMount() {\n // Start render loop\n this.tick();\n }\n\n componentDidUpdate() {\n this.redraw();\n }\n\n componentWillUnmount() {\n this.unsubscribeAll();\n cancelAnimationFrame(this.requestId);\n // eslint-disable-next-line max-len\n // https://stackoverflow.com/questions/23598471/how-do-i-clean-up-and-unload-a-webgl-canvas-context-from-gpu-after-use\n // https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_lose_context\n // We delete the context, only if the context has been intialized\n if (this._surface) {\n this._canvasRef.current\n ?.getContext(\"webgl2\")\n ?.getExtension(\"WEBGL_lose_context\")\n ?.loseContext();\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 this._canvas!.clear(CanvasKit.TRANSPARENT);\n this.renderInCanvas(this._canvas!);\n this._surface?.ref.flush();\n return this._surface?.makeImageSnapshot(rect);\n }\n\n /**\n * Override to render\n */\n protected abstract renderInCanvas(canvas: SkCanvas): void;\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n private tick() {\n if (this._redrawRequests > 0) {\n this._redrawRequests = 0;\n if (this._canvas) {\n const canvas = this._canvas!;\n canvas.clear(Float32Array.of(0, 0, 0, 0));\n canvas.save();\n canvas.scale(pd, pd);\n this.renderInCanvas(canvas);\n canvas.restore();\n this._surface?.ref.flush();\n }\n }\n this.requestId = requestAnimationFrame(this.tick.bind(this));\n }\n\n public redraw() {\n this._redrawRequests++;\n }\n\n private onLayout = this.onLayoutEvent.bind(this);\n\n render() {\n const { debug = false, ...viewProps } = this.props;\n return (\n <Platform.View {...viewProps} onLayout={this.onLayout}>\n <canvas ref={this._canvasRef} style={{ display: \"flex\", flex: 1 }} />\n </Platform.View>\n );\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,sB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,CAACxD,KAAK;IAClD,oBACEzC,MAAA,CAAAO,OAAA,CAAA2F,aAAA,CAAC9F,SAAA,CAAA+B,QAAQ,CAACgE,IAAI,EAAA3F,QAAA,KAAKyF,SAAS;MAAE/B,QAAQ,EAAE,IAAI,CAACA;IAAS,iBACpDlE,MAAA,CAAAO,OAAA,CAAA2F,aAAA;MAAQb,GAAG,EAAE,IAAI,CAACjC,UAAW;MAACgD,KAAK,EAAE;QAAEC,OAAO,EAAE,MAAM;QAAEC,IAAI,EAAE;MAAE;IAAE,CAAE,CACvD,CAAC;EAEpB;AACF;AAACC,OAAA,CAAAlE,eAAA,GAAAA,eAAA","ignoreList":[]}
|
@@ -1,11 +1,17 @@
|
|
1
1
|
import React from "react";
|
2
2
|
import type { SkRect } from "../skia/types";
|
3
|
-
import type {
|
3
|
+
import type { SkiaDomViewNativeProps } from "./types";
|
4
|
+
interface SkiaDomViewProps extends SkiaDomViewNativeProps {
|
5
|
+
mode?: "default" | "continuous";
|
6
|
+
}
|
4
7
|
export declare class SkiaDomView extends React.Component<SkiaDomViewProps> {
|
5
8
|
constructor(props: SkiaDomViewProps);
|
6
9
|
private _nativeId;
|
10
|
+
private requestId;
|
7
11
|
get nativeId(): number;
|
8
12
|
componentDidUpdate(prevProps: SkiaDomViewProps): void;
|
13
|
+
componentWillUnmount(): void;
|
14
|
+
private tick;
|
9
15
|
/**
|
10
16
|
* Creates a snapshot from the canvas in the surface
|
11
17
|
* @param rect Rect to use as bounds. Optional.
|
@@ -24,3 +30,4 @@ export declare class SkiaDomView extends React.Component<SkiaDomViewProps> {
|
|
24
30
|
redraw(): void;
|
25
31
|
render(): React.JSX.Element;
|
26
32
|
}
|
33
|
+
export {};
|
@@ -21,6 +21,7 @@ class SkiaDomView extends _react.default.Component {
|
|
21
21
|
constructor(props) {
|
22
22
|
super(props);
|
23
23
|
_defineProperty(this, "_nativeId", void 0);
|
24
|
+
_defineProperty(this, "requestId", 0);
|
24
25
|
this._nativeId = _SkiaViewNativeId.SkiaViewNativeId.current++;
|
25
26
|
const {
|
26
27
|
root,
|
@@ -34,6 +35,7 @@ class SkiaDomView extends _react.default.Component {
|
|
34
35
|
assertSkiaViewApi();
|
35
36
|
_api.SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
|
36
37
|
}
|
38
|
+
this.tick();
|
37
39
|
}
|
38
40
|
get nativeId() {
|
39
41
|
return this._nativeId;
|
@@ -51,6 +53,18 @@ class SkiaDomView extends _react.default.Component {
|
|
51
53
|
assertSkiaViewApi();
|
52
54
|
_api.SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
|
53
55
|
}
|
56
|
+
this.tick();
|
57
|
+
}
|
58
|
+
componentWillUnmount() {
|
59
|
+
if (this.requestId) {
|
60
|
+
cancelAnimationFrame(this.requestId);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
tick() {
|
64
|
+
this.redraw();
|
65
|
+
if (this.props.mode === "continuous") {
|
66
|
+
this.requestId = requestAnimationFrame(this.tick.bind(this));
|
67
|
+
}
|
54
68
|
}
|
55
69
|
|
56
70
|
/**
|
@@ -82,14 +96,12 @@ class SkiaDomView extends _react.default.Component {
|
|
82
96
|
}
|
83
97
|
render() {
|
84
98
|
const {
|
85
|
-
mode,
|
86
99
|
debug = false,
|
87
100
|
...viewProps
|
88
101
|
} = this.props;
|
89
102
|
return /*#__PURE__*/_react.default.createElement(NativeSkiaDomView, _extends({
|
90
103
|
collapsable: false,
|
91
104
|
nativeID: `${this._nativeId}`,
|
92
|
-
mode: mode,
|
93
105
|
debug: debug
|
94
106
|
}, viewProps));
|
95
107
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireDefault","require","_Platform","_SkiaDomViewNativeComponent","_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","NativeSkiaDomView","Platform","OS","SkiaDomViewNativeComponent","SkiaDomView","React","Component","constructor","props","_nativeId","SkiaViewNativeId","current","root","onSize","assertSkiaViewApi","SkiaViewApi","setJsiProperty","nativeId","componentDidUpdate","prevProps","
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","_Platform","_SkiaDomViewNativeComponent","_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","NativeSkiaDomView","Platform","OS","SkiaDomViewNativeComponent","SkiaDomView","React","Component","constructor","props","_nativeId","SkiaViewNativeId","current","root","onSize","assertSkiaViewApi","SkiaViewApi","setJsiProperty","tick","nativeId","componentDidUpdate","prevProps","componentWillUnmount","requestId","cancelAnimationFrame","redraw","mode","requestAnimationFrame","makeImageSnapshot","rect","makeImageSnapshotAsync","requestRedraw","render","debug","viewProps","createElement","collapsable","nativeID","exports","Error"],"sources":["SkiaDomView.tsx"],"sourcesContent":["import React from \"react\";\nimport type { HostComponent } from \"react-native\";\n\nimport type { SkRect } from \"../skia/types\";\nimport { Platform } from \"../Platform\";\nimport SkiaDomViewNativeComponent from \"../specs/SkiaDomViewNativeComponent\";\n\nimport { SkiaViewApi } from \"./api\";\nimport type { SkiaDomViewNativeProps } from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\nconst NativeSkiaDomView: HostComponent<SkiaDomViewNativeProps> =\n Platform.OS !== \"web\"\n ? SkiaDomViewNativeComponent\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\nexport class SkiaDomView extends React.Component<SkiaDomViewProps> {\n constructor(props: SkiaDomViewProps) {\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 public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaDomViewProps) {\n const { root, onSize } = this.props;\n if (root !== prevProps.root) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"root\", root);\n }\n if (onSize !== prevProps.onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n this.tick();\n }\n\n componentWillUnmount(): void {\n if (this.requestId) {\n cancelAnimationFrame(this.requestId);\n }\n }\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 /**\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 * 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 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 SkiaViewApi.requestRedraw(this._nativeId);\n }\n\n render() {\n const { debug = false, ...viewProps } = this.props;\n return (\n <NativeSkiaDomView\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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oBACE5C,MAAA,CAAAS,OAAA,CAAA6D,aAAA,CAAClC,iBAAiB,EAAA1B,QAAA;MAChB6D,WAAW,EAAE,KAAM;MACnBC,QAAQ,EAAE,GAAG,IAAI,CAAC3B,SAAS,EAAG;MAC9BuB,KAAK,EAAEA;IAAM,GACTC,SAAS,CACd,CAAC;EAEN;AACF;AAACI,OAAA,CAAAjC,WAAA,GAAAA,WAAA;AAED,MAAMU,iBAAiB,GAAGA,CAAA,KAAM;EAC9B,IACEC,gBAAW,KAAK,IAAI,IACpBA,gBAAW,CAACC,cAAc,KAAK,IAAI,IACnCD,gBAAW,CAACe,aAAa,KAAK,IAAI,IAClCf,gBAAW,CAACY,iBAAiB,KAAK,IAAI,EACtC;IACA,MAAMW,KAAK,CAAC,8BAA8B,CAAC;EAC7C;AACF,CAAC","ignoreList":[]}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { SkCanvas } from "../skia/types";
|
2
2
|
import { SkiaBaseWebView } from "./SkiaBaseWebView";
|
3
|
-
import type {
|
4
|
-
export declare class SkiaDomView extends SkiaBaseWebView<
|
5
|
-
constructor(props:
|
3
|
+
import type { SkiaDomViewNativeProps } from "./types";
|
4
|
+
export declare class SkiaDomView extends SkiaBaseWebView<SkiaDomViewNativeProps> {
|
5
|
+
constructor(props: SkiaDomViewNativeProps);
|
6
6
|
protected renderInCanvas(canvas: SkCanvas): void;
|
7
7
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_skia","require","_DrawingContext","_SkiaBaseWebView","SkiaDomView","SkiaBaseWebView","constructor","props","renderInCanvas","canvas","onSize","width","height","getSize","value","root","ctx","JsiDrawingContext","Skia","render","exports"],"sources":["SkiaDomView.web.tsx"],"sourcesContent":["import { Skia } from \"../skia\";\nimport type { SkCanvas } from \"../skia/types\";\nimport { JsiDrawingContext } from \"../dom/types/DrawingContext\";\n\nimport { SkiaBaseWebView } from \"./SkiaBaseWebView\";\nimport type {
|
1
|
+
{"version":3,"names":["_skia","require","_DrawingContext","_SkiaBaseWebView","SkiaDomView","SkiaBaseWebView","constructor","props","renderInCanvas","canvas","onSize","width","height","getSize","value","root","ctx","JsiDrawingContext","Skia","render","exports"],"sources":["SkiaDomView.web.tsx"],"sourcesContent":["import { Skia } from \"../skia\";\nimport type { SkCanvas } from \"../skia/types\";\nimport { JsiDrawingContext } from \"../dom/types/DrawingContext\";\n\nimport { SkiaBaseWebView } from \"./SkiaBaseWebView\";\nimport type { SkiaDomViewNativeProps } from \"./types\";\n\nexport class SkiaDomView extends SkiaBaseWebView<SkiaDomViewNativeProps> {\n constructor(props: SkiaDomViewNativeProps) {\n super(props);\n }\n\n protected renderInCanvas(canvas: SkCanvas): void {\n if (this.props.onSize) {\n const { width, height } = this.getSize();\n this.props.onSize.value = { width, height };\n }\n if (this.props.root) {\n const ctx = new JsiDrawingContext(Skia, canvas);\n this.props.root.render(ctx);\n }\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAEA,IAAAC,eAAA,GAAAD,OAAA;AAEA,IAAAE,gBAAA,GAAAF,OAAA;AAGO,MAAMG,WAAW,SAASC,gCAAe,CAAyB;EACvEC,WAAWA,CAACC,KAA6B,EAAE;IACzC,KAAK,CAACA,KAAK,CAAC;EACd;EAEUC,cAAcA,CAACC,MAAgB,EAAQ;IAC/C,IAAI,IAAI,CAACF,KAAK,CAACG,MAAM,EAAE;MACrB,MAAM;QAAEC,KAAK;QAAEC;MAAO,CAAC,GAAG,IAAI,CAACC,OAAO,CAAC,CAAC;MACxC,IAAI,CAACN,KAAK,CAACG,MAAM,CAACI,KAAK,GAAG;QAAEH,KAAK;QAAEC;MAAO,CAAC;IAC7C;IACA,IAAI,IAAI,CAACL,KAAK,CAACQ,IAAI,EAAE;MACnB,MAAMC,GAAG,GAAG,IAAIC,iCAAiB,CAACC,UAAI,EAAET,MAAM,CAAC;MAC/C,IAAI,CAACF,KAAK,CAACQ,IAAI,CAACI,MAAM,CAACH,GAAG,CAAC;IAC7B;EACF;AACF;AAACI,OAAA,CAAAhB,WAAA,GAAAA,WAAA","ignoreList":[]}
|
@@ -1,13 +1,18 @@
|
|
1
1
|
import React from "react";
|
2
2
|
import type { Skia, SkRect } from "../skia/types";
|
3
|
-
import type {
|
4
|
-
|
3
|
+
import type { SkiaDomViewNativeProps } from "./types";
|
4
|
+
interface SkiaDomViewProps extends SkiaDomViewNativeProps {
|
5
|
+
mode?: "default" | "continuous";
|
6
|
+
}
|
7
|
+
type SkiaJSDomViewProps = SkiaDomViewProps & {
|
5
8
|
Skia: Skia;
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
mode?: "default" | "continuous";
|
10
|
+
};
|
11
|
+
export declare class SkiaJSDomView extends React.Component<SkiaJSDomViewProps> {
|
12
|
+
constructor(props: SkiaJSDomViewProps);
|
10
13
|
private _nativeId;
|
14
|
+
private requestId;
|
15
|
+
private tick;
|
11
16
|
get nativeId(): number;
|
12
17
|
componentDidUpdate(prevProps: SkiaDomViewProps & {
|
13
18
|
Skia: Skia;
|
@@ -29,3 +34,4 @@ export declare class SkiaJSDomView extends React.Component<SkiaDomViewProps & {
|
|
29
34
|
componentWillUnmount(): void;
|
30
35
|
render(): React.JSX.Element;
|
31
36
|
}
|
37
|
+
export {};
|
@@ -22,6 +22,7 @@ class SkiaJSDomView extends _react.default.Component {
|
|
22
22
|
constructor(props) {
|
23
23
|
super(props);
|
24
24
|
_defineProperty(this, "_nativeId", void 0);
|
25
|
+
_defineProperty(this, "requestId", 0);
|
25
26
|
this._nativeId = _SkiaViewNativeId.SkiaViewNativeId.current++;
|
26
27
|
const {
|
27
28
|
root,
|
@@ -35,6 +36,13 @@ class SkiaJSDomView extends _react.default.Component {
|
|
35
36
|
assertSkiaViewApi();
|
36
37
|
_api.SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
|
37
38
|
}
|
39
|
+
this.tick();
|
40
|
+
}
|
41
|
+
tick() {
|
42
|
+
this.redraw();
|
43
|
+
if (this.props.mode === "continuous") {
|
44
|
+
this.requestId = requestAnimationFrame(this.tick.bind(this));
|
45
|
+
}
|
38
46
|
}
|
39
47
|
get nativeId() {
|
40
48
|
return this._nativeId;
|
@@ -52,6 +60,7 @@ class SkiaJSDomView extends _react.default.Component {
|
|
52
60
|
assertSkiaViewApi();
|
53
61
|
_api.SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
|
54
62
|
}
|
63
|
+
this.tick();
|
55
64
|
}
|
56
65
|
|
57
66
|
/**
|
@@ -70,7 +79,6 @@ class SkiaJSDomView extends _react.default.Component {
|
|
70
79
|
redraw() {
|
71
80
|
assertSkiaViewApi();
|
72
81
|
this.draw();
|
73
|
-
//SkiaViewApi.requestRedraw(this._nativeId);
|
74
82
|
}
|
75
83
|
draw() {
|
76
84
|
const {
|
@@ -94,17 +102,18 @@ class SkiaJSDomView extends _react.default.Component {
|
|
94
102
|
componentWillUnmount() {
|
95
103
|
assertSkiaViewApi();
|
96
104
|
_api.SkiaViewApi.setJsiProperty(this._nativeId, "picture", null);
|
105
|
+
if (this.requestId) {
|
106
|
+
cancelAnimationFrame(this.requestId);
|
107
|
+
}
|
97
108
|
}
|
98
109
|
render() {
|
99
110
|
const {
|
100
|
-
mode,
|
101
111
|
debug = false,
|
102
112
|
...viewProps
|
103
113
|
} = this.props;
|
104
114
|
return /*#__PURE__*/_react.default.createElement(NativeSkiaPictureView, _extends({
|
105
115
|
collapsable: false,
|
106
116
|
nativeID: `${this._nativeId}`,
|
107
|
-
mode: mode,
|
108
117
|
debug: debug
|
109
118
|
}, viewProps));
|
110
119
|
}
|
@@ -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","nativeId","componentDidUpdate","prevProps","undefined","draw","makeImageSnapshot","rect","
|
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 ||\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,YA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ACgC,aAAa,KAAK,IAAI,IAClChC,gBAAW,CAACY,iBAAiB,KAAK,IAAI,EACtC;IACA,MAAMqB,KAAK,CAAC,8BAA8B,CAAC;EAC7C;AACF,CAAC","ignoreList":[]}
|
@@ -1,11 +1,17 @@
|
|
1
1
|
import React from "react";
|
2
2
|
import type { SkRect } from "../skia/types";
|
3
|
-
import type {
|
3
|
+
import type { SkiaPictureViewNativeProps } from "./types";
|
4
|
+
interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {
|
5
|
+
mode?: "default" | "continuous";
|
6
|
+
}
|
4
7
|
export declare class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
|
8
|
+
private requestId;
|
5
9
|
constructor(props: SkiaPictureViewProps);
|
6
10
|
private _nativeId;
|
7
11
|
get nativeId(): number;
|
8
12
|
componentDidUpdate(prevProps: SkiaPictureViewProps): void;
|
13
|
+
componentWillUnmount(): void;
|
14
|
+
private tick;
|
9
15
|
/**
|
10
16
|
* Creates a snapshot from the canvas in the surface
|
11
17
|
* @param rect Rect to use as bounds. Optional.
|
@@ -18,3 +24,4 @@ export declare class SkiaPictureView extends React.Component<SkiaPictureViewProp
|
|
18
24
|
redraw(): void;
|
19
25
|
render(): React.JSX.Element;
|
20
26
|
}
|
27
|
+
export {};
|
@@ -17,6 +17,7 @@ const NativeSkiaPictureView = _SkiaPictureViewNativeComponent.default;
|
|
17
17
|
class SkiaPictureView extends _react.default.Component {
|
18
18
|
constructor(props) {
|
19
19
|
super(props);
|
20
|
+
_defineProperty(this, "requestId", 0);
|
20
21
|
_defineProperty(this, "_nativeId", void 0);
|
21
22
|
this._nativeId = _SkiaViewNativeId.SkiaViewNativeId.current++;
|
22
23
|
const {
|
@@ -31,6 +32,7 @@ class SkiaPictureView extends _react.default.Component {
|
|
31
32
|
assertSkiaViewApi();
|
32
33
|
_api.SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
|
33
34
|
}
|
35
|
+
this.tick();
|
34
36
|
}
|
35
37
|
get nativeId() {
|
36
38
|
return this._nativeId;
|
@@ -48,6 +50,18 @@ class SkiaPictureView extends _react.default.Component {
|
|
48
50
|
assertSkiaViewApi();
|
49
51
|
_api.SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
|
50
52
|
}
|
53
|
+
this.tick();
|
54
|
+
}
|
55
|
+
componentWillUnmount() {
|
56
|
+
if (this.requestId) {
|
57
|
+
cancelAnimationFrame(this.requestId);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
tick() {
|
61
|
+
this.redraw();
|
62
|
+
if (this.props.mode === "continuous") {
|
63
|
+
this.requestId = requestAnimationFrame(this.tick.bind(this));
|
64
|
+
}
|
51
65
|
}
|
52
66
|
|
53
67
|
/**
|
@@ -76,7 +90,6 @@ class SkiaPictureView extends _react.default.Component {
|
|
76
90
|
return /*#__PURE__*/_react.default.createElement(NativeSkiaPictureView, _extends({
|
77
91
|
collapsable: false,
|
78
92
|
nativeID: `${this._nativeId}`,
|
79
|
-
mode: mode !== null && mode !== void 0 ? mode : "default",
|
80
93
|
debug: debug
|
81
94
|
}, viewProps));
|
82
95
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireDefault","require","_SkiaPictureViewNativeComponent","_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","SkiaPictureViewNativeComponent","SkiaPictureView","React","Component","constructor","props","_nativeId","SkiaViewNativeId","current","picture","onSize","assertSkiaViewApi","SkiaViewApi","setJsiProperty","nativeId","componentDidUpdate","prevProps","
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","_SkiaPictureViewNativeComponent","_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","SkiaPictureViewNativeComponent","SkiaPictureView","React","Component","constructor","props","_nativeId","SkiaViewNativeId","current","picture","onSize","assertSkiaViewApi","SkiaViewApi","setJsiProperty","tick","nativeId","componentDidUpdate","prevProps","componentWillUnmount","requestId","cancelAnimationFrame","redraw","mode","requestAnimationFrame","makeImageSnapshot","rect","requestRedraw","render","debug","viewProps","createElement","collapsable","nativeID","exports","Error"],"sources":["SkiaPictureView.tsx"],"sourcesContent":["import React from \"react\";\n\nimport type { SkRect } from \"../skia/types\";\nimport SkiaPictureViewNativeComponent from \"../specs/SkiaPictureViewNativeComponent\";\n\nimport { SkiaViewApi } from \"./api\";\nimport type { SkiaPictureViewNativeProps } from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\nconst NativeSkiaPictureView = SkiaPictureViewNativeComponent;\n\ninterface SkiaPictureViewProps extends SkiaPictureViewNativeProps {\n mode?: \"default\" | \"continuous\";\n}\n\nexport class SkiaPictureView extends React.Component<SkiaPictureViewProps> {\n private requestId = 0;\n\n constructor(props: SkiaPictureViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId.current++;\n const { picture, onSize } = props;\n if (picture) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"picture\", picture);\n }\n if (onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n this.tick();\n }\n\n private _nativeId: number;\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaPictureViewProps) {\n const { picture, onSize } = this.props;\n if (picture !== prevProps.picture) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"picture\", picture);\n }\n if (onSize !== prevProps.onSize) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"onSize\", onSize);\n }\n this.tick();\n }\n\n componentWillUnmount() {\n if (this.requestId) {\n cancelAnimationFrame(this.requestId);\n }\n }\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 /**\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 render() {\n const { mode, 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;AAGA,IAAAC,+BAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,IAAA,GAAAF,OAAA;AAEA,IAAAG,iBAAA,GAAAH,OAAA;AAAsD,SAAAD,uBAAAK,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,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;IACnB,OAAOC,gBAAW,CAACY,iBAAiB,CAAC,IAAI,CAAClB,SAAS,EAAEmB,IAAI,CAAC;EAC5D;;EAEA;AACF;AACA;EACSJ,MAAMA,CAAA,EAAG;IACdV,iBAAiB,CAAC,CAAC;IACnBC,gBAAW,CAACc,aAAa,CAAC,IAAI,CAACpB,SAAS,CAAC;EAC3C;EAEAqB,MAAMA,CAAA,EAAG;IACP,MAAM;MAAEL,IAAI;MAAEM,KAAK,GAAG,KAAK;MAAE,GAAGC;IAAU,CAAC,GAAG,IAAI,CAACxB,KAAK;IACxD,oBACEzC,MAAA,CAAAQ,OAAA,CAAA0D,aAAA,CAAC/B,qBAAqB,EAAA1B,QAAA;MACpB0D,WAAW,EAAE,KAAM;MACnBC,QAAQ,EAAE,GAAG,IAAI,CAAC1B,SAAS,EAAG;MAC9BsB,KAAK,EAAEA;IAAM,GACTC,SAAS,CACd,CAAC;EAEN;AACF;AAACI,OAAA,CAAAhC,eAAA,GAAAA,eAAA;AAED,MAAMU,iBAAiB,GAAGA,CAAA,KAAM;EAC9B,IACEC,gBAAW,KAAK,IAAI,IACpBA,gBAAW,CAACC,cAAc,KAAK,IAAI,IACnCD,gBAAW,CAACc,aAAa,KAAK,IAAI,IAClCd,gBAAW,CAACY,iBAAiB,KAAK,IAAI,EACtC;IACA,MAAMU,KAAK,CAAC,8BAA8B,CAAC;EAC7C;AACF,CAAC","ignoreList":[]}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { SkCanvas } from "../skia/types";
|
2
|
-
import type {
|
2
|
+
import type { SkiaPictureViewNativeProps } from "./types";
|
3
3
|
import { SkiaBaseWebView } from "./SkiaBaseWebView";
|
4
|
-
export declare class SkiaPictureView extends SkiaBaseWebView<
|
5
|
-
constructor(props:
|
4
|
+
export declare class SkiaPictureView extends SkiaBaseWebView<SkiaPictureViewNativeProps> {
|
5
|
+
constructor(props: SkiaPictureViewNativeProps);
|
6
6
|
protected renderInCanvas(canvas: SkCanvas): void;
|
7
7
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_SkiaBaseWebView","require","SkiaPictureView","SkiaBaseWebView","constructor","props","renderInCanvas","canvas","picture","drawPicture","exports"],"sources":["SkiaPictureView.web.tsx"],"sourcesContent":["import type { SkCanvas } from \"../skia/types\";\n\nimport type {
|
1
|
+
{"version":3,"names":["_SkiaBaseWebView","require","SkiaPictureView","SkiaBaseWebView","constructor","props","renderInCanvas","canvas","picture","drawPicture","exports"],"sources":["SkiaPictureView.web.tsx"],"sourcesContent":["import type { SkCanvas } from \"../skia/types\";\n\nimport type { SkiaPictureViewNativeProps } from \"./types\";\nimport { SkiaBaseWebView } from \"./SkiaBaseWebView\";\n\nexport class SkiaPictureView extends SkiaBaseWebView<SkiaPictureViewNativeProps> {\n constructor(props: SkiaPictureViewNativeProps) {\n super(props);\n }\n\n protected renderInCanvas(canvas: SkCanvas): void {\n if (this.props.picture) {\n canvas.drawPicture(this.props.picture);\n }\n }\n}\n"],"mappings":";;;;;;AAGA,IAAAA,gBAAA,GAAAC,OAAA;AAEO,MAAMC,eAAe,SAASC,gCAAe,CAA6B;EAC/EC,WAAWA,CAACC,KAAiC,EAAE;IAC7C,KAAK,CAACA,KAAK,CAAC;EACd;EAEUC,cAAcA,CAACC,MAAgB,EAAQ;IAC/C,IAAI,IAAI,CAACF,KAAK,CAACG,OAAO,EAAE;MACtBD,MAAM,CAACE,WAAW,CAAC,IAAI,CAACJ,KAAK,CAACG,OAAO,CAAC;IACxC;EACF;AACF;AAACE,OAAA,CAAAR,eAAA,GAAAA,eAAA","ignoreList":[]}
|
@@ -2,9 +2,7 @@ import type { ViewProps } from "react-native";
|
|
2
2
|
import type { GroupProps, RenderNode } from "../dom/types";
|
3
3
|
import type { SkImage, SkPicture, SkRect, SkSize } from "../skia/types";
|
4
4
|
import type { SharedValueType } from "../renderer/processors/Animations/Animations";
|
5
|
-
export type DrawMode = "continuous" | "default";
|
6
5
|
export type NativeSkiaViewProps = ViewProps & {
|
7
|
-
mode?: DrawMode;
|
8
6
|
debug?: boolean;
|
9
7
|
};
|
10
8
|
export interface DrawingInfo {
|
@@ -19,14 +17,6 @@ export interface ISkiaViewApi {
|
|
19
17
|
makeImageSnapshotAsync: (nativeId: number, rect?: SkRect) => Promise<SkImage>;
|
20
18
|
}
|
21
19
|
export interface SkiaBaseViewProps extends ViewProps {
|
22
|
-
/**
|
23
|
-
* Sets the drawing mode for the skia view. There are two drawing
|
24
|
-
* modes, "continuous" and "default", where the continuous mode will
|
25
|
-
* continuously redraw the view, and the default mode will only
|
26
|
-
* redraw when any of the regular react properties are changed like
|
27
|
-
* sizes and margins.
|
28
|
-
*/
|
29
|
-
mode?: DrawMode;
|
30
20
|
/**
|
31
21
|
* When set to true the view will display information about the
|
32
22
|
* average time it takes to render.
|
@@ -38,9 +28,9 @@ export interface SkiaBaseViewProps extends ViewProps {
|
|
38
28
|
*/
|
39
29
|
onSize?: SharedValueType<SkSize>;
|
40
30
|
}
|
41
|
-
export interface
|
31
|
+
export interface SkiaPictureViewNativeProps extends SkiaBaseViewProps {
|
42
32
|
picture?: SkPicture;
|
43
33
|
}
|
44
|
-
export interface
|
34
|
+
export interface SkiaDomViewNativeProps extends SkiaBaseViewProps {
|
45
35
|
root?: RenderNode<GroupProps>;
|
46
36
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { ViewProps } from \"react-native\";\n\nimport type { GroupProps, RenderNode } from \"../dom/types\";\nimport type { SkImage, SkPicture, SkRect, SkSize } from \"../skia/types\";\nimport type { SharedValueType } from \"../renderer/processors/Animations/Animations\";\n\nexport type
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { ViewProps } from \"react-native\";\n\nimport type { GroupProps, RenderNode } from \"../dom/types\";\nimport type { SkImage, SkPicture, SkRect, SkSize } from \"../skia/types\";\nimport type { SharedValueType } from \"../renderer/processors/Animations/Animations\";\n\nexport type NativeSkiaViewProps = ViewProps & {\n debug?: boolean;\n};\n\nexport interface DrawingInfo {\n width: number;\n height: number;\n timestamp: number;\n}\n\nexport interface ISkiaViewApi {\n setJsiProperty: <T>(nativeId: number, name: string, value: T) => void;\n requestRedraw: (nativeId: number) => void;\n makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;\n makeImageSnapshotAsync: (nativeId: number, rect?: SkRect) => Promise<SkImage>;\n}\n\nexport interface SkiaBaseViewProps extends ViewProps {\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 * Pass an animated value to the onSize property to get updates when\n * the Skia view is resized.\n */\n onSize?: SharedValueType<SkSize>;\n}\n\nexport interface SkiaPictureViewNativeProps extends SkiaBaseViewProps {\n picture?: SkPicture;\n}\n\nexport interface SkiaDomViewNativeProps extends SkiaBaseViewProps {\n root?: RenderNode<GroupProps>;\n}\n"],"mappings":"","ignoreList":[]}
|
@@ -6,5 +6,6 @@ export declare const useCanvasRef: () => React.RefObject<SkiaDomView>;
|
|
6
6
|
export interface CanvasProps extends SkiaBaseViewProps {
|
7
7
|
ref?: RefObject<SkiaDomView>;
|
8
8
|
children: ReactNode;
|
9
|
+
mode?: "default" | "continuous";
|
9
10
|
}
|
10
11
|
export declare const Canvas: FunctionComponent<CanvasProps & React.RefAttributes<SkiaDomView>>;
|
@@ -27,7 +27,7 @@ export const Canvas = /*#__PURE__*/forwardRef(({
|
|
27
27
|
children,
|
28
28
|
style,
|
29
29
|
debug,
|
30
|
-
mode,
|
30
|
+
mode = "default",
|
31
31
|
onSize: _onSize,
|
32
32
|
onLayout: _onLayout,
|
33
33
|
...props
|
@@ -61,19 +61,19 @@ export const Canvas = /*#__PURE__*/forwardRef(({
|
|
61
61
|
style: style,
|
62
62
|
root: root.dom,
|
63
63
|
onLayout: onLayout,
|
64
|
-
|
65
|
-
|
64
|
+
debug: debug,
|
65
|
+
mode: mode
|
66
66
|
}, props));
|
67
67
|
} else {
|
68
68
|
return /*#__PURE__*/React.createElement(SkiaJSDomView, _extends({
|
69
|
-
Skia: Skia
|
69
|
+
Skia: Skia,
|
70
|
+
mode: mode
|
70
71
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
71
72
|
,
|
72
73
|
ref: ref,
|
73
74
|
style: style,
|
74
75
|
root: root.dom,
|
75
76
|
onLayout: onLayout,
|
76
|
-
mode: mode,
|
77
77
|
debug: debug
|
78
78
|
}, props));
|
79
79
|
}
|