@shopify/react-native-skia 0.1.151 → 0.1.152
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +4 -5
- package/android/cpp/jni/JniLoad.cpp +7 -5
- package/android/cpp/jni/JniSkiaManager.cpp +2 -15
- package/android/cpp/jni/include/JniSkiaBaseView.h +68 -0
- package/android/cpp/jni/include/JniSkiaDrawView.h +64 -47
- package/android/cpp/jni/include/JniSkiaManager.h +8 -10
- package/android/cpp/jni/include/JniSkiaPictureView.h +96 -0
- package/android/cpp/rnskia-android/{RNSkPlatformContextImpl.h → RNSkAndroidPlatformContext.h} +4 -4
- package/android/cpp/rnskia-android/RNSkAndroidView.h +100 -0
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +91 -0
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +39 -0
- package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +15 -6
- package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +5 -4
- package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +5 -11
- package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaPackage.java +1 -2
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +143 -0
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawView.java +17 -145
- package/android/src/main/java/com/shopify/reactnative/skia/{RNSkiaViewManager.java → SkiaDrawViewManager.java} +4 -15
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaManager.java +1 -10
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureView.java +45 -0
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureViewManager.java +64 -0
- package/cpp/jsi/JsiValueWrapper.h +11 -0
- package/cpp/rnskia/RNSkInfoParameter.h +4 -14
- package/cpp/rnskia/RNSkJsView.cpp +211 -0
- package/cpp/rnskia/RNSkJsView.h +115 -0
- package/cpp/rnskia/RNSkJsiViewApi.h +6 -6
- package/cpp/rnskia/RNSkManager.cpp +7 -7
- package/cpp/rnskia/RNSkManager.h +7 -7
- package/cpp/rnskia/RNSkPictureView.h +124 -0
- package/cpp/rnskia/RNSkView.h +287 -0
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.h +38 -0
- package/ios/RNSkia-iOS/{RNSkDrawViewImpl.mm → RNSkMetalCanvasProvider.mm} +40 -23
- package/ios/RNSkia-iOS/{PlatformContext.h → RNSkiOSPlatformContext.h} +4 -4
- package/ios/RNSkia-iOS/{PlatformContext.mm → RNSkiOSPlatformContext.mm} +5 -5
- package/ios/RNSkia-iOS/RNSkiOSView.h +34 -0
- package/ios/RNSkia-iOS/SkiaDrawViewManager.mm +19 -11
- package/ios/RNSkia-iOS/SkiaManager.mm +3 -3
- package/ios/RNSkia-iOS/SkiaPictureViewManager.h +8 -0
- package/ios/RNSkia-iOS/SkiaPictureViewManager.mm +51 -0
- package/ios/RNSkia-iOS/SkiaUIView.h +26 -0
- package/ios/RNSkia-iOS/{SkiaDrawView.mm → SkiaUIView.mm} +29 -23
- package/lib/commonjs/views/SkiaBaseWebView.js +213 -0
- package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -0
- package/lib/commonjs/views/SkiaPictureView.js +112 -0
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -0
- package/lib/commonjs/views/SkiaPictureView.web.js +31 -0
- package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -0
- package/lib/commonjs/views/SkiaView.js +1 -1
- package/lib/commonjs/views/SkiaView.js.map +1 -1
- package/lib/commonjs/views/SkiaView.web.js +14 -201
- package/lib/commonjs/views/SkiaView.web.js.map +1 -1
- package/lib/commonjs/views/index.js +13 -0
- package/lib/commonjs/views/index.js.map +1 -1
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/views/SkiaBaseWebView.js +198 -0
- package/lib/module/views/SkiaBaseWebView.js.map +1 -0
- package/lib/module/views/SkiaPictureView.js +94 -0
- package/lib/module/views/SkiaPictureView.js.map +1 -0
- package/lib/module/views/SkiaPictureView.web.js +19 -0
- package/lib/module/views/SkiaPictureView.web.js.map +1 -0
- package/lib/module/views/SkiaView.js +1 -1
- package/lib/module/views/SkiaView.js.map +1 -1
- package/lib/module/views/SkiaView.web.js +15 -199
- package/lib/module/views/SkiaView.web.js.map +1 -1
- package/lib/module/views/index.js +1 -0
- package/lib/module/views/index.js.map +1 -1
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/src/views/SkiaBaseWebView.d.ts +58 -0
- package/lib/typescript/src/views/SkiaPictureView.d.ts +27 -0
- package/lib/typescript/src/views/SkiaPictureView.web.d.ts +7 -0
- package/lib/typescript/src/views/SkiaView.d.ts +4 -4
- package/lib/typescript/src/views/SkiaView.web.d.ts +6 -53
- package/lib/typescript/src/views/index.d.ts +1 -0
- package/lib/typescript/src/views/types.d.ts +7 -2
- package/package.json +1 -1
- package/src/views/SkiaBaseWebView.tsx +177 -0
- package/src/views/SkiaPictureView.tsx +93 -0
- package/src/views/SkiaPictureView.web.tsx +23 -0
- package/src/views/SkiaView.tsx +6 -7
- package/src/views/SkiaView.web.tsx +18 -167
- package/src/views/index.ts +1 -0
- package/src/views/types.ts +9 -2
- package/android/cpp/jni/JniSkiaDrawView.cpp +0 -113
- package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +0 -73
- package/android/cpp/rnskia-android/RNSkDrawViewImpl.h +0 -48
- package/cpp/rnskia/RNSkDrawView.cpp +0 -315
- package/cpp/rnskia/RNSkDrawView.h +0 -226
- package/ios/RNSkia-iOS/RNSkDrawViewImpl.h +0 -52
- package/ios/RNSkia-iOS/SkiaDrawView.h +0 -23
@@ -6,7 +6,7 @@ import React from "react";
|
|
6
6
|
import { requireNativeComponent } from "react-native";
|
7
7
|
import { SkiaViewApi } from "./api";
|
8
8
|
let SkiaViewNativeId = 1000;
|
9
|
-
const NativeSkiaView = requireNativeComponent("
|
9
|
+
const NativeSkiaView = requireNativeComponent("SkiaDrawView");
|
10
10
|
export class SkiaView extends React.Component {
|
11
11
|
constructor(props) {
|
12
12
|
super(props);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","requireNativeComponent","SkiaViewApi","SkiaViewNativeId","NativeSkiaView","SkiaView","Component","constructor","props","_nativeId","onDraw","assertSkiaViewApi","setJsiProperty","nativeId","componentDidUpdate","prevProps","makeImageSnapshot","rect","redraw","requestRedraw","registerValues","values","registerValuesInView","render","mode","debug","viewProps","callJsiMethod","Error"],"sources":["SkiaView.tsx"],"sourcesContent":["import React from \"react\";\nimport { requireNativeComponent } from \"react-native\";\n\nimport type { SkRect } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\n\nimport { SkiaViewApi } from \"./api\";\nimport type { NativeSkiaViewProps,
|
1
|
+
{"version":3,"names":["React","requireNativeComponent","SkiaViewApi","SkiaViewNativeId","NativeSkiaView","SkiaView","Component","constructor","props","_nativeId","onDraw","assertSkiaViewApi","setJsiProperty","nativeId","componentDidUpdate","prevProps","makeImageSnapshot","rect","redraw","requestRedraw","registerValues","values","registerValuesInView","render","mode","debug","viewProps","callJsiMethod","Error"],"sources":["SkiaView.tsx"],"sourcesContent":["import React from \"react\";\nimport { requireNativeComponent } from \"react-native\";\n\nimport type { SkRect } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\n\nimport { SkiaViewApi } from \"./api\";\nimport type { NativeSkiaViewProps, SkiaDrawViewProps } from \"./types\";\n\nlet SkiaViewNativeId = 1000;\n\nconst NativeSkiaView =\n requireNativeComponent<NativeSkiaViewProps>(\"SkiaDrawView\");\n\nexport class SkiaView extends React.Component<SkiaDrawViewProps> {\n constructor(props: SkiaDrawViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId++;\n const { onDraw } = props;\n if (onDraw) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"drawCallback\", onDraw);\n }\n }\n\n private _nativeId: number;\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaDrawViewProps) {\n const { onDraw } = this.props;\n if (onDraw !== prevProps.onDraw) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"drawCallback\", onDraw);\n }\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n assertSkiaViewApi();\n return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n public redraw() {\n assertSkiaViewApi();\n SkiaViewApi.requestRedraw(this._nativeId);\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(values: SkiaValue<unknown>[]): () => void {\n assertSkiaViewApi();\n return SkiaViewApi.registerValuesInView(this._nativeId, values);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <NativeSkiaView\n collapsable={false}\n nativeID={`${this._nativeId}`}\n mode={mode}\n debug={debug}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertSkiaViewApi = () => {\n if (\n SkiaViewApi === null ||\n SkiaViewApi.setJsiProperty === null ||\n SkiaViewApi.callJsiMethod === null ||\n SkiaViewApi.registerValuesInView === null ||\n SkiaViewApi.requestRedraw === null ||\n SkiaViewApi.makeImageSnapshot === null\n ) {\n throw Error(\"Skia View Api was not found.\");\n }\n};\n"],"mappings":";;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,sBAAT,QAAuC,cAAvC;AAKA,SAASC,WAAT,QAA4B,OAA5B;AAGA,IAAIC,gBAAgB,GAAG,IAAvB;AAEA,MAAMC,cAAc,GAClBH,sBAAsB,CAAsB,cAAtB,CADxB;AAGA,OAAO,MAAMI,QAAN,SAAuBL,KAAK,CAACM,SAA7B,CAA0D;EAC/DC,WAAW,CAACC,KAAD,EAA2B;IACpC,MAAMA,KAAN;;IADoC;;IAEpC,KAAKC,SAAL,GAAiBN,gBAAgB,EAAjC;IACA,MAAM;MAAEO;IAAF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W,CAACU,cAAZ,KAA+B,IAD/B,IAEAV,WAAW,CAACyB,aAAZ,KAA8B,IAF9B,IAGAzB,WAAW,CAACoB,oBAAZ,KAAqC,IAHrC,IAIApB,WAAW,CAACiB,aAAZ,KAA8B,IAJ9B,IAKAjB,WAAW,CAACc,iBAAZ,KAAkC,IANpC,EAOE;IACA,MAAMY,KAAK,CAAC,8BAAD,CAAX;EACD;AACF,CAXD"}
|
@@ -1,208 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
4
|
-
|
5
|
-
/* global HTMLCanvasElement */
|
6
|
-
import React from "react";
|
7
|
-
import { PixelRatio, View } from "react-native";
|
8
|
-
import { JsiSkSurface } from "../skia/web/JsiSkSurface";
|
9
|
-
import { TouchType } from "./types";
|
1
|
+
import { PixelRatio } from "react-native";
|
2
|
+
import { SkiaBaseWebView } from "./SkiaBaseWebView";
|
10
3
|
const pd = PixelRatio.get();
|
11
|
-
export class SkiaView extends
|
4
|
+
export class SkiaView extends SkiaBaseWebView {
|
12
5
|
constructor(props) {
|
13
6
|
super(props);
|
14
|
-
|
15
|
-
_defineProperty(this, "_surface", null);
|
16
|
-
|
17
|
-
_defineProperty(this, "_unsubscriptions", []);
|
18
|
-
|
19
|
-
_defineProperty(this, "_touches", []);
|
20
|
-
|
21
|
-
_defineProperty(this, "_canvas", null);
|
22
|
-
|
23
|
-
_defineProperty(this, "_canvasRef", /*#__PURE__*/React.createRef());
|
24
|
-
|
25
|
-
_defineProperty(this, "_mode", void 0);
|
26
|
-
|
27
|
-
_defineProperty(this, "_redrawRequests", 0);
|
28
|
-
|
29
|
-
_defineProperty(this, "width", 0);
|
30
|
-
|
31
|
-
_defineProperty(this, "height", 0);
|
32
|
-
|
33
|
-
_defineProperty(this, "requestId", 0);
|
34
|
-
|
35
|
-
this._mode = props.mode ?? "default";
|
36
|
-
}
|
37
|
-
|
38
|
-
unsubscribeAll() {
|
39
|
-
this._unsubscriptions.forEach(u => u());
|
40
|
-
|
41
|
-
this._unsubscriptions = [];
|
42
|
-
}
|
43
|
-
|
44
|
-
onLayout(evt) {
|
45
|
-
const {
|
46
|
-
CanvasKit
|
47
|
-
} = global;
|
48
|
-
const {
|
49
|
-
width,
|
50
|
-
height
|
51
|
-
} = evt.nativeEvent.layout;
|
52
|
-
this.width = width;
|
53
|
-
this.height = height; // Reset canvas / surface on layout change
|
54
|
-
|
55
|
-
if (this._canvasRef.current) {
|
56
|
-
const canvas = this._canvasRef.current;
|
57
|
-
canvas.width = canvas.clientWidth * pd;
|
58
|
-
canvas.height = canvas.clientHeight * pd;
|
59
|
-
const surface = CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current);
|
60
|
-
|
61
|
-
if (!surface) {
|
62
|
-
throw new Error("Could not create surface");
|
63
|
-
}
|
64
|
-
|
65
|
-
this._surface = new JsiSkSurface(CanvasKit, surface);
|
66
|
-
this._canvas = this._surface.getCanvas();
|
67
|
-
this.redraw();
|
68
|
-
}
|
69
|
-
}
|
70
|
-
|
71
|
-
componentDidMount() {
|
72
|
-
// Start render loop
|
73
|
-
this.tick();
|
74
|
-
}
|
75
|
-
|
76
|
-
componentDidUpdate() {
|
77
|
-
this.redraw();
|
78
|
-
}
|
79
|
-
|
80
|
-
componentWillUnmount() {
|
81
|
-
this.unsubscribeAll();
|
82
|
-
cancelAnimationFrame(this.requestId);
|
83
7
|
}
|
84
|
-
/**
|
85
|
-
* Creates a snapshot from the canvas in the surface
|
86
|
-
* @param rect Rect to use as bounds. Optional.
|
87
|
-
* @returns An Image object.
|
88
|
-
*/
|
89
|
-
|
90
|
-
|
91
|
-
makeImageSnapshot(rect) {
|
92
|
-
var _this$_surface;
|
93
|
-
|
94
|
-
return (_this$_surface = this._surface) === null || _this$_surface === void 0 ? void 0 : _this$_surface.makeImageSnapshot(rect);
|
95
|
-
}
|
96
|
-
/**
|
97
|
-
* Sends a redraw request to the native SkiaView.
|
98
|
-
*/
|
99
|
-
|
100
|
-
|
101
|
-
tick() {
|
102
|
-
if (this._mode === "continuous" || this._redrawRequests > 0) {
|
103
|
-
this._redrawRequests = 0;
|
104
8
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
this.
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
if (this.props.onDraw) {
|
118
|
-
const canvas = this._canvas;
|
119
|
-
canvas.save();
|
120
|
-
canvas.scale(pd, pd);
|
121
|
-
this.props.onDraw(canvas, info);
|
122
|
-
canvas.restore();
|
123
|
-
}
|
124
|
-
|
125
|
-
(_this$_surface2 = this._surface) === null || _this$_surface2 === void 0 ? void 0 : _this$_surface2.ref.flush();
|
126
|
-
}
|
9
|
+
renderInCanvas(canvas, touches) {
|
10
|
+
if (this.props.onDraw) {
|
11
|
+
const info = {
|
12
|
+
height: this.height,
|
13
|
+
width: this.width,
|
14
|
+
timestamp: Date.now(),
|
15
|
+
touches: touches.map(t => [t])
|
16
|
+
};
|
17
|
+
canvas.save();
|
18
|
+
canvas.scale(pd, pd);
|
19
|
+
this.props.onDraw(canvas, info);
|
20
|
+
canvas.restore();
|
127
21
|
}
|
128
|
-
|
129
|
-
this.requestId = requestAnimationFrame(this.tick.bind(this));
|
130
|
-
}
|
131
|
-
|
132
|
-
redraw() {
|
133
|
-
this._redrawRequests++;
|
134
|
-
}
|
135
|
-
/**
|
136
|
-
* Updates the drawing mode for the skia view. This is the same
|
137
|
-
* as declaratively setting the mode property on the SkiaView.
|
138
|
-
* There are two drawing modes, "continuous" and "default",
|
139
|
-
* where the continuous mode will continuously redraw the view and
|
140
|
-
* the default mode will only redraw when any of the regular react
|
141
|
-
* properties are changed like size and margins.
|
142
|
-
* @param mode Drawing mode to use.
|
143
|
-
*/
|
144
|
-
|
145
|
-
|
146
|
-
setDrawMode(mode) {
|
147
|
-
this._mode = mode;
|
148
|
-
this.tick();
|
149
|
-
}
|
150
|
-
/**
|
151
|
-
* Registers one or move values as a dependant value of the Skia View. The view will
|
152
|
-
* The view will redraw itself when any of the values change.
|
153
|
-
* @param values Values to register
|
154
|
-
*/
|
155
|
-
|
156
|
-
|
157
|
-
registerValues(_values) {
|
158
|
-
// Unsubscribe from dependency values
|
159
|
-
this.unsubscribeAll(); // Register redraw dependencies on values
|
160
|
-
|
161
|
-
_values.forEach(v => {
|
162
|
-
this._unsubscriptions.push(v.addListener(() => {
|
163
|
-
this.redraw();
|
164
|
-
}));
|
165
|
-
});
|
166
|
-
}
|
167
|
-
|
168
|
-
handleTouchEvent(evt, touchType) {
|
169
|
-
this._touches.push({
|
170
|
-
id: evt.pointerId,
|
171
|
-
x: evt.clientX - evt.currentTarget.getClientRects()[0].left,
|
172
|
-
y: evt.clientY - evt.currentTarget.getClientRects()[0].top,
|
173
|
-
force: evt.pressure,
|
174
|
-
type: touchType,
|
175
|
-
timestamp: Date.now()
|
176
|
-
});
|
177
|
-
|
178
|
-
this.redraw();
|
179
|
-
}
|
180
|
-
|
181
|
-
createTouchHandler(touchType) {
|
182
|
-
return evt => this.handleTouchEvent(evt, touchType);
|
183
|
-
}
|
184
|
-
|
185
|
-
render() {
|
186
|
-
const {
|
187
|
-
mode,
|
188
|
-
debug = false,
|
189
|
-
...viewProps
|
190
|
-
} = this.props;
|
191
|
-
return /*#__PURE__*/React.createElement(View, _extends({}, viewProps, {
|
192
|
-
onLayout: this.onLayout.bind(this)
|
193
|
-
}), /*#__PURE__*/React.createElement("canvas", {
|
194
|
-
ref: this._canvasRef,
|
195
|
-
style: {
|
196
|
-
display: "flex",
|
197
|
-
flex: 1
|
198
|
-
},
|
199
|
-
onPointerDown: this.createTouchHandler(TouchType.Start),
|
200
|
-
onPointerMove: this.createTouchHandler(TouchType.Active),
|
201
|
-
onPointerUp: this.createTouchHandler(TouchType.End),
|
202
|
-
onPointerCancel: this.createTouchHandler(TouchType.Cancelled),
|
203
|
-
onPointerLeave: this.createTouchHandler(TouchType.End),
|
204
|
-
onPointerOut: this.createTouchHandler(TouchType.End)
|
205
|
-
}));
|
206
22
|
}
|
207
23
|
|
208
24
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","PixelRatio","View","JsiSkSurface","TouchType","pd","get","SkiaView","Component","constructor","props","createRef","_mode","mode","unsubscribeAll","_unsubscriptions","forEach","u","onLayout","evt","CanvasKit","global","width","height","nativeEvent","layout","_canvasRef","current","canvas","clientWidth","clientHeight","surface","MakeWebGLCanvasSurface","Error","_surface","_canvas","getCanvas","redraw","componentDidMount","tick","componentDidUpdate","componentWillUnmount","cancelAnimationFrame","requestId","makeImageSnapshot","rect","_redrawRequests","onDraw","touches","_touches","info","timestamp","Date","now","map","t","save","scale","restore","ref","flush","requestAnimationFrame","bind","setDrawMode","registerValues","_values","v","push","addListener","handleTouchEvent","touchType","id","pointerId","x","clientX","currentTarget","getClientRects","left","y","clientY","top","force","pressure","type","createTouchHandler","render","debug","viewProps","display","flex","Start","Active","End","Cancelled"],"sources":["SkiaView.web.tsx"],"sourcesContent":["/* global HTMLCanvasElement */\nimport React from \"react\";\nimport type { PointerEvent } from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\nimport { PixelRatio, View } from \"react-native\";\n\nimport type { SkRect, SkCanvas } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\n\nimport type { DrawingInfo, DrawMode, SkiaViewProps, TouchInfo } from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst pd = PixelRatio.get();\n\nexport class SkiaView extends React.Component<SkiaViewProps> {\n constructor(props: SkiaViewProps) {\n super(props);\n this._mode = props.mode ?? \"default\";\n }\n\n private _surface: JsiSkSurface | null = null;\n private _unsubscriptions: Array<() => void> = [];\n private _touches: Array<TouchInfo> = [];\n private _canvas: SkCanvas | null = null;\n private _canvasRef = React.createRef<HTMLCanvasElement>();\n private _mode: DrawMode;\n private _redrawRequests = 0;\n private width = 0;\n private height = 0;\n private requestId = 0;\n\n private unsubscribeAll() {\n this._unsubscriptions.forEach((u) => u());\n this._unsubscriptions = [];\n }\n\n private onLayout(evt: LayoutChangeEvent) {\n const { CanvasKit } = global;\n const { width, height } = evt.nativeEvent.layout;\n this.width = width;\n this.height = height;\n // Reset canvas / surface on layout change\n if (this._canvasRef.current) {\n const canvas = this._canvasRef.current;\n canvas.width = canvas.clientWidth * pd;\n canvas.height = canvas.clientHeight * pd;\n const surface = CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current);\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 }\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 }\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 return this._surface?.makeImageSnapshot(rect);\n }\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 && this.props.onDraw) {\n const touches = [...this._touches];\n this._touches = [];\n const info: DrawingInfo = {\n height: this.height,\n width: this.width,\n timestamp: Date.now(),\n touches: touches.map((t) => [t]),\n };\n if (this.props.onDraw) {\n const canvas = this._canvas!;\n canvas.save();\n canvas.scale(pd, pd);\n this.props.onDraw(canvas, info);\n canvas.restore();\n }\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 /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(_values: SkiaValue<unknown>[]) {\n // Unsubscribe from dependency values\n this.unsubscribeAll();\n // Register redraw dependencies on values\n _values.forEach((v) => {\n this._unsubscriptions.push(\n v.addListener(() => {\n this.redraw();\n })\n );\n });\n }\n\n private handleTouchEvent(evt: PointerEvent, touchType: TouchType) {\n this._touches.push({\n id: evt.pointerId,\n x: evt.clientX - evt.currentTarget.getClientRects()[0].left,\n y: evt.clientY - evt.currentTarget.getClientRects()[0].top,\n force: evt.pressure,\n type: touchType,\n timestamp: Date.now(),\n });\n this.redraw();\n }\n\n createTouchHandler(touchType: TouchType) {\n return (evt: PointerEvent) => this.handleTouchEvent(evt, touchType);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <View {...viewProps} onLayout={this.onLayout.bind(this)}>\n <canvas\n ref={this._canvasRef}\n style={{ display: \"flex\", flex: 1 }}\n onPointerDown={this.createTouchHandler(TouchType.Start)}\n onPointerMove={this.createTouchHandler(TouchType.Active)}\n onPointerUp={this.createTouchHandler(TouchType.End)}\n onPointerCancel={this.createTouchHandler(TouchType.Cancelled)}\n onPointerLeave={this.createTouchHandler(TouchType.End)}\n onPointerOut={this.createTouchHandler(TouchType.End)}\n />\n </View>\n );\n }\n}\n"],"mappings":";;;;AAAA;AACA,OAAOA,KAAP,MAAkB,OAAlB;AAGA,SAASC,UAAT,EAAqBC,IAArB,QAAiC,cAAjC;AAIA,SAASC,YAAT,QAA6B,0BAA7B;AAGA,SAASC,SAAT,QAA0B,SAA1B;AAEA,MAAMC,EAAE,GAAGJ,UAAU,CAACK,GAAX,EAAX;AAEA,OAAO,MAAMC,QAAN,SAAuBP,KA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9B;EACD;;EAEDe,MAAM,GAAG;IACP,MAAM;MAAExE,IAAF;MAAQyE,KAAK,GAAG,KAAhB;MAAuB,GAAGC;IAA1B,IAAwC,KAAK7E,KAAnD;IACA,oBACE,oBAAC,IAAD,eAAU6E,SAAV;MAAqB,QAAQ,EAAE,KAAKrE,QAAL,CAAc4C,IAAd,CAAmB,IAAnB;IAA/B,iBACE;MACE,GAAG,EAAE,KAAKpC,UADZ;MAEE,KAAK,EAAE;QAAE8D,OAAO,EAAE,MAAX;QAAmBC,IAAI,EAAE;MAAzB,CAFT;MAGE,aAAa,EAAE,KAAKL,kBAAL,CAAwBhF,SAAS,CAACsF,KAAlC,CAHjB;MAIE,aAAa,EAAE,KAAKN,kBAAL,CAAwBhF,SAAS,CAACuF,MAAlC,CAJjB;MAKE,WAAW,EAAE,KAAKP,kBAAL,CAAwBhF,SAAS,CAACwF,GAAlC,CALf;MAME,eAAe,EAAE,KAAKR,kBAAL,CAAwBhF,SAAS,CAACyF,SAAlC,CANnB;MAOE,cAAc,EAAE,KAAKT,kBAAL,CAAwBhF,SAAS,CAACwF,GAAlC,CAPlB;MAQE,YAAY,EAAE,KAAKR,kBAAL,CAAwBhF,SAAS,CAACwF,GAAlC;IARhB,EADF,CADF;EAcD;;AAjK0D"}
|
1
|
+
{"version":3,"names":["PixelRatio","SkiaBaseWebView","pd","get","SkiaView","constructor","props","renderInCanvas","canvas","touches","onDraw","info","height","width","timestamp","Date","now","map","t","save","scale","restore"],"sources":["SkiaView.web.tsx"],"sourcesContent":["import { PixelRatio } from \"react-native\";\n\nimport type { SkCanvas } from \"../skia/types\";\n\nimport type { DrawingInfo, SkiaDrawViewProps, TouchInfo } from \"./types\";\nimport { SkiaBaseWebView } from \"./SkiaBaseWebView\";\n\nconst pd = PixelRatio.get();\n\nexport class SkiaView extends SkiaBaseWebView<SkiaDrawViewProps> {\n constructor(props: SkiaDrawViewProps) {\n super(props);\n }\n\n protected renderInCanvas(canvas: SkCanvas, touches: TouchInfo[]): void {\n if (this.props.onDraw) {\n const info: DrawingInfo = {\n height: this.height,\n width: this.width,\n timestamp: Date.now(),\n touches: touches.map((t) => [t]),\n };\n canvas.save();\n canvas.scale(pd, pd);\n this.props.onDraw(canvas, info);\n canvas.restore();\n }\n }\n}\n"],"mappings":"AAAA,SAASA,UAAT,QAA2B,cAA3B;AAKA,SAASC,eAAT,QAAgC,mBAAhC;AAEA,MAAMC,EAAE,GAAGF,UAAU,CAACG,GAAX,EAAX;AAEA,OAAO,MAAMC,QAAN,SAAuBH,eAAvB,CAA0D;EAC/DI,WAAW,CAACC,KAAD,EAA2B;IACpC,MAAMA,KAAN;EACD;;EAESC,cAAc,CAACC,MAAD,EAAmBC,OAAnB,EAA+C;IACrE,IAAI,KAAKH,KAAL,CAAWI,MAAf,EAAuB;MACrB,MAAMC,IAAiB,GAAG;QACxBC,MAAM,EAAE,KAAKA,MADW;QAExBC,KAAK,EAAE,KAAKA,KAFY;QAGxBC,SAAS,EAAEC,IAAI,CAACC,GAAL,EAHa;QAIxBP,OAAO,EAAEA,OAAO,CAACQ,GAAR,CAAaC,CAAD,IAAO,CAACA,CAAD,CAAnB;MAJe,CAA1B;MAMAV,MAAM,CAACW,IAAP;MACAX,MAAM,CAACY,KAAP,CAAalB,EAAb,EAAiBA,EAAjB;MACA,KAAKI,KAAL,CAAWI,MAAX,CAAkBF,MAAlB,EAA0BG,IAA1B;MACAH,MAAM,CAACa,OAAP;IACD;EACF;;AAlB8D"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./SkiaView\";\nexport * from \"./types\";\nexport * from \"./useDrawCallback\";\nexport * from \"./useTouchHandler\";\n"],"mappings":"AAAA,cAAc,YAAd;AACA,cAAc,SAAd;AACA,cAAc,mBAAd;AACA,cAAc,mBAAd"}
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./SkiaView\";\nexport * from \"./SkiaPictureView\";\nexport * from \"./types\";\nexport * from \"./useDrawCallback\";\nexport * from \"./useTouchHandler\";\n"],"mappings":"AAAA,cAAc,YAAd;AACA,cAAc,mBAAd;AACA,cAAc,SAAd;AACA,cAAc,mBAAd;AACA,cAAc,mBAAd"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["TouchType"],"sources":["types.ts"],"sourcesContent":["import type { ViewProps } from \"react-native\";\n\nimport type { SkCanvas, SkImage, SkRect } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\n\nexport type DrawMode = \"continuous\" | \"default\";\n\nexport type NativeSkiaViewProps = ViewProps & {\n mode?: DrawMode;\n debug?: boolean;\n};\n\nexport enum TouchType {\n Start,\n Active,\n End,\n Cancelled,\n}\n\nexport interface TouchInfo {\n x: number;\n y: number;\n force: number;\n type: TouchType;\n id: number;\n timestamp: number;\n}\n\nexport interface DrawingInfo {\n width: number;\n height: number;\n timestamp: number;\n touches: Array<Array<TouchInfo>>;\n}\n\nexport type ExtendedTouchInfo = TouchInfo & {\n // points per second\n velocityX: number;\n velocityY: number;\n};\n\nexport type TouchHandlers = {\n onStart?: (touchInfo: TouchInfo) => void;\n onActive?: (touchInfo: ExtendedTouchInfo) => void;\n onEnd?: (touchInfo: ExtendedTouchInfo) => void;\n};\n\nexport type TouchHandler = (touchInfo: Array<Array<TouchInfo>>) => void;\n\nexport type RNSkiaDrawCallback = (canvas: SkCanvas, info: DrawingInfo) => void;\n\n/**\n * Listener interface for value changes\n */\nexport interface ValueListener {\n addListener: (callback: () => void) => number;\n removeListener: (id: number) => void;\n}\n\nexport interface ISkiaViewApi {\n setJsiProperty: <T>(nativeId: number, name: string, value: T) => void;\n callJsiMethod: <T extends Array<unknown>>(\n nativeId: number,\n name: string,\n ...args: T\n ) => void;\n registerValuesInView: (\n nativeId: number,\n values: SkiaValue<unknown>[]\n ) => () => void;\n requestRedraw: (nativeId: number) => void;\n makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;\n}\n\nexport interface
|
1
|
+
{"version":3,"names":["TouchType"],"sources":["types.ts"],"sourcesContent":["import type { ViewProps } from \"react-native\";\n\nimport type { SkCanvas, SkImage, SkPicture, SkRect } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\n\nexport type DrawMode = \"continuous\" | \"default\";\n\nexport type NativeSkiaViewProps = ViewProps & {\n mode?: DrawMode;\n debug?: boolean;\n};\n\nexport enum TouchType {\n Start,\n Active,\n End,\n Cancelled,\n}\n\nexport interface TouchInfo {\n x: number;\n y: number;\n force: number;\n type: TouchType;\n id: number;\n timestamp: number;\n}\n\nexport interface DrawingInfo {\n width: number;\n height: number;\n timestamp: number;\n touches: Array<Array<TouchInfo>>;\n}\n\nexport type ExtendedTouchInfo = TouchInfo & {\n // points per second\n velocityX: number;\n velocityY: number;\n};\n\nexport type TouchHandlers = {\n onStart?: (touchInfo: TouchInfo) => void;\n onActive?: (touchInfo: ExtendedTouchInfo) => void;\n onEnd?: (touchInfo: ExtendedTouchInfo) => void;\n};\n\nexport type TouchHandler = (touchInfo: Array<Array<TouchInfo>>) => void;\n\nexport type RNSkiaDrawCallback = (canvas: SkCanvas, info: DrawingInfo) => void;\n\n/**\n * Listener interface for value changes\n */\nexport interface ValueListener {\n addListener: (callback: () => void) => number;\n removeListener: (id: number) => void;\n}\n\nexport interface ISkiaViewApi {\n setJsiProperty: <T>(nativeId: number, name: string, value: T) => void;\n callJsiMethod: <T extends Array<unknown>>(\n nativeId: number,\n name: string,\n ...args: T\n ) => void;\n registerValuesInView: (\n nativeId: number,\n values: SkiaValue<unknown>[]\n ) => () => void;\n requestRedraw: (nativeId: number) => void;\n makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;\n}\n\nexport interface SkiaBaseViewProps extends ViewProps {\n /**\n * Sets the drawing mode for the skia view. There are two drawing\n * modes, \"continuous\" and \"default\", where the continuous mode will\n * continuously redraw the view, and the default mode will only\n * redraw when any of the regular react properties are changed like\n * sizes and margins.\n */\n mode?: DrawMode;\n /**\n * When set to true the view will display information about the\n * average time it takes to render.\n */\n debug?: boolean;\n}\n\nexport interface SkiaDrawViewProps extends SkiaBaseViewProps {\n /**\n * Draw callback. Will be called whenever the view is invalidated and\n * needs to redraw. This is either caused by a change in a react\n * property, a touch event, or a call to redraw. If the view is in\n * continuous mode the callback will be called 60 frames per second\n * by the native view.\n */\n onDraw?: RNSkiaDrawCallback;\n}\n\nexport interface SkiaPictureViewProps extends SkiaBaseViewProps {\n picture?: SkPicture;\n}\n"],"mappings":"AAYA,WAAYA,SAAZ;;WAAYA,S;EAAAA,S,CAAAA,S;EAAAA,S,CAAAA,S;EAAAA,S,CAAAA,S;EAAAA,S,CAAAA,S;GAAAA,S,KAAAA,S"}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import React from "react";
|
2
|
+
import type { PointerEvent } from "react";
|
3
|
+
import type { SkRect, SkCanvas } from "../skia/types";
|
4
|
+
import type { SkiaValue } from "../values";
|
5
|
+
import type { DrawMode, SkiaBaseViewProps, TouchInfo } from "./types";
|
6
|
+
import { TouchType } from "./types";
|
7
|
+
export declare abstract class SkiaBaseWebView<TProps extends SkiaBaseViewProps> extends React.Component<TProps> {
|
8
|
+
constructor(props: TProps);
|
9
|
+
private _surface;
|
10
|
+
private _unsubscriptions;
|
11
|
+
private _touches;
|
12
|
+
private _canvas;
|
13
|
+
private _canvasRef;
|
14
|
+
private _mode;
|
15
|
+
private _redrawRequests;
|
16
|
+
private requestId;
|
17
|
+
protected width: number;
|
18
|
+
protected height: number;
|
19
|
+
private unsubscribeAll;
|
20
|
+
private onLayout;
|
21
|
+
componentDidMount(): void;
|
22
|
+
componentDidUpdate(): void;
|
23
|
+
componentWillUnmount(): void;
|
24
|
+
/**
|
25
|
+
* Creates a snapshot from the canvas in the surface
|
26
|
+
* @param rect Rect to use as bounds. Optional.
|
27
|
+
* @returns An Image object.
|
28
|
+
*/
|
29
|
+
makeImageSnapshot(rect?: SkRect): import("../skia/types").SkImage | undefined;
|
30
|
+
/**
|
31
|
+
* Override to render
|
32
|
+
*/
|
33
|
+
protected abstract renderInCanvas(canvas: SkCanvas, touches: TouchInfo[]): void;
|
34
|
+
/**
|
35
|
+
* Sends a redraw request to the native SkiaView.
|
36
|
+
*/
|
37
|
+
private tick;
|
38
|
+
redraw(): void;
|
39
|
+
/**
|
40
|
+
* Updates the drawing mode for the skia view. This is the same
|
41
|
+
* as declaratively setting the mode property on the SkiaView.
|
42
|
+
* There are two drawing modes, "continuous" and "default",
|
43
|
+
* where the continuous mode will continuously redraw the view and
|
44
|
+
* the default mode will only redraw when any of the regular react
|
45
|
+
* properties are changed like size and margins.
|
46
|
+
* @param mode Drawing mode to use.
|
47
|
+
*/
|
48
|
+
setDrawMode(mode: DrawMode): void;
|
49
|
+
/**
|
50
|
+
* Registers one or move values as a dependant value of the Skia View. The view will
|
51
|
+
* The view will redraw itself when any of the values change.
|
52
|
+
* @param values Values to register
|
53
|
+
*/
|
54
|
+
registerValues(_values: SkiaValue<unknown>[]): void;
|
55
|
+
private handleTouchEvent;
|
56
|
+
createTouchHandler(touchType: TouchType): (evt: PointerEvent) => void;
|
57
|
+
render(): JSX.Element;
|
58
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import React from "react";
|
2
|
+
import type { SkRect } from "../skia/types";
|
3
|
+
import type { SkiaValue } from "../values";
|
4
|
+
import type { SkiaPictureViewProps } from "./types";
|
5
|
+
export declare class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
|
6
|
+
constructor(props: SkiaPictureViewProps);
|
7
|
+
private _nativeId;
|
8
|
+
get nativeId(): number;
|
9
|
+
componentDidUpdate(prevProps: SkiaPictureViewProps): void;
|
10
|
+
/**
|
11
|
+
* Creates a snapshot from the canvas in the surface
|
12
|
+
* @param rect Rect to use as bounds. Optional.
|
13
|
+
* @returns An Image object.
|
14
|
+
*/
|
15
|
+
makeImageSnapshot(rect?: SkRect): import("../skia/types").SkImage;
|
16
|
+
/**
|
17
|
+
* Sends a redraw request to the native SkiaView.
|
18
|
+
*/
|
19
|
+
redraw(): void;
|
20
|
+
/**
|
21
|
+
* Registers one or move values as a dependant value of the Skia View. The view will
|
22
|
+
* The view will redraw itself when any of the values change.
|
23
|
+
* @param values Values to register
|
24
|
+
*/
|
25
|
+
registerValues(values: SkiaValue<unknown>[]): () => void;
|
26
|
+
render(): JSX.Element;
|
27
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import type { SkCanvas } from "../skia/types";
|
2
|
+
import type { SkiaPictureViewProps } from "./types";
|
3
|
+
import { SkiaBaseWebView } from "./SkiaBaseWebView";
|
4
|
+
export declare class SkiaPictureView extends SkiaBaseWebView<SkiaPictureViewProps> {
|
5
|
+
constructor(props: SkiaPictureViewProps);
|
6
|
+
protected renderInCanvas(canvas: SkCanvas): void;
|
7
|
+
}
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import React from "react";
|
2
2
|
import type { SkRect } from "../skia/types";
|
3
3
|
import type { SkiaValue } from "../values";
|
4
|
-
import type {
|
5
|
-
export declare class SkiaView extends React.Component<
|
6
|
-
constructor(props:
|
4
|
+
import type { SkiaDrawViewProps } from "./types";
|
5
|
+
export declare class SkiaView extends React.Component<SkiaDrawViewProps> {
|
6
|
+
constructor(props: SkiaDrawViewProps);
|
7
7
|
private _nativeId;
|
8
8
|
get nativeId(): number;
|
9
|
-
componentDidUpdate(prevProps:
|
9
|
+
componentDidUpdate(prevProps: SkiaDrawViewProps): void;
|
10
10
|
/**
|
11
11
|
* Creates a snapshot from the canvas in the surface
|
12
12
|
* @param rect Rect to use as bounds. Optional.
|
@@ -1,54 +1,7 @@
|
|
1
|
-
import
|
2
|
-
import type {
|
3
|
-
import
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
export declare class SkiaView extends React.Component<SkiaViewProps> {
|
8
|
-
constructor(props: SkiaViewProps);
|
9
|
-
private _surface;
|
10
|
-
private _unsubscriptions;
|
11
|
-
private _touches;
|
12
|
-
private _canvas;
|
13
|
-
private _canvasRef;
|
14
|
-
private _mode;
|
15
|
-
private _redrawRequests;
|
16
|
-
private width;
|
17
|
-
private height;
|
18
|
-
private requestId;
|
19
|
-
private unsubscribeAll;
|
20
|
-
private onLayout;
|
21
|
-
componentDidMount(): void;
|
22
|
-
componentDidUpdate(): void;
|
23
|
-
componentWillUnmount(): void;
|
24
|
-
/**
|
25
|
-
* Creates a snapshot from the canvas in the surface
|
26
|
-
* @param rect Rect to use as bounds. Optional.
|
27
|
-
* @returns An Image object.
|
28
|
-
*/
|
29
|
-
makeImageSnapshot(rect?: SkRect): import("../skia/types").SkImage | undefined;
|
30
|
-
/**
|
31
|
-
* Sends a redraw request to the native SkiaView.
|
32
|
-
*/
|
33
|
-
private tick;
|
34
|
-
redraw(): void;
|
35
|
-
/**
|
36
|
-
* Updates the drawing mode for the skia view. This is the same
|
37
|
-
* as declaratively setting the mode property on the SkiaView.
|
38
|
-
* There are two drawing modes, "continuous" and "default",
|
39
|
-
* where the continuous mode will continuously redraw the view and
|
40
|
-
* the default mode will only redraw when any of the regular react
|
41
|
-
* properties are changed like size and margins.
|
42
|
-
* @param mode Drawing mode to use.
|
43
|
-
*/
|
44
|
-
setDrawMode(mode: DrawMode): void;
|
45
|
-
/**
|
46
|
-
* Registers one or move values as a dependant value of the Skia View. The view will
|
47
|
-
* The view will redraw itself when any of the values change.
|
48
|
-
* @param values Values to register
|
49
|
-
*/
|
50
|
-
registerValues(_values: SkiaValue<unknown>[]): void;
|
51
|
-
private handleTouchEvent;
|
52
|
-
createTouchHandler(touchType: TouchType): (evt: PointerEvent) => void;
|
53
|
-
render(): JSX.Element;
|
1
|
+
import type { SkCanvas } from "../skia/types";
|
2
|
+
import type { SkiaDrawViewProps, TouchInfo } from "./types";
|
3
|
+
import { SkiaBaseWebView } from "./SkiaBaseWebView";
|
4
|
+
export declare class SkiaView extends SkiaBaseWebView<SkiaDrawViewProps> {
|
5
|
+
constructor(props: SkiaDrawViewProps);
|
6
|
+
protected renderInCanvas(canvas: SkCanvas, touches: TouchInfo[]): void;
|
54
7
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { ViewProps } from "react-native";
|
2
|
-
import type { SkCanvas, SkImage, SkRect } from "../skia/types";
|
2
|
+
import type { SkCanvas, SkImage, SkPicture, SkRect } from "../skia/types";
|
3
3
|
import type { SkiaValue } from "../values";
|
4
4
|
export declare type DrawMode = "continuous" | "default";
|
5
5
|
export declare type NativeSkiaViewProps = ViewProps & {
|
@@ -51,7 +51,7 @@ export interface ISkiaViewApi {
|
|
51
51
|
requestRedraw: (nativeId: number) => void;
|
52
52
|
makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;
|
53
53
|
}
|
54
|
-
export interface
|
54
|
+
export interface SkiaBaseViewProps extends ViewProps {
|
55
55
|
/**
|
56
56
|
* Sets the drawing mode for the skia view. There are two drawing
|
57
57
|
* modes, "continuous" and "default", where the continuous mode will
|
@@ -65,6 +65,8 @@ export interface SkiaViewProps extends ViewProps {
|
|
65
65
|
* average time it takes to render.
|
66
66
|
*/
|
67
67
|
debug?: boolean;
|
68
|
+
}
|
69
|
+
export interface SkiaDrawViewProps extends SkiaBaseViewProps {
|
68
70
|
/**
|
69
71
|
* Draw callback. Will be called whenever the view is invalidated and
|
70
72
|
* needs to redraw. This is either caused by a change in a react
|
@@ -74,3 +76,6 @@ export interface SkiaViewProps extends ViewProps {
|
|
74
76
|
*/
|
75
77
|
onDraw?: RNSkiaDrawCallback;
|
76
78
|
}
|
79
|
+
export interface SkiaPictureViewProps extends SkiaBaseViewProps {
|
80
|
+
picture?: SkPicture;
|
81
|
+
}
|
package/package.json
CHANGED