@shopify/react-native-skia 2.2.8 → 2.2.10
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.
- package/android/build.gradle +0 -11
- package/cpp/api/JsiSkParagraph.h +40 -8
- package/lib/commonjs/renderer/Canvas.d.ts +1 -0
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/__tests__/e2e/ParagraphMethods.spec.d.ts +1 -0
- package/lib/commonjs/renderer/__tests__/e2e/setup/Paragraph.d.ts +1 -1
- package/lib/commonjs/skia/types/Paragraph/Paragraph.d.ts +31 -1
- package/lib/commonjs/skia/types/Paragraph/Paragraph.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkParagraph.d.ts +2 -2
- package/lib/commonjs/skia/web/JsiSkParagraph.js +4 -18
- package/lib/commonjs/skia/web/JsiSkParagraph.js.map +1 -1
- package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +3 -3
- package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -2
- package/lib/commonjs/views/SkiaPictureView.web.d.ts +10 -6
- package/lib/commonjs/views/SkiaPictureView.web.js +253 -20
- package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
- package/lib/commonjs/views/types.d.ts +1 -0
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +1 -0
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/__tests__/e2e/ParagraphMethods.spec.d.ts +1 -0
- package/lib/module/renderer/__tests__/e2e/setup/Paragraph.d.ts +1 -1
- package/lib/module/skia/types/Paragraph/Paragraph.d.ts +31 -1
- package/lib/module/skia/types/Paragraph/Paragraph.js.map +1 -1
- package/lib/module/skia/web/JsiSkParagraph.d.ts +2 -2
- package/lib/module/skia/web/JsiSkParagraph.js +4 -18
- package/lib/module/skia/web/JsiSkParagraph.js.map +1 -1
- package/lib/module/specs/NativeSkiaModule.web.d.ts +3 -3
- package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -2
- package/lib/module/views/SkiaPictureView.web.d.ts +10 -6
- package/lib/module/views/SkiaPictureView.web.js +251 -18
- package/lib/module/views/SkiaPictureView.web.js.map +1 -1
- package/lib/module/views/types.d.ts +1 -0
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +11 -1
- package/lib/typescript/lib/commonjs/views/SkiaPictureView.web.d.ts +1 -6
- package/lib/typescript/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -2
- package/lib/typescript/lib/module/views/SkiaPictureView.web.d.ts +2 -6
- package/lib/typescript/src/renderer/Canvas.d.ts +1 -0
- package/lib/typescript/src/renderer/__tests__/e2e/ParagraphMethods.spec.d.ts +1 -0
- package/lib/typescript/src/renderer/__tests__/e2e/setup/Paragraph.d.ts +1 -1
- package/lib/typescript/src/skia/types/Paragraph/Paragraph.d.ts +31 -1
- package/lib/typescript/src/skia/web/JsiSkParagraph.d.ts +2 -2
- package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +3 -3
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.web.d.ts +1 -2
- package/lib/typescript/src/views/SkiaPictureView.web.d.ts +10 -6
- package/lib/typescript/src/views/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/renderer/Canvas.tsx +1 -0
- package/src/renderer/__tests__/e2e/ParagraphMethods.spec.tsx +388 -0
- package/src/skia/types/Paragraph/Paragraph.ts +32 -1
- package/src/skia/web/JsiSkParagraph.ts +19 -28
- package/src/specs/NativeSkiaModule.web.ts +4 -4
- package/src/views/SkiaPictureView.web.tsx +312 -18
- package/src/views/types.ts +4 -0
- package/lib/commonjs/views/SkiaBaseWebView.d.ts +0 -40
- package/lib/commonjs/views/SkiaBaseWebView.js +0 -143
- package/lib/commonjs/views/SkiaBaseWebView.js.map +0 -1
- package/lib/module/views/SkiaBaseWebView.d.ts +0 -40
- package/lib/module/views/SkiaBaseWebView.js +0 -136
- package/lib/module/views/SkiaBaseWebView.js.map +0 -1
- package/lib/typescript/lib/commonjs/views/SkiaBaseWebView.d.ts +0 -39
- package/lib/typescript/lib/module/views/SkiaBaseWebView.d.ts +0 -36
- package/lib/typescript/src/views/SkiaBaseWebView.d.ts +0 -40
- package/src/views/SkiaBaseWebView.tsx +0 -140
@@ -1,9 +1,13 @@
|
|
1
|
-
import
|
1
|
+
import React from "react";
|
2
|
+
import type { SkRect, SkPicture, SkImage } from "../skia/types";
|
2
3
|
import type { SkiaPictureViewNativeProps } from "./types";
|
3
|
-
|
4
|
-
export declare class SkiaPictureView extends SkiaBaseWebView<SkiaPictureViewNativeProps> {
|
5
|
-
private picture;
|
6
|
-
constructor(props: SkiaPictureViewNativeProps);
|
4
|
+
export interface SkiaPictureViewHandle {
|
7
5
|
setPicture(picture: SkPicture): void;
|
8
|
-
|
6
|
+
getSize(): {
|
7
|
+
width: number;
|
8
|
+
height: number;
|
9
|
+
};
|
10
|
+
redraw(): void;
|
11
|
+
makeImageSnapshot(rect?: SkRect): SkImage | null;
|
9
12
|
}
|
13
|
+
export declare const SkiaPictureView: React.ForwardRefExoticComponent<SkiaPictureViewNativeProps & React.RefAttributes<SkiaPictureViewHandle>>;
|
@@ -1,29 +1,262 @@
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
1
2
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
2
3
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
3
4
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
/* global HTMLCanvasElement */
|
6
|
+
import React, { useRef, useEffect, useCallback, useImperativeHandle, forwardRef } from "react";
|
7
|
+
import { JsiSkSurface } from "../skia/web/JsiSkSurface";
|
8
|
+
import { Platform } from "../Platform";
|
9
|
+
import { SkiaViewNativeId } from "./SkiaViewNativeId";
|
10
|
+
class WebGLRenderer {
|
11
|
+
constructor(canvas, pd) {
|
12
|
+
this.canvas = canvas;
|
13
|
+
this.pd = pd;
|
14
|
+
_defineProperty(this, "surface", null);
|
15
|
+
this.onResize();
|
16
|
+
}
|
17
|
+
makeImageSnapshot(picture, rect) {
|
18
|
+
if (!this.surface) {
|
19
|
+
return null;
|
20
|
+
}
|
21
|
+
const canvas = this.surface.getCanvas();
|
22
|
+
canvas.clear(CanvasKit.TRANSPARENT);
|
23
|
+
this.draw(picture);
|
24
|
+
this.surface.ref.flush();
|
25
|
+
return this.surface.makeImageSnapshot(rect);
|
26
|
+
}
|
27
|
+
onResize() {
|
9
28
|
const {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
29
|
+
canvas,
|
30
|
+
pd
|
31
|
+
} = this;
|
32
|
+
canvas.width = canvas.clientWidth * pd;
|
33
|
+
canvas.height = canvas.clientHeight * pd;
|
34
|
+
const surface = CanvasKit.MakeWebGLCanvasSurface(canvas);
|
35
|
+
const ctx = canvas.getContext("webgl2");
|
36
|
+
if (ctx) {
|
37
|
+
ctx.drawingBufferColorSpace = "display-p3";
|
38
|
+
}
|
39
|
+
if (!surface) {
|
40
|
+
throw new Error("Could not create surface");
|
41
|
+
}
|
42
|
+
this.surface = new JsiSkSurface(CanvasKit, surface);
|
43
|
+
}
|
44
|
+
draw(picture) {
|
45
|
+
if (this.surface) {
|
46
|
+
const canvas = this.surface.getCanvas();
|
47
|
+
canvas.clear(Float32Array.of(0, 0, 0, 0));
|
48
|
+
canvas.save();
|
49
|
+
canvas.scale(pd, pd);
|
50
|
+
canvas.drawPicture(picture);
|
51
|
+
canvas.restore();
|
52
|
+
this.surface.ref.flush();
|
53
|
+
}
|
54
|
+
}
|
55
|
+
dispose() {
|
56
|
+
if (this.surface) {
|
57
|
+
var _this$canvas;
|
58
|
+
(_this$canvas = this.canvas) === null || _this$canvas === void 0 || (_this$canvas = _this$canvas.getContext("webgl2")) === null || _this$canvas === void 0 || (_this$canvas = _this$canvas.getExtension("WEBGL_lose_context")) === null || _this$canvas === void 0 || _this$canvas.loseContext();
|
59
|
+
this.surface.ref.delete();
|
60
|
+
this.surface = null;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
class StaticWebGLRenderer {
|
65
|
+
constructor(canvas, pd) {
|
66
|
+
this.canvas = canvas;
|
67
|
+
this.pd = pd;
|
68
|
+
_defineProperty(this, "cachedImage", null);
|
69
|
+
}
|
70
|
+
onResize() {
|
71
|
+
this.cachedImage = null;
|
72
|
+
}
|
73
|
+
renderPictureToSurface(picture) {
|
74
|
+
const tempCanvas = new OffscreenCanvas(this.canvas.clientWidth * this.pd, this.canvas.clientHeight * this.pd);
|
75
|
+
let surface = null;
|
76
|
+
try {
|
77
|
+
const webglSurface = CanvasKit.MakeWebGLCanvasSurface(tempCanvas);
|
78
|
+
const ctx = tempCanvas.getContext("webgl2");
|
79
|
+
if (ctx) {
|
80
|
+
ctx.drawingBufferColorSpace = "display-p3";
|
81
|
+
}
|
82
|
+
if (!webglSurface) {
|
83
|
+
throw new Error("Could not create WebGL surface");
|
84
|
+
}
|
85
|
+
surface = new JsiSkSurface(CanvasKit, webglSurface);
|
86
|
+
const skiaCanvas = surface.getCanvas();
|
87
|
+
skiaCanvas.clear(Float32Array.of(0, 0, 0, 0));
|
88
|
+
skiaCanvas.save();
|
89
|
+
skiaCanvas.scale(this.pd, this.pd);
|
90
|
+
skiaCanvas.drawPicture(picture);
|
91
|
+
skiaCanvas.restore();
|
92
|
+
surface.ref.flush();
|
93
|
+
return {
|
94
|
+
surface,
|
95
|
+
tempCanvas
|
96
|
+
};
|
97
|
+
} catch (error) {
|
98
|
+
if (surface) {
|
99
|
+
surface.ref.delete();
|
100
|
+
}
|
101
|
+
this.cleanupWebGLContext(tempCanvas);
|
102
|
+
return null;
|
14
103
|
}
|
15
|
-
global.SkiaViewApi.registerView(nativeID, this);
|
16
104
|
}
|
17
|
-
|
18
|
-
|
19
|
-
|
105
|
+
cleanupWebGLContext(tempCanvas) {
|
106
|
+
const ctx = tempCanvas.getContext("webgl2");
|
107
|
+
if (ctx) {
|
108
|
+
const loseContext = ctx.getExtension("WEBGL_lose_context");
|
109
|
+
if (loseContext) {
|
110
|
+
loseContext.loseContext();
|
111
|
+
}
|
112
|
+
}
|
20
113
|
}
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
114
|
+
draw(picture) {
|
115
|
+
const renderResult = this.renderPictureToSurface(picture);
|
116
|
+
if (!renderResult) {
|
117
|
+
return;
|
118
|
+
}
|
119
|
+
const {
|
120
|
+
tempCanvas
|
121
|
+
} = renderResult;
|
122
|
+
const ctx2d = this.canvas.getContext("2d");
|
123
|
+
if (!ctx2d) {
|
124
|
+
throw new Error("Could not get 2D context");
|
26
125
|
}
|
126
|
+
|
127
|
+
// Set canvas dimensions to match pixel density
|
128
|
+
this.canvas.width = this.canvas.clientWidth * this.pd;
|
129
|
+
this.canvas.height = this.canvas.clientHeight * this.pd;
|
130
|
+
|
131
|
+
// Draw the tempCanvas scaled down to the display size
|
132
|
+
ctx2d.drawImage(tempCanvas, 0, 0, tempCanvas.width, tempCanvas.height, 0, 0, this.canvas.clientWidth * this.pd, this.canvas.clientHeight * this.pd);
|
133
|
+
this.cleanupWebGLContext(tempCanvas);
|
134
|
+
}
|
135
|
+
makeImageSnapshot(picture, rect) {
|
136
|
+
if (!this.cachedImage) {
|
137
|
+
const renderResult = this.renderPictureToSurface(picture);
|
138
|
+
if (!renderResult) {
|
139
|
+
return null;
|
140
|
+
}
|
141
|
+
const {
|
142
|
+
surface,
|
143
|
+
tempCanvas
|
144
|
+
} = renderResult;
|
145
|
+
try {
|
146
|
+
this.cachedImage = surface.makeImageSnapshot(rect);
|
147
|
+
} catch (error) {
|
148
|
+
console.error("Error creating image snapshot:", error);
|
149
|
+
} finally {
|
150
|
+
surface.ref.delete();
|
151
|
+
this.cleanupWebGLContext(tempCanvas);
|
152
|
+
}
|
153
|
+
}
|
154
|
+
return this.cachedImage;
|
155
|
+
}
|
156
|
+
dispose() {
|
157
|
+
var _this$cachedImage;
|
158
|
+
(_this$cachedImage = this.cachedImage) === null || _this$cachedImage === void 0 || _this$cachedImage.dispose();
|
159
|
+
this.cachedImage = null;
|
27
160
|
}
|
28
161
|
}
|
162
|
+
const pd = Platform.PixelRatio;
|
163
|
+
export const SkiaPictureView = /*#__PURE__*/forwardRef((props, ref) => {
|
164
|
+
const canvasRef = useRef(null);
|
165
|
+
const renderer = useRef(null);
|
166
|
+
const redrawRequestsRef = useRef(0);
|
167
|
+
const requestIdRef = useRef(0);
|
168
|
+
const pictureRef = useRef(null);
|
169
|
+
const {
|
170
|
+
picture,
|
171
|
+
onLayout
|
172
|
+
} = props;
|
173
|
+
const redraw = useCallback(() => {
|
174
|
+
redrawRequestsRef.current++;
|
175
|
+
}, []);
|
176
|
+
const getSize = useCallback(() => {
|
177
|
+
var _canvasRef$current, _canvasRef$current2;
|
178
|
+
return {
|
179
|
+
width: ((_canvasRef$current = canvasRef.current) === null || _canvasRef$current === void 0 ? void 0 : _canvasRef$current.clientWidth) || 0,
|
180
|
+
height: ((_canvasRef$current2 = canvasRef.current) === null || _canvasRef$current2 === void 0 ? void 0 : _canvasRef$current2.clientHeight) || 0
|
181
|
+
};
|
182
|
+
}, []);
|
183
|
+
const setPicture = useCallback(newPicture => {
|
184
|
+
pictureRef.current = newPicture;
|
185
|
+
redraw();
|
186
|
+
}, [redraw]);
|
187
|
+
const makeImageSnapshot = useCallback(rect => {
|
188
|
+
if (renderer.current && pictureRef.current) {
|
189
|
+
return renderer.current.makeImageSnapshot(pictureRef.current, rect);
|
190
|
+
}
|
191
|
+
return null;
|
192
|
+
}, []);
|
193
|
+
const tick = useCallback(() => {
|
194
|
+
if (redrawRequestsRef.current > 0) {
|
195
|
+
redrawRequestsRef.current = 0;
|
196
|
+
if (renderer.current && pictureRef.current) {
|
197
|
+
renderer.current.draw(pictureRef.current);
|
198
|
+
}
|
199
|
+
}
|
200
|
+
requestIdRef.current = requestAnimationFrame(tick);
|
201
|
+
}, []);
|
202
|
+
const onLayoutEvent = useCallback(evt => {
|
203
|
+
const canvas = canvasRef.current;
|
204
|
+
if (canvas) {
|
205
|
+
renderer.current = props.__destroyWebGLContextAfterRender === true ? new StaticWebGLRenderer(canvas, pd) : new WebGLRenderer(canvas, pd);
|
206
|
+
if (pictureRef.current) {
|
207
|
+
renderer.current.draw(pictureRef.current);
|
208
|
+
}
|
209
|
+
}
|
210
|
+
if (onLayout) {
|
211
|
+
onLayout(evt);
|
212
|
+
}
|
213
|
+
}, [onLayout, props.__destroyWebGLContextAfterRender]);
|
214
|
+
useImperativeHandle(ref, () => ({
|
215
|
+
setPicture,
|
216
|
+
getSize,
|
217
|
+
redraw,
|
218
|
+
makeImageSnapshot
|
219
|
+
}), [setPicture, getSize, redraw, makeImageSnapshot]);
|
220
|
+
useEffect(() => {
|
221
|
+
var _props$nativeID;
|
222
|
+
const nativeID = (_props$nativeID = props.nativeID) !== null && _props$nativeID !== void 0 ? _props$nativeID : `${SkiaViewNativeId.current++}`;
|
223
|
+
global.SkiaViewApi.registerView(nativeID, {
|
224
|
+
setPicture,
|
225
|
+
getSize,
|
226
|
+
redraw,
|
227
|
+
makeImageSnapshot
|
228
|
+
});
|
229
|
+
if (props.picture) {
|
230
|
+
setPicture(props.picture);
|
231
|
+
}
|
232
|
+
}, [setPicture, getSize, redraw, makeImageSnapshot, props]);
|
233
|
+
useEffect(() => {
|
234
|
+
tick();
|
235
|
+
return () => {
|
236
|
+
cancelAnimationFrame(requestIdRef.current);
|
237
|
+
if (renderer.current) {
|
238
|
+
renderer.current.dispose();
|
239
|
+
renderer.current = null;
|
240
|
+
}
|
241
|
+
};
|
242
|
+
}, [tick]);
|
243
|
+
useEffect(() => {
|
244
|
+
if (renderer.current && pictureRef.current) {
|
245
|
+
renderer.current.draw(pictureRef.current);
|
246
|
+
}
|
247
|
+
}, [picture, redraw]);
|
248
|
+
const {
|
249
|
+
debug = false,
|
250
|
+
...viewProps
|
251
|
+
} = props;
|
252
|
+
return /*#__PURE__*/React.createElement(Platform.View, _extends({}, viewProps, {
|
253
|
+
onLayout: onLayoutEvent
|
254
|
+
}), /*#__PURE__*/React.createElement("canvas", {
|
255
|
+
ref: canvasRef,
|
256
|
+
style: {
|
257
|
+
display: "flex",
|
258
|
+
flex: 1
|
259
|
+
}
|
260
|
+
}));
|
261
|
+
});
|
29
262
|
//# sourceMappingURL=SkiaPictureView.web.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["SkiaBaseWebView","SkiaPictureView","constructor","props","_defineProperty","nativeID","Error","global","SkiaViewApi","registerView","setPicture","picture","redraw","renderInCanvas","canvas","drawPicture"],"sources":["SkiaPictureView.web.tsx"],"sourcesContent":["import type { SkCanvas, SkPicture } from \"../skia/types\";\nimport type { ISkiaViewApiWeb } from \"../specs/NativeSkiaModule.web\";\n\nimport type { SkiaPictureViewNativeProps } from \"./types\";\nimport { SkiaBaseWebView } from \"./SkiaBaseWebView\";\n\nexport class SkiaPictureView extends SkiaBaseWebView<SkiaPictureViewNativeProps> {\n private picture: SkPicture | null = null;\n\n constructor(props: SkiaPictureViewNativeProps) {\n super(props);\n const { nativeID } = props;\n if (!nativeID) {\n throw new Error(\"SkiaPictureView requires a nativeID prop\");\n }\n (global.SkiaViewApi as ISkiaViewApiWeb).registerView(nativeID, this);\n }\n\n public setPicture(picture: SkPicture) {\n this.picture = picture;\n this.redraw();\n }\n\n protected renderInCanvas(canvas: SkCanvas): void {\n if (this.props.picture) {\n canvas.drawPicture(this.props.picture);\n } else if (this.picture) {\n canvas.drawPicture(this.picture);\n }\n }\n}\n"],"mappings":";;;AAIA,SAASA,eAAe,QAAQ,mBAAmB;AAEnD,OAAO,MAAMC,eAAe,SAASD,eAAe,CAA6B;EAG/EE,WAAWA,CAACC,KAAiC,EAAE;IAC7C,KAAK,CAACA,KAAK,CAAC;IAACC,eAAA,kBAHqB,IAAI;IAItC,MAAM;MAAEC;IAAS,CAAC,GAAGF,KAAK;IAC1B,IAAI,CAACE,QAAQ,EAAE;MACb,MAAM,IAAIC,KAAK,CAAC,0CAA0C,CAAC;IAC7D;IACCC,MAAM,CAACC,WAAW,CAAqBC,YAAY,CAACJ,QAAQ,EAAE,IAAI,CAAC;EACtE;EAEOK,UAAUA,CAACC,OAAkB,EAAE;IACpC,IAAI,CAACA,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,MAAM,CAAC,CAAC;EACf;EAEUC,cAAcA,CAACC,MAAgB,EAAQ;IAC/C,IAAI,IAAI,CAACX,KAAK,CAACQ,OAAO,EAAE;MACtBG,MAAM,CAACC,WAAW,CAAC,IAAI,CAACZ,KAAK,CAACQ,OAAO,CAAC;IACxC,CAAC,MAAM,IAAI,IAAI,CAACA,OAAO,EAAE;MACvBG,MAAM,CAACC,WAAW,CAAC,IAAI,CAACJ,OAAO,CAAC;IAClC;EACF;AACF","ignoreList":[]}
|
1
|
+
{"version":3,"names":["React","useRef","useEffect","useCallback","useImperativeHandle","forwardRef","JsiSkSurface","Platform","SkiaViewNativeId","WebGLRenderer","constructor","canvas","pd","_defineProperty","onResize","makeImageSnapshot","picture","rect","surface","getCanvas","clear","CanvasKit","TRANSPARENT","draw","ref","flush","width","clientWidth","height","clientHeight","MakeWebGLCanvasSurface","ctx","getContext","drawingBufferColorSpace","Error","Float32Array","of","save","scale","drawPicture","restore","dispose","_this$canvas","getExtension","loseContext","delete","StaticWebGLRenderer","cachedImage","renderPictureToSurface","tempCanvas","OffscreenCanvas","webglSurface","skiaCanvas","error","cleanupWebGLContext","renderResult","ctx2d","drawImage","console","_this$cachedImage","PixelRatio","SkiaPictureView","props","canvasRef","renderer","redrawRequestsRef","requestIdRef","pictureRef","onLayout","redraw","current","getSize","_canvasRef$current","_canvasRef$current2","setPicture","newPicture","tick","requestAnimationFrame","onLayoutEvent","evt","__destroyWebGLContextAfterRender","_props$nativeID","nativeID","global","SkiaViewApi","registerView","cancelAnimationFrame","debug","viewProps","createElement","View","_extends","style","display","flex"],"sources":["SkiaPictureView.web.tsx"],"sourcesContent":["/* global HTMLCanvasElement */\nimport React, {\n useRef,\n useEffect,\n useCallback,\n useImperativeHandle,\n forwardRef,\n} from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\n\nimport type { SkRect, SkPicture, SkImage } from \"../skia/types\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\nimport { Platform } from \"../Platform\";\nimport type { ISkiaViewApiWeb } from \"../specs/NativeSkiaModule.web\";\n\nimport type { SkiaPictureViewNativeProps } from \"./types\";\nimport { SkiaViewNativeId } from \"./SkiaViewNativeId\";\n\ninterface Renderer {\n onResize(): void;\n draw(picture: SkPicture): void;\n makeImageSnapshot(picture: SkPicture, rect?: SkRect): SkImage | null;\n dispose(): void;\n}\n\nclass WebGLRenderer implements Renderer {\n private surface: JsiSkSurface | null = null;\n\n constructor(private canvas: HTMLCanvasElement, private pd: number) {\n this.onResize();\n }\n\n makeImageSnapshot(picture: SkPicture, rect?: SkRect): SkImage | null {\n if (!this.surface) {\n return null;\n }\n const canvas = this.surface.getCanvas();\n canvas!.clear(CanvasKit.TRANSPARENT);\n this.draw(picture);\n this.surface.ref.flush();\n return this.surface.makeImageSnapshot(rect);\n }\n\n onResize() {\n const { canvas, pd } = this;\n canvas.width = canvas.clientWidth * pd;\n canvas.height = canvas.clientHeight * pd;\n const surface = CanvasKit.MakeWebGLCanvasSurface(canvas);\n const ctx = canvas.getContext(\"webgl2\");\n if (ctx) {\n ctx.drawingBufferColorSpace = \"display-p3\";\n }\n if (!surface) {\n throw new Error(\"Could not create surface\");\n }\n this.surface = new JsiSkSurface(CanvasKit, surface);\n }\n\n draw(picture: SkPicture) {\n if (this.surface) {\n const canvas = this.surface.getCanvas();\n canvas.clear(Float32Array.of(0, 0, 0, 0));\n canvas.save();\n canvas.scale(pd, pd);\n canvas.drawPicture(picture);\n canvas.restore();\n this.surface.ref.flush();\n }\n }\n\n dispose(): void {\n if (this.surface) {\n this.canvas\n ?.getContext(\"webgl2\")\n ?.getExtension(\"WEBGL_lose_context\")\n ?.loseContext();\n this.surface.ref.delete();\n this.surface = null;\n }\n }\n}\n\nclass StaticWebGLRenderer implements Renderer {\n private cachedImage: SkImage | null = null;\n\n constructor(private canvas: HTMLCanvasElement, private pd: number) {}\n\n onResize(): void {\n this.cachedImage = null;\n }\n\n private renderPictureToSurface(\n picture: SkPicture\n ): { surface: JsiSkSurface; tempCanvas: OffscreenCanvas } | null {\n const tempCanvas = new OffscreenCanvas(\n this.canvas.clientWidth * this.pd,\n this.canvas.clientHeight * this.pd\n );\n\n let surface: JsiSkSurface | null = null;\n\n try {\n const webglSurface = CanvasKit.MakeWebGLCanvasSurface(tempCanvas);\n const ctx = tempCanvas.getContext(\"webgl2\");\n if (ctx) {\n ctx.drawingBufferColorSpace = \"display-p3\";\n }\n\n if (!webglSurface) {\n throw new Error(\"Could not create WebGL surface\");\n }\n\n surface = new JsiSkSurface(CanvasKit, webglSurface);\n\n const skiaCanvas = surface.getCanvas();\n skiaCanvas.clear(Float32Array.of(0, 0, 0, 0));\n skiaCanvas.save();\n skiaCanvas.scale(this.pd, this.pd);\n skiaCanvas.drawPicture(picture);\n skiaCanvas.restore();\n surface.ref.flush();\n\n return { surface, tempCanvas };\n } catch (error) {\n if (surface) {\n surface.ref.delete();\n }\n this.cleanupWebGLContext(tempCanvas);\n return null;\n }\n }\n\n private cleanupWebGLContext(tempCanvas: OffscreenCanvas): void {\n const ctx = tempCanvas.getContext(\"webgl2\");\n if (ctx) {\n const loseContext = ctx.getExtension(\"WEBGL_lose_context\");\n if (loseContext) {\n loseContext.loseContext();\n }\n }\n }\n\n draw(picture: SkPicture): void {\n const renderResult = this.renderPictureToSurface(picture);\n if (!renderResult) {\n return;\n }\n const { tempCanvas } = renderResult;\n const ctx2d = this.canvas.getContext(\"2d\");\n if (!ctx2d) {\n throw new Error(\"Could not get 2D context\");\n }\n\n // Set canvas dimensions to match pixel density\n this.canvas.width = this.canvas.clientWidth * this.pd;\n this.canvas.height = this.canvas.clientHeight * this.pd;\n\n // Draw the tempCanvas scaled down to the display size\n ctx2d.drawImage(\n tempCanvas,\n 0,\n 0,\n tempCanvas.width,\n tempCanvas.height,\n 0,\n 0,\n this.canvas.clientWidth * this.pd,\n this.canvas.clientHeight * this.pd\n );\n\n this.cleanupWebGLContext(tempCanvas);\n }\n\n makeImageSnapshot(picture: SkPicture, rect?: SkRect): SkImage | null {\n if (!this.cachedImage) {\n const renderResult = this.renderPictureToSurface(picture);\n if (!renderResult) {\n return null;\n }\n\n const { surface, tempCanvas } = renderResult;\n\n try {\n this.cachedImage = surface.makeImageSnapshot(rect);\n } catch (error) {\n console.error(\"Error creating image snapshot:\", error);\n } finally {\n surface.ref.delete();\n this.cleanupWebGLContext(tempCanvas);\n }\n }\n\n return this.cachedImage;\n }\n\n dispose(): void {\n this.cachedImage?.dispose();\n this.cachedImage = null;\n }\n}\n\nconst pd = Platform.PixelRatio;\n\nexport interface SkiaPictureViewHandle {\n setPicture(picture: SkPicture): void;\n getSize(): { width: number; height: number };\n redraw(): void;\n makeImageSnapshot(rect?: SkRect): SkImage | null;\n}\n\nexport const SkiaPictureView = forwardRef<\n SkiaPictureViewHandle,\n SkiaPictureViewNativeProps\n>((props, ref) => {\n const canvasRef = useRef<HTMLCanvasElement | null>(null);\n const renderer = useRef<Renderer | null>(null);\n const redrawRequestsRef = useRef(0);\n const requestIdRef = useRef(0);\n const pictureRef = useRef<SkPicture | null>(null);\n\n const { picture, onLayout } = props;\n\n const redraw = useCallback(() => {\n redrawRequestsRef.current++;\n }, []);\n\n const getSize = useCallback(() => {\n return {\n width: canvasRef.current?.clientWidth || 0,\n height: canvasRef.current?.clientHeight || 0,\n };\n }, []);\n\n const setPicture = useCallback(\n (newPicture: SkPicture) => {\n pictureRef.current = newPicture;\n redraw();\n },\n [redraw]\n );\n\n const makeImageSnapshot = useCallback((rect?: SkRect) => {\n if (renderer.current && pictureRef.current) {\n return renderer.current.makeImageSnapshot(pictureRef.current, rect);\n }\n return null;\n }, []);\n\n const tick = useCallback(() => {\n if (redrawRequestsRef.current > 0) {\n redrawRequestsRef.current = 0;\n if (renderer.current && pictureRef.current) {\n renderer.current.draw(pictureRef.current);\n }\n }\n requestIdRef.current = requestAnimationFrame(tick);\n }, []);\n\n const onLayoutEvent = useCallback(\n (evt: LayoutChangeEvent) => {\n const canvas = canvasRef.current;\n if (canvas) {\n renderer.current =\n props.__destroyWebGLContextAfterRender === true\n ? new StaticWebGLRenderer(canvas, pd)\n : new WebGLRenderer(canvas, pd);\n if (pictureRef.current) {\n renderer.current.draw(pictureRef.current);\n }\n }\n if (onLayout) {\n onLayout(evt);\n }\n },\n [onLayout, props.__destroyWebGLContextAfterRender]\n );\n\n useImperativeHandle(\n ref,\n () => ({\n setPicture,\n getSize,\n redraw,\n makeImageSnapshot,\n }),\n [setPicture, getSize, redraw, makeImageSnapshot]\n );\n\n useEffect(() => {\n const nativeID = props.nativeID ?? `${SkiaViewNativeId.current++}`;\n (global.SkiaViewApi as ISkiaViewApiWeb).registerView(nativeID, {\n setPicture,\n getSize,\n redraw,\n makeImageSnapshot,\n } as SkiaPictureViewHandle);\n if (props.picture) {\n setPicture(props.picture);\n }\n }, [setPicture, getSize, redraw, makeImageSnapshot, props]);\n\n useEffect(() => {\n tick();\n return () => {\n cancelAnimationFrame(requestIdRef.current);\n if (renderer.current) {\n renderer.current.dispose();\n renderer.current = null;\n }\n };\n }, [tick]);\n\n useEffect(() => {\n if (renderer.current && pictureRef.current) {\n renderer.current.draw(pictureRef.current);\n }\n }, [picture, redraw]);\n\n const { debug = false, ...viewProps } = props;\n return (\n <Platform.View {...viewProps} onLayout={onLayoutEvent}>\n <canvas ref={canvasRef} style={{ display: \"flex\", flex: 1 }} />\n </Platform.View>\n );\n});\n"],"mappings":";;;;AAAA;AACA,OAAOA,KAAK,IACVC,MAAM,EACNC,SAAS,EACTC,WAAW,EACXC,mBAAmB,EACnBC,UAAU,QACL,OAAO;AAId,SAASC,YAAY,QAAQ,0BAA0B;AACvD,SAASC,QAAQ,QAAQ,aAAa;AAItC,SAASC,gBAAgB,QAAQ,oBAAoB;AASrD,MAAMC,aAAa,CAAqB;EAGtCC,WAAWA,CAASC,MAAyB,EAAUC,EAAU,EAAE;IAAA,KAA/CD,MAAyB,GAAzBA,MAAyB;IAAA,KAAUC,EAAU,GAAVA,EAAU;IAAAC,eAAA,kBAF1B,IAAI;IAGzC,IAAI,CAACC,QAAQ,CAAC,CAAC;EACjB;EAEAC,iBAAiBA,CAACC,OAAkB,EAAEC,IAAa,EAAkB;IACnE,IAAI,CAAC,IAAI,CAACC,OAAO,EAAE;MACjB,OAAO,IAAI;IACb;IACA,MAAMP,MAAM,GAAG,IAAI,CAACO,OAAO,CAACC,SAAS,CAAC,CAAC;IACvCR,MAAM,CAAES,KAAK,CAACC,SAAS,CAACC,WAAW,CAAC;IACpC,IAAI,CAACC,IAAI,CAACP,OAAO,CAAC;IAClB,IAAI,CAACE,OAAO,CAACM,GAAG,CAACC,KAAK,CAAC,CAAC;IACxB,OAAO,IAAI,CAACP,OAAO,CAACH,iBAAiB,CAACE,IAAI,CAAC;EAC7C;EAEAH,QAAQA,CAAA,EAAG;IACT,MAAM;MAAEH,MAAM;MAAEC;IAAG,CAAC,GAAG,IAAI;IAC3BD,MAA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KAAKH,SAAS;IAAEpB,QAAQ,EAAEU;EAAc,iBACpD9E,KAAA,CAAAyF,aAAA;IAAQjE,GAAG,EAAEuC,SAAU;IAAC6B,KAAK,EAAE;MAAEC,OAAO,EAAE,MAAM;MAAEC,IAAI,EAAE;IAAE;EAAE,CAAE,CACjD,CAAC;AAEpB,CAAC,CAAC","ignoreList":[]}
|
@@ -26,6 +26,7 @@ export interface SkiaBaseViewProps extends ViewProps {
|
|
26
26
|
*/
|
27
27
|
onSize?: SharedValue<SkSize>;
|
28
28
|
opaque?: boolean;
|
29
|
+
__destroyWebGLContextAfterRender?: boolean;
|
29
30
|
}
|
30
31
|
export interface SkiaPictureViewNativeProps extends SkiaBaseViewProps {
|
31
32
|
picture?: SkPicture;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { ViewProps } from \"react-native\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport type { Node } from \"../dom/types\";\nimport type { SkImage, SkPicture, SkRect, SkSize } from \"../skia/types\";\n\nexport type NativeSkiaViewProps = ViewProps & {\n debug?: boolean;\n opaque?: boolean;\n};\n\nexport interface ISkiaViewApi {\n web?: boolean;\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 size: (nativeId: number) => SkSize;\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?: SharedValue<SkSize>;\n\n opaque?: boolean;\n}\n\nexport interface SkiaPictureViewNativeProps extends SkiaBaseViewProps {\n picture?: SkPicture;\n}\n\nexport interface SkiaDomViewNativeProps extends SkiaBaseViewProps {\n root?: Node<unknown>;\n}\n"],"mappings":"","ignoreList":[]}
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { ViewProps } from \"react-native\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport type { Node } from \"../dom/types\";\nimport type { SkImage, SkPicture, SkRect, SkSize } from \"../skia/types\";\n\nexport type NativeSkiaViewProps = ViewProps & {\n debug?: boolean;\n opaque?: boolean;\n};\n\nexport interface ISkiaViewApi {\n web?: boolean;\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 size: (nativeId: number) => SkSize;\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?: SharedValue<SkSize>;\n\n opaque?: boolean;\n\n // On web, only 16 WebGL contextes are allowed. If the drawing is non-animated, set\n // __destroyWebGLContextAfterRender to true to release the context after each draw.\n __destroyWebGLContextAfterRender?: boolean;\n}\n\nexport interface SkiaPictureViewNativeProps extends SkiaBaseViewProps {\n picture?: SkPicture;\n}\n\nexport interface SkiaDomViewNativeProps extends SkiaBaseViewProps {\n root?: Node<unknown>;\n}\n"],"mappings":"","ignoreList":[]}
|
@@ -6,5 +6,15 @@ declare function SkiaPictureViewNativeComponent({ nativeID, debug, opaque, onLay
|
|
6
6
|
debug: any;
|
7
7
|
opaque: any;
|
8
8
|
onLayout: any;
|
9
|
-
}): _react.
|
9
|
+
}): _react.CElement<{
|
10
|
+
nativeID: any;
|
11
|
+
debug: any;
|
12
|
+
opaque: any;
|
13
|
+
onLayout: any;
|
14
|
+
}, _react.Component<{
|
15
|
+
nativeID: any;
|
16
|
+
debug: any;
|
17
|
+
opaque: any;
|
18
|
+
onLayout: any;
|
19
|
+
}, any, any>>;
|
10
20
|
import _react = require("react");
|
@@ -1,7 +1,2 @@
|
|
1
1
|
export const __esModule: boolean;
|
2
|
-
export
|
3
|
-
setPicture(picture: any): void;
|
4
|
-
picture: any;
|
5
|
-
renderInCanvas(canvas: any): void;
|
6
|
-
}
|
7
|
-
import _SkiaBaseWebView = require("./SkiaBaseWebView");
|
2
|
+
export const SkiaPictureView: any;
|
@@ -5,5 +5,4 @@ declare function SkiaPictureViewNativeComponent({ nativeID, debug, opaque, onLay
|
|
5
5
|
debug: any;
|
6
6
|
opaque: any;
|
7
7
|
onLayout: any;
|
8
|
-
}): import("react").
|
9
|
-
import { SkiaPictureView } from "../views/SkiaPictureView.web";
|
8
|
+
}): import("react").DetailedReactHTMLElement<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
|
@@ -1,6 +1,2 @@
|
|
1
|
-
export
|
2
|
-
|
3
|
-
picture: any;
|
4
|
-
renderInCanvas(canvas: any): void;
|
5
|
-
}
|
6
|
-
import { SkiaBaseWebView } from "./SkiaBaseWebView";
|
1
|
+
export const SkiaPictureView: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
|
2
|
+
import React from "react";
|
@@ -23,5 +23,6 @@ export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
|
|
23
23
|
onSize?: SharedValue<SkSize>;
|
24
24
|
colorSpace?: "p3" | "srgb";
|
25
25
|
ref?: React.Ref<CanvasRef>;
|
26
|
+
__destroyWebGLContextAfterRender?: boolean;
|
26
27
|
}
|
27
28
|
export declare const Canvas: ({ debug, opaque, children, onSize, colorSpace, ref, onLayout, ...viewProps }: CanvasProps) => React.JSX.Element;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -12,7 +12,7 @@ export declare class ParagraphAsset<Ctx extends EvalContext> extends SkiaObject<
|
|
12
12
|
getLongestLine(): number;
|
13
13
|
getGlyphPositionAtCoordinate(x: number, y: number): number;
|
14
14
|
getRectsForRange(start: number, end: number): import("../../../../skia/types").SkRect[];
|
15
|
-
getLineMetrics(): import("../../../../skia/types").
|
15
|
+
getLineMetrics(): import("../../../../skia/types").LineMetrics[];
|
16
16
|
getRectsForPlaceholders(): import("../../../../skia/types").SkRectWithDirection[];
|
17
17
|
__typename__: "Paragraph";
|
18
18
|
dispose(): void;
|
@@ -2,6 +2,36 @@ import type { SkCanvas } from "../Canvas";
|
|
2
2
|
import type { SkJSIInstance } from "../JsiInstance";
|
3
3
|
import type { SkRect } from "../Rect";
|
4
4
|
import type { TextDirection } from "./ParagraphStyle";
|
5
|
+
export interface LineMetrics {
|
6
|
+
/** The index in the text buffer the line begins. */
|
7
|
+
startIndex: number;
|
8
|
+
/** The index in the text buffer the line ends. */
|
9
|
+
endIndex: number;
|
10
|
+
endExcludingWhitespaces: number;
|
11
|
+
endIncludingNewline: number;
|
12
|
+
/** True if the line ends in a hard break (e.g. newline) */
|
13
|
+
isHardBreak: boolean;
|
14
|
+
/**
|
15
|
+
* The final computed ascent for the line. This can be impacted by
|
16
|
+
* the strut, height, scaling, as well as outlying runs that are very tall.
|
17
|
+
*/
|
18
|
+
ascent: number;
|
19
|
+
/**
|
20
|
+
* The final computed descent for the line. This can be impacted by
|
21
|
+
* the strut, height, scaling, as well as outlying runs that are very tall.
|
22
|
+
*/
|
23
|
+
descent: number;
|
24
|
+
/** round(ascent + descent) */
|
25
|
+
height: number;
|
26
|
+
/** width of the line */
|
27
|
+
width: number;
|
28
|
+
/** The left edge of the line. The right edge can be obtained with `left + width` */
|
29
|
+
left: number;
|
30
|
+
/** The y position of the baseline for this line from the top of the paragraph. */
|
31
|
+
baseline: number;
|
32
|
+
/** Zero indexed line number. */
|
33
|
+
lineNumber: number;
|
34
|
+
}
|
5
35
|
export interface SkRectWithDirection {
|
6
36
|
rect: SkRect;
|
7
37
|
direction: TextDirection;
|
@@ -70,7 +100,7 @@ export interface SkParagraph extends SkJSIInstance<"Paragraph"> {
|
|
70
100
|
* Returns the bounding boxes for all lines in the paragraph. This method
|
71
101
|
* requires the layout method to have been called first.
|
72
102
|
*/
|
73
|
-
getLineMetrics():
|
103
|
+
getLineMetrics(): LineMetrics[];
|
74
104
|
/**
|
75
105
|
* Returns a list of rects with direction info for the placeholders added
|
76
106
|
* to the paragraph.
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { CanvasKit, Paragraph } from "canvaskit-wasm";
|
2
|
-
import type { SkRect, SkRectWithDirection, SkParagraph } from "../types";
|
2
|
+
import type { SkRect, SkRectWithDirection, SkParagraph, LineMetrics } from "../types";
|
3
3
|
import { HostObject } from "./Host";
|
4
4
|
import type { JsiSkCanvas } from "./JsiSkCanvas";
|
5
5
|
export declare class JsiSkParagraph extends HostObject<Paragraph, "Paragraph"> implements SkParagraph {
|
@@ -14,6 +14,6 @@ export declare class JsiSkParagraph extends HostObject<Paragraph, "Paragraph"> i
|
|
14
14
|
getGlyphPositionAtCoordinate(x: number, y: number): number;
|
15
15
|
getRectsForPlaceholders(): SkRectWithDirection[];
|
16
16
|
getRectsForRange(start: number, end: number): SkRect[];
|
17
|
-
getLineMetrics():
|
17
|
+
getLineMetrics(): LineMetrics[];
|
18
18
|
dispose(): void;
|
19
19
|
}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import type { SkPicture } from "../skia/types";
|
2
2
|
import type { ISkiaViewApi } from "../views/types";
|
3
|
-
import type {
|
3
|
+
import type { SkiaPictureViewHandle } from "../views/SkiaPictureView.web";
|
4
4
|
export type ISkiaViewApiWeb = ISkiaViewApi & {
|
5
|
-
views: Record<string,
|
5
|
+
views: Record<string, SkiaPictureViewHandle>;
|
6
6
|
deferedPictures: Record<string, SkPicture>;
|
7
|
-
registerView(nativeId: string, view:
|
7
|
+
registerView(nativeId: string, view: SkiaPictureViewHandle): void;
|
8
8
|
};
|
9
9
|
declare const _default: {};
|
10
10
|
export default _default;
|
@@ -1,9 +1,8 @@
|
|
1
1
|
import type { ViewProps } from "react-native";
|
2
|
-
import { SkiaPictureView } from "../views/SkiaPictureView.web";
|
3
2
|
export interface NativeProps extends ViewProps {
|
4
3
|
debug?: boolean;
|
5
4
|
opaque?: boolean;
|
6
5
|
nativeID: string;
|
7
6
|
}
|
8
|
-
declare const SkiaPictureViewNativeComponent: ({ nativeID, debug, opaque, onLayout, ...viewProps }: NativeProps) => import("react").
|
7
|
+
declare const SkiaPictureViewNativeComponent: ({ nativeID, debug, opaque, onLayout, ...viewProps }: NativeProps) => import("react").FunctionComponentElement<import("..").SkiaPictureViewNativeProps & import("react").RefAttributes<import("../views/SkiaPictureView.web").SkiaPictureViewHandle>>;
|
9
8
|
export default SkiaPictureViewNativeComponent;
|
@@ -1,9 +1,13 @@
|
|
1
|
-
import
|
1
|
+
import React from "react";
|
2
|
+
import type { SkRect, SkPicture, SkImage } from "../skia/types";
|
2
3
|
import type { SkiaPictureViewNativeProps } from "./types";
|
3
|
-
|
4
|
-
export declare class SkiaPictureView extends SkiaBaseWebView<SkiaPictureViewNativeProps> {
|
5
|
-
private picture;
|
6
|
-
constructor(props: SkiaPictureViewNativeProps);
|
4
|
+
export interface SkiaPictureViewHandle {
|
7
5
|
setPicture(picture: SkPicture): void;
|
8
|
-
|
6
|
+
getSize(): {
|
7
|
+
width: number;
|
8
|
+
height: number;
|
9
|
+
};
|
10
|
+
redraw(): void;
|
11
|
+
makeImageSnapshot(rect?: SkRect): SkImage | null;
|
9
12
|
}
|
13
|
+
export declare const SkiaPictureView: React.ForwardRefExoticComponent<SkiaPictureViewNativeProps & React.RefAttributes<SkiaPictureViewHandle>>;
|
@@ -26,6 +26,7 @@ export interface SkiaBaseViewProps extends ViewProps {
|
|
26
26
|
*/
|
27
27
|
onSize?: SharedValue<SkSize>;
|
28
28
|
opaque?: boolean;
|
29
|
+
__destroyWebGLContextAfterRender?: boolean;
|
29
30
|
}
|
30
31
|
export interface SkiaPictureViewNativeProps extends SkiaBaseViewProps {
|
31
32
|
picture?: SkPicture;
|
package/package.json
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
"setup-skia-web": "scripts/setup-canvaskit.js"
|
9
9
|
},
|
10
10
|
"title": "React Native Skia",
|
11
|
-
"version": "2.2.
|
11
|
+
"version": "2.2.10",
|
12
12
|
"description": "High-performance React Native Graphics using Skia",
|
13
13
|
"main": "lib/module/index.js",
|
14
14
|
"react-native": "src/index.ts",
|
package/src/renderer/Canvas.tsx
CHANGED