@shopify/react-native-skia 0.1.159 → 0.1.162
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/CMakeLists.txt +9 -9
- package/cpp/rnskia/RNSkDomView.cpp +3 -2
- package/cpp/rnskia/dom/base/JsiDependencyManager.h +6 -7
- package/cpp/rnskia/dom/base/JsiDomNode.h +59 -36
- package/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h +1 -1
- package/cpp/rnskia/dom/nodes/JsiPaintNode.h +3 -1
- package/cpp/rnskia/dom/props/BoxShadowProps.h +1 -0
- package/cpp/rnskia/dom/props/PaintProps.h +1 -2
- package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +1 -1
- package/lib/commonjs/renderer/Canvas.js +6 -4
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/views/SkiaBaseWebView.js +8 -0
- package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
- package/lib/module/renderer/Canvas.js +6 -3
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/views/SkiaBaseWebView.js +8 -0
- package/lib/module/views/SkiaBaseWebView.js.map +1 -1
- package/libs/android/arm64-v8a/libskottie.a +0 -0
- package/libs/android/arm64-v8a/libskshaper.a +0 -0
- package/libs/android/armeabi-v7a/libskottie.a +0 -0
- package/libs/android/armeabi-v7a/libskshaper.a +0 -0
- package/libs/android/x86/libskottie.a +0 -0
- package/libs/android/x86/libskshaper.a +0 -0
- package/libs/android/x86_64/libskottie.a +0 -0
- package/libs/android/x86_64/libskshaper.a +0 -0
- package/libs/ios/libskia.xcframework/Info.plist +5 -5
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
- package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
- package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
- package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
- package/package.json +9 -4
- package/react-native-skia.podspec +4 -3
- package/src/renderer/Canvas.tsx +5 -1
- package/src/views/SkiaBaseWebView.tsx +5 -0
- package/libs/android/arm64-v8a/libskparagraph.a +0 -0
- package/libs/android/arm64-v8a/libskunicode.a +0 -0
- package/libs/android/armeabi-v7a/libskparagraph.a +0 -0
- package/libs/android/armeabi-v7a/libskunicode.a +0 -0
- package/libs/android/x86/libskparagraph.a +0 -0
- package/libs/android/x86/libskunicode.a +0 -0
- package/libs/android/x86_64/libskparagraph.a +0 -0
- package/libs/android/x86_64/libskunicode.a +0 -0
- package/libs/ios/libskparagraph.xcframework/Info.plist +0 -42
- package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
- package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
- package/libs/ios/libskunicode.xcframework/Info.plist +0 -42
- package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e/libskunicode.a +0 -0
- package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode.a +0 -0
package/android/CMakeLists.txt
CHANGED
@@ -9,8 +9,8 @@ set (PACKAGE_NAME "reactskia")
|
|
9
9
|
set (SKIA_LIB "skia")
|
10
10
|
set (SKIA_SVG_LIB "svg")
|
11
11
|
set (SKIA_SKSHAPER_LIB "skshaper")
|
12
|
-
set (SKIA_SKPARAGRAPH_LIB "skparagraph")
|
13
|
-
set (SKIA_SKUNICODE_LIB "skunicode")
|
12
|
+
#set (SKIA_SKPARAGRAPH_LIB "skparagraph")
|
13
|
+
#set (SKIA_SKUNICODE_LIB "skunicode")
|
14
14
|
|
15
15
|
set(build_DIR ${CMAKE_SOURCE_DIR}/build)
|
16
16
|
file(GLOB LIBRN_DIR "${PREBUILT_DIR}/${ANDROID_ABI}")
|
@@ -72,7 +72,7 @@ target_include_directories(
|
|
72
72
|
cpp/skia/include/utils/
|
73
73
|
cpp/skia/include/pathops/
|
74
74
|
cpp/skia/modules/
|
75
|
-
cpp/skia/modules/skparagraph/include/
|
75
|
+
#cpp/skia/modules/skparagraph/include/
|
76
76
|
cpp/skia/include/
|
77
77
|
cpp/skia
|
78
78
|
|
@@ -103,11 +103,11 @@ set_property(TARGET svg PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libsvg.a")
|
|
103
103
|
add_library(skshaper STATIC IMPORTED)
|
104
104
|
set_property(TARGET skshaper PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskshaper.a")
|
105
105
|
|
106
|
-
add_library(skparagraph STATIC IMPORTED)
|
107
|
-
set_property(TARGET skparagraph PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskparagraph.a")
|
106
|
+
#add_library(skparagraph STATIC IMPORTED)
|
107
|
+
#set_property(TARGET skparagraph PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskparagraph.a")
|
108
108
|
|
109
|
-
add_library(skunicode STATIC IMPORTED)
|
110
|
-
set_property(TARGET skunicode PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskunicode.a")
|
109
|
+
#add_library(skunicode STATIC IMPORTED)
|
110
|
+
#set_property(TARGET skunicode PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskunicode.a")
|
111
111
|
|
112
112
|
|
113
113
|
find_library(
|
@@ -169,8 +169,8 @@ target_link_libraries(
|
|
169
169
|
${TURBOMODULES_LIB}
|
170
170
|
${SKIA_SVG_LIB}
|
171
171
|
${SKIA_SKSHAPER_LIB}
|
172
|
-
|
173
|
-
|
172
|
+
#${SKIA_SKPARAGRAPH_LIB}
|
173
|
+
#${SKIA_SKUNICODE_LIB}
|
174
174
|
${SKIA_LIB}
|
175
175
|
-ljnigraphics
|
176
176
|
-lGLESv2
|
@@ -84,8 +84,9 @@ void RNSkDomRenderer::renderCanvas(SkCanvas *canvas, float scaledWidth,
|
|
84
84
|
canvas->scale(pd, pd);
|
85
85
|
|
86
86
|
if (_drawingContext == nullptr) {
|
87
|
-
|
88
|
-
|
87
|
+
auto paint = std::make_shared<SkPaint>();
|
88
|
+
paint->setAntiAlias(true);
|
89
|
+
_drawingContext = std::make_shared<DrawingContext>(paint, 1.0f);
|
89
90
|
|
90
91
|
_drawingContext->setRequestRedraw([weakSelf = weak_from_this()]() {
|
91
92
|
auto self = weakSelf.lock();
|
@@ -114,13 +114,12 @@ public:
|
|
114
114
|
_subscriptions.emplace(node.get(), unsubscribers);
|
115
115
|
|
116
116
|
// Set callback for unsubscribing
|
117
|
-
node->setDisposeCallback(
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
});
|
117
|
+
node->setDisposeCallback([node, weakSelf = weak_from_this()]() {
|
118
|
+
auto self = weakSelf.lock();
|
119
|
+
if (self) {
|
120
|
+
self->unsubscribeNode(node.get());
|
121
|
+
}
|
122
|
+
});
|
124
123
|
|
125
124
|
return jsi::Value::undefined();
|
126
125
|
}
|
@@ -149,6 +149,9 @@ public:
|
|
149
149
|
*/
|
150
150
|
const char *getType() { return _type; }
|
151
151
|
|
152
|
+
/**
|
153
|
+
Returns the identifier for the node
|
154
|
+
*/
|
152
155
|
size_t getNodeId() { return _nodeId; }
|
153
156
|
|
154
157
|
/**
|
@@ -173,10 +176,22 @@ public:
|
|
173
176
|
not.
|
174
177
|
*/
|
175
178
|
void commitPendingChanges() {
|
179
|
+
// Update properties container
|
176
180
|
if (_propsContainer != nullptr) {
|
177
181
|
_propsContainer->updatePendingValues();
|
178
182
|
}
|
179
183
|
|
184
|
+
// Run all pending node operations
|
185
|
+
{
|
186
|
+
std::lock_guard<std::mutex> lock(_childrenLock);
|
187
|
+
for (auto &op : _queuedNodeOps) {
|
188
|
+
op();
|
189
|
+
}
|
190
|
+
|
191
|
+
_queuedNodeOps.clear();
|
192
|
+
}
|
193
|
+
|
194
|
+
// Update children
|
180
195
|
for (auto &child : _children) {
|
181
196
|
child->commitPendingChanges();
|
182
197
|
}
|
@@ -193,6 +208,34 @@ public:
|
|
193
208
|
_propsContainer->markAsResolved();
|
194
209
|
}
|
195
210
|
|
211
|
+
// Now let's dispose if needed
|
212
|
+
if (_isDisposed) {
|
213
|
+
// Callback signaling that we're done
|
214
|
+
if (_disposeCallback != nullptr) {
|
215
|
+
_disposeCallback();
|
216
|
+
_disposeCallback = nullptr;
|
217
|
+
}
|
218
|
+
|
219
|
+
// Clear props
|
220
|
+
if (_propsContainer != nullptr) {
|
221
|
+
_propsContainer->dispose();
|
222
|
+
}
|
223
|
+
|
224
|
+
// Remove children
|
225
|
+
std::vector<std::shared_ptr<JsiDomNode>> tmp;
|
226
|
+
{
|
227
|
+
std::lock_guard<std::mutex> lock(_childrenLock);
|
228
|
+
tmp.reserve(_children.size());
|
229
|
+
for (auto &child : _children) {
|
230
|
+
tmp.push_back(child);
|
231
|
+
}
|
232
|
+
_children.clear();
|
233
|
+
}
|
234
|
+
for (auto &child : tmp) {
|
235
|
+
child->dispose();
|
236
|
+
}
|
237
|
+
}
|
238
|
+
|
196
239
|
// Resolve children
|
197
240
|
for (auto &child : _children) {
|
198
241
|
child->resetPendingChanges();
|
@@ -262,7 +305,7 @@ protected:
|
|
262
305
|
*/
|
263
306
|
virtual void addChild(std::shared_ptr<JsiDomNode> child) {
|
264
307
|
std::lock_guard<std::mutex> lock(_childrenLock);
|
265
|
-
_children.push_back(child);
|
308
|
+
_queuedNodeOps.push_back([child, this]() { _children.push_back(child); });
|
266
309
|
}
|
267
310
|
|
268
311
|
/**
|
@@ -271,9 +314,11 @@ protected:
|
|
271
314
|
*/
|
272
315
|
virtual void insertChildBefore(std::shared_ptr<JsiDomNode> child,
|
273
316
|
std::shared_ptr<JsiDomNode> before) {
|
274
|
-
auto position = std::find(_children.begin(), _children.end(), before);
|
275
317
|
std::lock_guard<std::mutex> lock(_childrenLock);
|
276
|
-
|
318
|
+
_queuedNodeOps.push_back([child, before, this]() {
|
319
|
+
auto position = std::find(_children.begin(), _children.end(), before);
|
320
|
+
_children.insert(position, child);
|
321
|
+
});
|
277
322
|
}
|
278
323
|
|
279
324
|
/**
|
@@ -282,14 +327,15 @@ protected:
|
|
282
327
|
*/
|
283
328
|
virtual void removeChild(std::shared_ptr<JsiDomNode> child) {
|
284
329
|
std::lock_guard<std::mutex> lock(_childrenLock);
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
330
|
+
_queuedNodeOps.push_back([child, this]() {
|
331
|
+
// Delete child itself
|
332
|
+
_children.erase(
|
333
|
+
std::remove_if(_children.begin(), _children.end(),
|
334
|
+
[child](const auto &node) { return node == child; }),
|
335
|
+
_children.end());
|
336
|
+
|
337
|
+
child->dispose();
|
338
|
+
});
|
293
339
|
}
|
294
340
|
|
295
341
|
/**
|
@@ -302,31 +348,6 @@ protected:
|
|
302
348
|
}
|
303
349
|
|
304
350
|
_isDisposed = true;
|
305
|
-
|
306
|
-
// Callback signaling that we're done
|
307
|
-
if (_disposeCallback != nullptr) {
|
308
|
-
_disposeCallback();
|
309
|
-
_disposeCallback = nullptr;
|
310
|
-
}
|
311
|
-
|
312
|
-
// Clear props
|
313
|
-
if (_propsContainer != nullptr) {
|
314
|
-
_propsContainer->dispose();
|
315
|
-
}
|
316
|
-
|
317
|
-
// Remove children
|
318
|
-
std::vector<std::shared_ptr<JsiDomNode>> tmp;
|
319
|
-
{
|
320
|
-
std::lock_guard<std::mutex> lock(_childrenLock);
|
321
|
-
tmp.reserve(_children.size());
|
322
|
-
for (auto &child : _children) {
|
323
|
-
tmp.push_back(child);
|
324
|
-
}
|
325
|
-
_children.clear();
|
326
|
-
}
|
327
|
-
for (auto &child : tmp) {
|
328
|
-
child->dispose();
|
329
|
-
}
|
330
351
|
}
|
331
352
|
|
332
353
|
#if SKIA_DOM_DEBUG
|
@@ -356,6 +377,8 @@ private:
|
|
356
377
|
std::atomic<bool> _isDisposed = {false};
|
357
378
|
|
358
379
|
size_t _nodeId;
|
380
|
+
|
381
|
+
std::vector<std::function<void()>> _queuedNodeOps;
|
359
382
|
};
|
360
383
|
|
361
384
|
} // namespace RNSkia
|
@@ -44,7 +44,7 @@ protected:
|
|
44
44
|
if (paint->getColorFilter() != nullptr &&
|
45
45
|
paint->getColorFilter() != getCurrent().get()) {
|
46
46
|
paint->setColorFilter(
|
47
|
-
SkColorFilters::Compose(paint->refColorFilter()
|
47
|
+
SkColorFilters::Compose(ColorFilter, paint->refColorFilter()));
|
48
48
|
} else {
|
49
49
|
paint->setColorFilter(ColorFilter);
|
50
50
|
}
|
@@ -37,7 +37,9 @@ public:
|
|
37
37
|
// ...and it should be a totally new paint, not inheriting from parent
|
38
38
|
// paint.
|
39
39
|
if (_localContext->isChanged()) {
|
40
|
-
|
40
|
+
auto paint = std::make_shared<SkPaint>();
|
41
|
+
paint->setAntiAlias(true);
|
42
|
+
_localContext->setMutablePaint(paint);
|
41
43
|
}
|
42
44
|
|
43
45
|
// Let's decorate paint props
|
@@ -150,8 +150,7 @@ public:
|
|
150
150
|
// AntiAlias
|
151
151
|
if (_antiAlias->isSet() &&
|
152
152
|
(_antiAlias->isChanged() || context->isChanged())) {
|
153
|
-
context->getMutablePaint()->setAntiAlias(
|
154
|
-
_antiAlias->value().getAsNumber());
|
153
|
+
context->getMutablePaint()->setAntiAlias(_antiAlias->value().getAsBool());
|
155
154
|
}
|
156
155
|
}
|
157
156
|
|
@@ -62,7 +62,7 @@ float RNSkMetalCanvasProvider::getScaledHeight() { return _height * _context->ge
|
|
62
62
|
Render to a canvas
|
63
63
|
*/
|
64
64
|
void RNSkMetalCanvasProvider::renderToCanvas(const std::function<void(SkCanvas*)>& cb) {
|
65
|
-
if(_width
|
65
|
+
if (_width <= 0 || _height <= 0) {
|
66
66
|
return;
|
67
67
|
}
|
68
68
|
|
@@ -29,7 +29,8 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
29
29
|
|
30
30
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
31
31
|
|
32
|
-
|
32
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
33
|
+
|
33
34
|
const skiaReconciler = (0, _reactReconciler.default)(_HostConfig.skHostConfig);
|
34
35
|
exports.skiaReconciler = skiaReconciler;
|
35
36
|
skiaReconciler.injectIntoDevTools({
|
@@ -58,7 +59,8 @@ const Canvas = /*#__PURE__*/(0, _react.forwardRef)((_ref, forwardedRef) => {
|
|
58
59
|
debug,
|
59
60
|
mode,
|
60
61
|
onTouch,
|
61
|
-
onSize
|
62
|
+
onSize,
|
63
|
+
...props
|
62
64
|
} = _ref;
|
63
65
|
const innerRef = useCanvasRef();
|
64
66
|
const ref = useCombinedRefs(forwardedRef, innerRef);
|
@@ -94,7 +96,7 @@ const Canvas = /*#__PURE__*/(0, _react.forwardRef)((_ref, forwardedRef) => {
|
|
94
96
|
});
|
95
97
|
};
|
96
98
|
}, [container, root]);
|
97
|
-
return /*#__PURE__*/_react.default.createElement(_views.SkiaDomView, {
|
99
|
+
return /*#__PURE__*/_react.default.createElement(_views.SkiaDomView, _extends({
|
98
100
|
ref: ref,
|
99
101
|
style: style,
|
100
102
|
root: container.root,
|
@@ -102,7 +104,7 @@ const Canvas = /*#__PURE__*/(0, _react.forwardRef)((_ref, forwardedRef) => {
|
|
102
104
|
onSize: onSize,
|
103
105
|
mode: mode,
|
104
106
|
debug: debug
|
105
|
-
});
|
107
|
+
}, props));
|
106
108
|
});
|
107
109
|
/**
|
108
110
|
* Combines a list of refs into a single ref. This can be used to provide
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["skiaReconciler","ReactReconciler","skHostConfig","injectIntoDevTools","bundleType","version","rendererPackageName","render","element","root","container","updateContainer","hostDebug","depMgr","update","useCanvasRef","useRef","createDependencyManager","registerValues","global","SkiaDomApi","DependencyManager","Canvas","forwardRef","forwardedRef","children","style","debug","mode","onTouch","onSize","innerRef","ref","useCombinedRefs","setTick","useState","redraw","useCallback","Platform","OS","tick","current","values","Error","useMemo","Container","Skia","createContainer","console","error","useEffect","remove","refs","targetRef","React","forEach"],"sources":["Canvas.tsx"],"sourcesContent":["import React, {\n useEffect,\n useCallback,\n useMemo,\n forwardRef,\n useRef,\n useState,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n ComponentProps,\n MutableRefObject,\n ForwardedRef,\n} from \"react\";\nimport type { OpaqueRoot } from \"react-reconciler\";\nimport ReactReconciler from \"react-reconciler\";\nimport { Platform } from \"react-native\";\n\nimport { SkiaDomView } from \"../views\";\nimport type { TouchHandler } from \"../views\";\nimport { Skia } from \"../skia/Skia\";\nimport type { SkiaValue } from \"../values\";\n\nimport { debug as hostDebug, skHostConfig } from \"./HostConfig\";\n// import { debugTree } from \"./nodes\";\nimport { Container } from \"./Container\";\nimport { DependencyManager } from \"./DependencyManager\";\nimport { CanvasProvider } from \"./useCanvas\";\n\nexport const skiaReconciler = ReactReconciler(skHostConfig);\n\nskiaReconciler.injectIntoDevTools({\n bundleType: 1,\n version: \"0.0.1\",\n rendererPackageName: \"react-native-skia\",\n});\n\nconst render = (element: ReactNode, root: OpaqueRoot, container: Container) => {\n skiaReconciler.updateContainer(element, root, null, () => {\n hostDebug(\"updateContainer\");\n container.depMgr.update();\n });\n};\n\nexport const useCanvasRef = () => useRef<SkiaDomView>(null);\n\nconst createDependencyManager = (\n registerValues: (values: Array<SkiaValue<unknown>>) => () => void\n) =>\n global.SkiaDomApi && global.SkiaDomApi.DependencyManager\n ? global.SkiaDomApi.DependencyManager(registerValues)\n : new DependencyManager(registerValues);\n\nexport interface CanvasProps extends ComponentProps<typeof SkiaDomView> {\n ref?: RefObject<SkiaDomView>;\n children: ReactNode;\n onTouch?: TouchHandler;\n}\n\nexport const Canvas = forwardRef<SkiaDomView, CanvasProps>(\n ({ children, style, debug, mode, onTouch, onSize }
|
1
|
+
{"version":3,"names":["skiaReconciler","ReactReconciler","skHostConfig","injectIntoDevTools","bundleType","version","rendererPackageName","render","element","root","container","updateContainer","hostDebug","depMgr","update","useCanvasRef","useRef","createDependencyManager","registerValues","global","SkiaDomApi","DependencyManager","Canvas","forwardRef","forwardedRef","children","style","debug","mode","onTouch","onSize","props","innerRef","ref","useCombinedRefs","setTick","useState","redraw","useCallback","Platform","OS","tick","current","values","Error","useMemo","Container","Skia","createContainer","console","error","useEffect","remove","refs","targetRef","React","forEach"],"sources":["Canvas.tsx"],"sourcesContent":["import React, {\n useEffect,\n useCallback,\n useMemo,\n forwardRef,\n useRef,\n useState,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n ComponentProps,\n MutableRefObject,\n ForwardedRef,\n} from \"react\";\nimport type { OpaqueRoot } from \"react-reconciler\";\nimport ReactReconciler from \"react-reconciler\";\nimport { Platform } from \"react-native\";\n\nimport { SkiaDomView } from \"../views\";\nimport type { TouchHandler } from \"../views\";\nimport { Skia } from \"../skia/Skia\";\nimport type { SkiaValue } from \"../values\";\n\nimport { debug as hostDebug, skHostConfig } from \"./HostConfig\";\n// import { debugTree } from \"./nodes\";\nimport { Container } from \"./Container\";\nimport { DependencyManager } from \"./DependencyManager\";\nimport { CanvasProvider } from \"./useCanvas\";\n\nexport const skiaReconciler = ReactReconciler(skHostConfig);\n\nskiaReconciler.injectIntoDevTools({\n bundleType: 1,\n version: \"0.0.1\",\n rendererPackageName: \"react-native-skia\",\n});\n\nconst render = (element: ReactNode, root: OpaqueRoot, container: Container) => {\n skiaReconciler.updateContainer(element, root, null, () => {\n hostDebug(\"updateContainer\");\n container.depMgr.update();\n });\n};\n\nexport const useCanvasRef = () => useRef<SkiaDomView>(null);\n\nconst createDependencyManager = (\n registerValues: (values: Array<SkiaValue<unknown>>) => () => void\n) =>\n global.SkiaDomApi && global.SkiaDomApi.DependencyManager\n ? global.SkiaDomApi.DependencyManager(registerValues)\n : new DependencyManager(registerValues);\n\nexport interface CanvasProps extends ComponentProps<typeof SkiaDomView> {\n ref?: RefObject<SkiaDomView>;\n children: ReactNode;\n onTouch?: TouchHandler;\n}\n\nexport const Canvas = forwardRef<SkiaDomView, CanvasProps>(\n (\n { children, style, debug, mode, onTouch, onSize, ...props },\n forwardedRef\n ) => {\n const innerRef = useCanvasRef();\n const ref = useCombinedRefs(forwardedRef, innerRef);\n const [, setTick] = useState(0);\n const redraw = useCallback(() => {\n Platform.OS === \"web\"\n ? setTick((tick) => tick + 1)\n : innerRef.current?.redraw();\n }, [innerRef]);\n\n const registerValues = useCallback(\n (values: Array<SkiaValue<unknown>>) => {\n if (ref.current === null) {\n throw new Error(\"Canvas ref is not set\");\n }\n return ref.current.registerValues(values);\n },\n [ref]\n );\n\n const container = useMemo(() => {\n return new Container(\n Skia,\n createDependencyManager(registerValues),\n redraw\n );\n }, [redraw, registerValues]);\n\n const root = useMemo(\n () =>\n skiaReconciler.createContainer(\n container,\n 0,\n null,\n true,\n null,\n \"\",\n console.error,\n null\n ),\n [container]\n );\n\n // Render effect\n useEffect(() => {\n render(\n <CanvasProvider value={{ Skia }}>{children}</CanvasProvider>,\n root,\n container\n );\n }, [children, root, redraw, container]);\n\n useEffect(() => {\n return () => {\n skiaReconciler.updateContainer(null, root, null, () => {\n container.depMgr.remove();\n });\n };\n }, [container, root]);\n\n return (\n <SkiaDomView\n ref={ref}\n style={style}\n root={container.root}\n onTouch={onTouch}\n onSize={onSize}\n mode={mode}\n debug={debug}\n {...props}\n />\n );\n }\n);\n\n/**\n * Combines a list of refs into a single ref. This can be used to provide\n * both a forwarded ref and an internal ref keeping the same functionality\n * on both of the refs.\n * @param refs Array of refs to combine\n * @returns A single ref that can be used in a ref prop.\n */\nconst useCombinedRefs = <T,>(\n ...refs: Array<MutableRefObject<T> | ForwardedRef<T>>\n) => {\n const targetRef = React.useRef<T>(null);\n React.useEffect(() => {\n refs.forEach((ref) => {\n if (ref) {\n if (typeof ref === \"function\") {\n ref(targetRef.current);\n } else {\n ref.current = targetRef.current;\n }\n }\n });\n }, [refs]);\n return targetRef;\n};\n"],"mappings":";;;;;;;AAAA;;AAgBA;;AACA;;AAEA;;AAEA;;AAGA;;AAEA;;AACA;;AACA;;;;;;;;;;AAEO,MAAMA,cAAc,GAAG,IAAAC,wBAAA,EAAgBC,wBAAhB,CAAvB;;AAEPF,cAAc,CAACG,kBAAf,CAAkC;EAChCC,UAAU,EAAE,CADoB;EAEhCC,OAAO,EAAE,OAFuB;EAGhCC,mBAAmB,EAAE;AAHW,CAAlC;;AAMA,MAAMC,MAAM,GAAG,CAACC,OAAD,EAAqBC,IAArB,EAAuCC,SAAvC,KAAgE;EAC7EV,cAAc,CAACW,e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F,IANR;IAOE,KAAK,EAAED;EAPT,GAQMI,KARN,EADF;AAYD,CA5EmB,CAAf;AA+EP;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACA,MAAMG,eAAe,GAAG,YAEnB;EAAA,kCADAmB,IACA;IADAA,IACA;EAAA;;EACH,MAAMC,SAAS,GAAGC,cAAA,CAAMvC,MAAN,CAAgB,IAAhB,CAAlB;;EACAuC,cAAA,CAAMJ,SAAN,CAAgB,MAAM;IACpBE,IAAI,CAACG,OAAL,CAAcvB,GAAD,IAAS;MACpB,IAAIA,GAAJ,EAAS;QACP,IAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;UAC7BA,GAAG,CAACqB,SAAS,CAACZ,OAAX,CAAH;QACD,CAFD,MAEO;UACLT,GAAG,CAACS,OAAJ,GAAcY,SAAS,CAACZ,OAAxB;QACD;MACF;IACF,CARD;EASD,CAVD,EAUG,CAACW,IAAD,CAVH;;EAWA,OAAOC,SAAP;AACD,CAhBD"}
|
@@ -78,6 +78,11 @@ class SkiaBaseWebView extends _react.default.Component {
|
|
78
78
|
this._surface = new _JsiSkSurface.JsiSkSurface(CanvasKit, surface);
|
79
79
|
this._canvas = this._surface.getCanvas();
|
80
80
|
this.redraw();
|
81
|
+
} // Call onLayout callback if it exists
|
82
|
+
|
83
|
+
|
84
|
+
if (this.props.onLayout) {
|
85
|
+
this.props.onLayout(evt);
|
81
86
|
}
|
82
87
|
}
|
83
88
|
|
@@ -130,6 +135,9 @@ class SkiaBaseWebView extends _react.default.Component {
|
|
130
135
|
|
131
136
|
const touches = [...this._touches];
|
132
137
|
this._touches = [];
|
138
|
+
|
139
|
+
this._canvas.clear(CanvasKit.TRANSPARENT);
|
140
|
+
|
133
141
|
this.renderInCanvas(this._canvas, touches);
|
134
142
|
(_this$_surface2 = this._surface) === null || _this$_surface2 === void 0 ? void 0 : _this$_surface2.ref.flush();
|
135
143
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["pd","PixelRatio","get","SkiaBaseWebView","React","Component","constructor","props","createRef","_mode","mode","unsubscribeAll","_unsubscriptions","forEach","u","onLayout","evt","CanvasKit","global","width","height","nativeEvent","layout","_canvasRef","current","canvas","surface","MakeWebGLCanvasSurface","Error","_surface","JsiSkSurface","_canvas","getCanvas","redraw","getSize","componentDidMount","tick","componentDidUpdate","componentWillUnmount","cancelAnimationFrame","requestId","makeImageSnapshot","rect","_redrawRequests","touches","_touches","renderInCanvas","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","timestamp","Date","now","createTouchHandler","render","debug","viewProps","display","flex","TouchType","Start","Active","End","Cancelled"],"sources":["SkiaBaseWebView.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 { DrawMode, SkiaBaseViewProps, TouchInfo } from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst pd = PixelRatio.get();\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 _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 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 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 = width * pd;\n canvas.height = height * 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 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 }\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 * Override to render\n */\n protected abstract renderInCanvas(\n canvas: SkCanvas,\n touches: TouchInfo[]\n ): 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 touches = [...this._touches];\n this._touches = [];\n this.renderInCanvas(this._canvas!, touches);\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":";;;;;;;AACA;;AAGA;;AAIA;;AAGA;;;;;;;;AAEA,MAAMA,EAAE,GAAGC,uBAAA,CAAWC,GAAX,EAAX;;AAEO,MAAeC,eAAf,SAEGC,cAAA,CAAMC,SAFT,CAE2B;EAChCC,WAAW,CAACC,KAAD,EAAgB;IACzB,MAAMA,KAAN;;IADyB,kCAKa,IALb;;IAAA,0CAMmB,EANnB;;IAAA,kCAOU,EAPV;;IAAA,iCAQQ,IARR;;IAAA,iDASNH,cAAA,CAAMI,SAAN,EATM;;IAAA;;IAAA,yCAWD,CAXC;;IAAA,mCAYP,CAZO;;IAAA,+BAcT,CAdS;;IAAA,gCAeR,CAfQ;;IAEzB,KAAKC,KAAL,GAAaF,KAAK,CAACG,IAAN,IAAc,SAA3B;EACD;;E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AAUG,GAAlC;IARhB,EADF,CADF;EAcD;;AAlK+B"}
|
1
|
+
{"version":3,"names":["pd","PixelRatio","get","SkiaBaseWebView","React","Component","constructor","props","createRef","_mode","mode","unsubscribeAll","_unsubscriptions","forEach","u","onLayout","evt","CanvasKit","global","width","height","nativeEvent","layout","_canvasRef","current","canvas","surface","MakeWebGLCanvasSurface","Error","_surface","JsiSkSurface","_canvas","getCanvas","redraw","getSize","componentDidMount","tick","componentDidUpdate","componentWillUnmount","cancelAnimationFrame","requestId","makeImageSnapshot","rect","_redrawRequests","touches","_touches","clear","TRANSPARENT","renderInCanvas","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","timestamp","Date","now","createTouchHandler","render","debug","viewProps","display","flex","TouchType","Start","Active","End","Cancelled"],"sources":["SkiaBaseWebView.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 { DrawMode, SkiaBaseViewProps, TouchInfo } from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst pd = PixelRatio.get();\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 _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 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 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 = width * pd;\n canvas.height = height * 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 // 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 }\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 * Override to render\n */\n protected abstract renderInCanvas(\n canvas: SkCanvas,\n touches: TouchInfo[]\n ): 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 touches = [...this._touches];\n this._touches = [];\n this._canvas!.clear(CanvasKit.TRANSPARENT);\n this.renderInCanvas(this._canvas!, touches);\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":";;;;;;;AACA;;AAGA;;AAIA;;AAGA;;;;;;;;AAEA,MAAMA,EAAE,GAAGC,uBAAA,CAAWC,GAAX,EAAX;;AAEO,MAAeC,eAAf,SAEGC,cAAA,CAAMC,SAFT,CAE2B;EAChCC,WAAW,CAACC,KAAD,EAAgB;IACzB,MAAMA,KAAN;;IADyB,kCAKa,IALb;;IAAA,0CAMmB,EANnB;;IAAA,kCAOU,EAPV;;IAAA,iCAQQ,IARR;;IAAA,i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E,KAAKL,kBAAL,CAAwBM,gBAAA,CAAUC,KAAlC,CAHjB;MAIE,aAAa,EAAE,KAAKP,kBAAL,CAAwBM,gBAAA,CAAUE,MAAlC,CAJjB;MAKE,WAAW,EAAE,KAAKR,kBAAL,CAAwBM,gBAAA,CAAUG,GAAlC,CALf;MAME,eAAe,EAAE,KAAKT,kBAAL,CAAwBM,gBAAA,CAAUI,SAAlC,CANnB;MAOE,cAAc,EAAE,KAAKV,kBAAL,CAAwBM,gBAAA,CAAUG,GAAlC,CAPlB;MAQE,YAAY,EAAE,KAAKT,kBAAL,CAAwBM,gBAAA,CAAUG,GAAlC;IARhB,EADF,CADF;EAcD;;AAvK+B"}
|
@@ -1,3 +1,5 @@
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
2
|
+
|
1
3
|
import React, { useEffect, useCallback, useMemo, forwardRef, useRef, useState } from "react";
|
2
4
|
import ReactReconciler from "react-reconciler";
|
3
5
|
import { Platform } from "react-native";
|
@@ -33,7 +35,8 @@ export const Canvas = /*#__PURE__*/forwardRef((_ref, forwardedRef) => {
|
|
33
35
|
debug,
|
34
36
|
mode,
|
35
37
|
onTouch,
|
36
|
-
onSize
|
38
|
+
onSize,
|
39
|
+
...props
|
37
40
|
} = _ref;
|
38
41
|
const innerRef = useCanvasRef();
|
39
42
|
const ref = useCombinedRefs(forwardedRef, innerRef);
|
@@ -69,7 +72,7 @@ export const Canvas = /*#__PURE__*/forwardRef((_ref, forwardedRef) => {
|
|
69
72
|
});
|
70
73
|
};
|
71
74
|
}, [container, root]);
|
72
|
-
return /*#__PURE__*/React.createElement(SkiaDomView, {
|
75
|
+
return /*#__PURE__*/React.createElement(SkiaDomView, _extends({
|
73
76
|
ref: ref,
|
74
77
|
style: style,
|
75
78
|
root: container.root,
|
@@ -77,7 +80,7 @@ export const Canvas = /*#__PURE__*/forwardRef((_ref, forwardedRef) => {
|
|
77
80
|
onSize: onSize,
|
78
81
|
mode: mode,
|
79
82
|
debug: debug
|
80
|
-
});
|
83
|
+
}, props));
|
81
84
|
});
|
82
85
|
/**
|
83
86
|
* Combines a list of refs into a single ref. This can be used to provide
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","useEffect","useCallback","useMemo","forwardRef","useRef","useState","ReactReconciler","Platform","SkiaDomView","Skia","debug","hostDebug","skHostConfig","Container","DependencyManager","CanvasProvider","skiaReconciler","injectIntoDevTools","bundleType","version","rendererPackageName","render","element","root","container","updateContainer","depMgr","update","useCanvasRef","createDependencyManager","registerValues","global","SkiaDomApi","Canvas","forwardedRef","children","style","mode","onTouch","onSize","innerRef","ref","useCombinedRefs","setTick","redraw","OS","tick","current","values","Error","createContainer","console","error","remove","refs","targetRef","forEach"],"sources":["Canvas.tsx"],"sourcesContent":["import React, {\n useEffect,\n useCallback,\n useMemo,\n forwardRef,\n useRef,\n useState,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n ComponentProps,\n MutableRefObject,\n ForwardedRef,\n} from \"react\";\nimport type { OpaqueRoot } from \"react-reconciler\";\nimport ReactReconciler from \"react-reconciler\";\nimport { Platform } from \"react-native\";\n\nimport { SkiaDomView } from \"../views\";\nimport type { TouchHandler } from \"../views\";\nimport { Skia } from \"../skia/Skia\";\nimport type { SkiaValue } from \"../values\";\n\nimport { debug as hostDebug, skHostConfig } from \"./HostConfig\";\n// import { debugTree } from \"./nodes\";\nimport { Container } from \"./Container\";\nimport { DependencyManager } from \"./DependencyManager\";\nimport { CanvasProvider } from \"./useCanvas\";\n\nexport const skiaReconciler = ReactReconciler(skHostConfig);\n\nskiaReconciler.injectIntoDevTools({\n bundleType: 1,\n version: \"0.0.1\",\n rendererPackageName: \"react-native-skia\",\n});\n\nconst render = (element: ReactNode, root: OpaqueRoot, container: Container) => {\n skiaReconciler.updateContainer(element, root, null, () => {\n hostDebug(\"updateContainer\");\n container.depMgr.update();\n });\n};\n\nexport const useCanvasRef = () => useRef<SkiaDomView>(null);\n\nconst createDependencyManager = (\n registerValues: (values: Array<SkiaValue<unknown>>) => () => void\n) =>\n global.SkiaDomApi && global.SkiaDomApi.DependencyManager\n ? global.SkiaDomApi.DependencyManager(registerValues)\n : new DependencyManager(registerValues);\n\nexport interface CanvasProps extends ComponentProps<typeof SkiaDomView> {\n ref?: RefObject<SkiaDomView>;\n children: ReactNode;\n onTouch?: TouchHandler;\n}\n\nexport const Canvas = forwardRef<SkiaDomView, CanvasProps>(\n ({ children, style, debug, mode, onTouch, onSize }
|
1
|
+
{"version":3,"names":["React","useEffect","useCallback","useMemo","forwardRef","useRef","useState","ReactReconciler","Platform","SkiaDomView","Skia","debug","hostDebug","skHostConfig","Container","DependencyManager","CanvasProvider","skiaReconciler","injectIntoDevTools","bundleType","version","rendererPackageName","render","element","root","container","updateContainer","depMgr","update","useCanvasRef","createDependencyManager","registerValues","global","SkiaDomApi","Canvas","forwardedRef","children","style","mode","onTouch","onSize","props","innerRef","ref","useCombinedRefs","setTick","redraw","OS","tick","current","values","Error","createContainer","console","error","remove","refs","targetRef","forEach"],"sources":["Canvas.tsx"],"sourcesContent":["import React, {\n useEffect,\n useCallback,\n useMemo,\n forwardRef,\n useRef,\n useState,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n ComponentProps,\n MutableRefObject,\n ForwardedRef,\n} from \"react\";\nimport type { OpaqueRoot } from \"react-reconciler\";\nimport ReactReconciler from \"react-reconciler\";\nimport { Platform } from \"react-native\";\n\nimport { SkiaDomView } from \"../views\";\nimport type { TouchHandler } from \"../views\";\nimport { Skia } from \"../skia/Skia\";\nimport type { SkiaValue } from \"../values\";\n\nimport { debug as hostDebug, skHostConfig } from \"./HostConfig\";\n// import { debugTree } from \"./nodes\";\nimport { Container } from \"./Container\";\nimport { DependencyManager } from \"./DependencyManager\";\nimport { CanvasProvider } from \"./useCanvas\";\n\nexport const skiaReconciler = ReactReconciler(skHostConfig);\n\nskiaReconciler.injectIntoDevTools({\n bundleType: 1,\n version: \"0.0.1\",\n rendererPackageName: \"react-native-skia\",\n});\n\nconst render = (element: ReactNode, root: OpaqueRoot, container: Container) => {\n skiaReconciler.updateContainer(element, root, null, () => {\n hostDebug(\"updateContainer\");\n container.depMgr.update();\n });\n};\n\nexport const useCanvasRef = () => useRef<SkiaDomView>(null);\n\nconst createDependencyManager = (\n registerValues: (values: Array<SkiaValue<unknown>>) => () => void\n) =>\n global.SkiaDomApi && global.SkiaDomApi.DependencyManager\n ? global.SkiaDomApi.DependencyManager(registerValues)\n : new DependencyManager(registerValues);\n\nexport interface CanvasProps extends ComponentProps<typeof SkiaDomView> {\n ref?: RefObject<SkiaDomView>;\n children: ReactNode;\n onTouch?: TouchHandler;\n}\n\nexport const Canvas = forwardRef<SkiaDomView, CanvasProps>(\n (\n { children, style, debug, mode, onTouch, onSize, ...props },\n forwardedRef\n ) => {\n const innerRef = useCanvasRef();\n const ref = useCombinedRefs(forwardedRef, innerRef);\n const [, setTick] = useState(0);\n const redraw = useCallback(() => {\n Platform.OS === \"web\"\n ? setTick((tick) => tick + 1)\n : innerRef.current?.redraw();\n }, [innerRef]);\n\n const registerValues = useCallback(\n (values: Array<SkiaValue<unknown>>) => {\n if (ref.current === null) {\n throw new Error(\"Canvas ref is not set\");\n }\n return ref.current.registerValues(values);\n },\n [ref]\n );\n\n const container = useMemo(() => {\n return new Container(\n Skia,\n createDependencyManager(registerValues),\n redraw\n );\n }, [redraw, registerValues]);\n\n const root = useMemo(\n () =>\n skiaReconciler.createContainer(\n container,\n 0,\n null,\n true,\n null,\n \"\",\n console.error,\n null\n ),\n [container]\n );\n\n // Render effect\n useEffect(() => {\n render(\n <CanvasProvider value={{ Skia }}>{children}</CanvasProvider>,\n root,\n container\n );\n }, [children, root, redraw, container]);\n\n useEffect(() => {\n return () => {\n skiaReconciler.updateContainer(null, root, null, () => {\n container.depMgr.remove();\n });\n };\n }, [container, root]);\n\n return (\n <SkiaDomView\n ref={ref}\n style={style}\n root={container.root}\n onTouch={onTouch}\n onSize={onSize}\n mode={mode}\n debug={debug}\n {...props}\n />\n );\n }\n);\n\n/**\n * Combines a list of refs into a single ref. This can be used to provide\n * both a forwarded ref and an internal ref keeping the same functionality\n * on both of the refs.\n * @param refs Array of refs to combine\n * @returns A single ref that can be used in a ref prop.\n */\nconst useCombinedRefs = <T,>(\n ...refs: Array<MutableRefObject<T> | ForwardedRef<T>>\n) => {\n const targetRef = React.useRef<T>(null);\n React.useEffect(() => {\n refs.forEach((ref) => {\n if (ref) {\n if (typeof ref === \"function\") {\n ref(targetRef.current);\n } else {\n ref.current = targetRef.current;\n }\n }\n });\n }, [refs]);\n return targetRef;\n};\n"],"mappings":";;AAAA,OAAOA,KAAP,IACEC,SADF,EAEEC,WAFF,EAGEC,OAHF,EAIEC,UAJF,EAKEC,MALF,EAMEC,QANF,QAOO,OAPP;AAgBA,OAAOC,eAAP,MAA4B,kBAA5B;AACA,SAASC,QAAT,QAAyB,cAAzB;AAEA,SAASC,WAAT,QAA4B,UAA5B;AAEA,SAASC,IAAT,QAAqB,cAArB;AAGA,SAASC,KAAK,IAAIC,SAAlB,EAA6BC,YAA7B,QAAiD,cAAjD,C,CACA;;AACA,SAASC,SAAT,QAA0B,aAA1B;AACA,SAASC,iBAAT,QAAkC,qBAAlC;AACA,SAASC,cAAT,QAA+B,aAA/B;AAEA,OAAO,MAAMC,cAAc,GAAGV,eAAe,CAACM,YAAD,CAAtC;AAEPI,cAAc,CAACC,kBAAf,CAAkC;EAChCC,UAAU,EAAE,CADoB;EAEhCC,OAAO,EAAE,OAFuB;EAGhCC,mBAAmB,EAAE;AAHW,CAAlC;;AAMA,MAAMC,MAAM,GAAG,CAACC,OAAD,EAAqBC,IAArB,EAAuCC,SAAvC,KAAgE;EAC7ER,cAAc,CAACS,eAAf,CAA+BH,OAA/B,EAAwCC,IAAxC,EAA8C,IAA9C,EAA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P;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMG,eAAe,GAAG,YAEnB;EAAA,kCADAY,IACA;IADAA,IACA;EAAA;;EACH,MAAMC,SAAS,GAAGzD,KAAK,CAACK,MAAN,CAAgB,IAAhB,CAAlB;EACAL,KAAK,CAACC,SAAN,CAAgB,MAAM;IACpBuD,IAAI,CAACE,OAAL,CAAcf,GAAD,IAAS;MACpB,IAAIA,GAAJ,EAAS;QACP,IAAI,OAAOA,GAAP,KAAe,UAAnB,EAA+B;UAC7BA,GAAG,CAACc,SAAS,CAACR,OAAX,CAAH;QACD,CAFD,MAEO;UACLN,GAAG,CAACM,OAAJ,GAAcQ,SAAS,CAACR,OAAxB;QACD;MACF;IACF,CARD;EASD,CAVD,EAUG,CAACO,IAAD,CAVH;EAWA,OAAOC,SAAP;AACD,CAhBD"}
|
@@ -67,6 +67,11 @@ export class SkiaBaseWebView extends React.Component {
|
|
67
67
|
this._surface = new JsiSkSurface(CanvasKit, surface);
|
68
68
|
this._canvas = this._surface.getCanvas();
|
69
69
|
this.redraw();
|
70
|
+
} // Call onLayout callback if it exists
|
71
|
+
|
72
|
+
|
73
|
+
if (this.props.onLayout) {
|
74
|
+
this.props.onLayout(evt);
|
70
75
|
}
|
71
76
|
}
|
72
77
|
|
@@ -119,6 +124,9 @@ export class SkiaBaseWebView extends React.Component {
|
|
119
124
|
|
120
125
|
const touches = [...this._touches];
|
121
126
|
this._touches = [];
|
127
|
+
|
128
|
+
this._canvas.clear(CanvasKit.TRANSPARENT);
|
129
|
+
|
122
130
|
this.renderInCanvas(this._canvas, touches);
|
123
131
|
(_this$_surface2 = this._surface) === null || _this$_surface2 === void 0 ? void 0 : _this$_surface2.ref.flush();
|
124
132
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","PixelRatio","View","JsiSkSurface","TouchType","pd","get","SkiaBaseWebView","Component","constructor","props","createRef","_mode","mode","unsubscribeAll","_unsubscriptions","forEach","u","onLayout","evt","CanvasKit","global","width","height","nativeEvent","layout","_canvasRef","current","canvas","surface","MakeWebGLCanvasSurface","Error","_surface","_canvas","getCanvas","redraw","getSize","componentDidMount","tick","componentDidUpdate","componentWillUnmount","cancelAnimationFrame","requestId","makeImageSnapshot","rect","_redrawRequests","touches","_touches","renderInCanvas","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","timestamp","Date","now","createTouchHandler","render","debug","viewProps","display","flex","Start","Active","End","Cancelled"],"sources":["SkiaBaseWebView.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 { DrawMode, SkiaBaseViewProps, TouchInfo } from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst pd = PixelRatio.get();\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 _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 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 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 = width * pd;\n canvas.height = height * 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 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 }\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 * Override to render\n */\n protected abstract renderInCanvas(\n canvas: SkCanvas,\n touches: TouchInfo[]\n ): 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 touches = [...this._touches];\n this._touches = [];\n this.renderInCanvas(this._canvas!, touches);\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,MAAeC,eAAf,SAEGP,KAAK,CAACQ,SAFT,CAE2B;EAChCC,WAAW,CAACC,KAAD,EAAgB;IAAA;;IACzB,MAAMA,KAAN;;IADyB,kCAKa,IALb;;IAAA,0CAMmB,EANnB;;IAAA,kCAOU,EAPV;;IAAA,iCAQQ,IARR;;IAAA,iDASNV,KAAK,CAACW,SAAN,EATM;;IAAA;;IAAA,yCAWD,CAXC;;IAAA,mCAYP,CAZO;;IAAA,+BAcT,CAdS;;IAAA,gCAeR,CAfQ;;IAEzB,KAAKC,KAAL,kBAAaF,KAAK,CAACG,IAA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AAKR,kBAAL,CAAwBzE,SAAS,CAACiF,GAAlC;IARhB,EADF,CADF;EAcD;;AAlK+B"}
|
1
|
+
{"version":3,"names":["React","PixelRatio","View","JsiSkSurface","TouchType","pd","get","SkiaBaseWebView","Component","constructor","props","createRef","_mode","mode","unsubscribeAll","_unsubscriptions","forEach","u","onLayout","evt","CanvasKit","global","width","height","nativeEvent","layout","_canvasRef","current","canvas","surface","MakeWebGLCanvasSurface","Error","_surface","_canvas","getCanvas","redraw","getSize","componentDidMount","tick","componentDidUpdate","componentWillUnmount","cancelAnimationFrame","requestId","makeImageSnapshot","rect","_redrawRequests","touches","_touches","clear","TRANSPARENT","renderInCanvas","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","timestamp","Date","now","createTouchHandler","render","debug","viewProps","display","flex","Start","Active","End","Cancelled"],"sources":["SkiaBaseWebView.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 { DrawMode, SkiaBaseViewProps, TouchInfo } from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst pd = PixelRatio.get();\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 _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 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 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 = width * pd;\n canvas.height = height * 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 // 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 }\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 * Override to render\n */\n protected abstract renderInCanvas(\n canvas: SkCanvas,\n touches: TouchInfo[]\n ): 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 touches = [...this._touches];\n this._touches = [];\n this._canvas!.clear(CanvasKit.TRANSPARENT);\n this.renderInCanvas(this._canvas!, touches);\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,MAAeC,eAAf,SAEGP,KAAK,CAACQ,SAFT,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C,IAAd,CAAmB,IAAnB;IAA/B,iBACE;MACE,GAAG,EAAE,KAAK5B,UADZ;MAEE,KAAK,EAAE;QAAEyD,OAAO,EAAE,MAAX;QAAmBC,IAAI,EAAE;MAAzB,CAFT;MAGE,aAAa,EAAE,KAAKL,kBAAL,CAAwB3E,SAAS,CAACiF,KAAlC,CAHjB;MAIE,aAAa,EAAE,KAAKN,kBAAL,CAAwB3E,SAAS,CAACkF,MAAlC,CAJjB;MAKE,WAAW,EAAE,KAAKP,kBAAL,CAAwB3E,SAAS,CAACmF,GAAlC,CALf;MAME,eAAe,EAAE,KAAKR,kBAAL,CAAwB3E,SAAS,CAACoF,SAAlC,CANnB;MAOE,cAAc,EAAE,KAAKT,kBAAL,CAAwB3E,SAAS,CAACmF,GAAlC,CAPlB;MAQE,YAAY,EAAE,KAAKR,kBAAL,CAAwB3E,SAAS,CAACmF,GAAlC;IARhB,EADF,CADF;EAcD;;AAvK+B"}
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -6,32 +6,32 @@
|
|
6
6
|
<array>
|
7
7
|
<dict>
|
8
8
|
<key>LibraryIdentifier</key>
|
9
|
-
<string>ios-
|
9
|
+
<string>ios-arm64_arm64e_x86_64-simulator</string>
|
10
10
|
<key>LibraryPath</key>
|
11
11
|
<string>libskia.a</string>
|
12
12
|
<key>SupportedArchitectures</key>
|
13
13
|
<array>
|
14
14
|
<string>arm64</string>
|
15
15
|
<string>arm64e</string>
|
16
|
+
<string>x86_64</string>
|
16
17
|
</array>
|
17
18
|
<key>SupportedPlatform</key>
|
18
19
|
<string>ios</string>
|
20
|
+
<key>SupportedPlatformVariant</key>
|
21
|
+
<string>simulator</string>
|
19
22
|
</dict>
|
20
23
|
<dict>
|
21
24
|
<key>LibraryIdentifier</key>
|
22
|
-
<string>ios-
|
25
|
+
<string>ios-arm64_arm64e</string>
|
23
26
|
<key>LibraryPath</key>
|
24
27
|
<string>libskia.a</string>
|
25
28
|
<key>SupportedArchitectures</key>
|
26
29
|
<array>
|
27
30
|
<string>arm64</string>
|
28
31
|
<string>arm64e</string>
|
29
|
-
<string>x86_64</string>
|
30
32
|
</array>
|
31
33
|
<key>SupportedPlatform</key>
|
32
34
|
<string>ios</string>
|
33
|
-
<key>SupportedPlatformVariant</key>
|
34
|
-
<string>simulator</string>
|
35
35
|
</dict>
|
36
36
|
</array>
|
37
37
|
<key>CFBundlePackageType</key>
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -6,32 +6,32 @@
|
|
6
6
|
<array>
|
7
7
|
<dict>
|
8
8
|
<key>LibraryIdentifier</key>
|
9
|
-
<string>ios-
|
9
|
+
<string>ios-arm64_arm64e_x86_64-simulator</string>
|
10
10
|
<key>LibraryPath</key>
|
11
11
|
<string>libskshaper.a</string>
|
12
12
|
<key>SupportedArchitectures</key>
|
13
13
|
<array>
|
14
14
|
<string>arm64</string>
|
15
15
|
<string>arm64e</string>
|
16
|
+
<string>x86_64</string>
|
16
17
|
</array>
|
17
18
|
<key>SupportedPlatform</key>
|
18
19
|
<string>ios</string>
|
20
|
+
<key>SupportedPlatformVariant</key>
|
21
|
+
<string>simulator</string>
|
19
22
|
</dict>
|
20
23
|
<dict>
|
21
24
|
<key>LibraryIdentifier</key>
|
22
|
-
<string>ios-
|
25
|
+
<string>ios-arm64_arm64e</string>
|
23
26
|
<key>LibraryPath</key>
|
24
27
|
<string>libskshaper.a</string>
|
25
28
|
<key>SupportedArchitectures</key>
|
26
29
|
<array>
|
27
30
|
<string>arm64</string>
|
28
31
|
<string>arm64e</string>
|
29
|
-
<string>x86_64</string>
|
30
32
|
</array>
|
31
33
|
<key>SupportedPlatform</key>
|
32
34
|
<string>ios</string>
|
33
|
-
<key>SupportedPlatformVariant</key>
|
34
|
-
<string>simulator</string>
|
35
35
|
</dict>
|
36
36
|
</array>
|
37
37
|
<key>CFBundlePackageType</key>
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
package/package.json
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
"setup-skia-web": "./scripts/setup-canvaskit.js"
|
8
8
|
},
|
9
9
|
"title": "React Native Skia",
|
10
|
-
"version": "0.1.
|
10
|
+
"version": "0.1.162",
|
11
11
|
"description": "High-performance React Native Graphics using Skia",
|
12
12
|
"main": "lib/module/index.js",
|
13
13
|
"files": [
|
@@ -32,8 +32,6 @@
|
|
32
32
|
"libs/ios/libsvg.xcframework",
|
33
33
|
"libs/ios/libskottie.xcframework",
|
34
34
|
"libs/ios/libsksg.xcframework",
|
35
|
-
"libs/ios/libskparagraph.xcframework",
|
36
|
-
"libs/ios/libskunicode.xcframework",
|
37
35
|
"react-native-skia.podspec",
|
38
36
|
"scripts/install-npm.js",
|
39
37
|
"scripts/setup-canvaskit.js",
|
@@ -43,6 +41,7 @@
|
|
43
41
|
"tsc": "tsc --noEmit",
|
44
42
|
"lint": "eslint . --ext .ts,.tsx --max-warnings 0 --cache",
|
45
43
|
"test": "jest",
|
44
|
+
"e2e": "E2E=true yarn test -i e2e",
|
46
45
|
"postinstall": "node scripts/install-npm.js",
|
47
46
|
"build": "bob build"
|
48
47
|
},
|
@@ -94,8 +93,14 @@
|
|
94
93
|
"typescript": "4.8.3"
|
95
94
|
},
|
96
95
|
"dependencies": {
|
96
|
+
"@types/pixelmatch": "^5.2.4",
|
97
|
+
"@types/pngjs": "^6.0.1",
|
98
|
+
"@types/ws": "^8.5.3",
|
97
99
|
"canvaskit-wasm": "0.36.1",
|
98
|
-
"
|
100
|
+
"pixelmatch": "^5.3.0",
|
101
|
+
"pngjs": "^6.0.0",
|
102
|
+
"react-reconciler": "^0.27.0",
|
103
|
+
"ws": "^8.11.0"
|
99
104
|
},
|
100
105
|
"eslintIgnore": [
|
101
106
|
"node_modules/",
|
@@ -23,7 +23,8 @@ Pod::Spec.new do |s|
|
|
23
23
|
s.requires_arc = true
|
24
24
|
s.pod_target_xcconfig = {
|
25
25
|
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) SK_GL=1 SK_METAL=1',
|
26
|
-
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17'
|
26
|
+
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
|
27
|
+
'DEFINES_MODULE' => 'YES'
|
27
28
|
}
|
28
29
|
|
29
30
|
s.frameworks = 'GLKit', 'MetalKit'
|
@@ -32,8 +33,8 @@ Pod::Spec.new do |s|
|
|
32
33
|
'libs/ios/libskia.xcframework',
|
33
34
|
'libs/ios/libsvg.xcframework',
|
34
35
|
'libs/ios/libskshaper.xcframework',
|
35
|
-
'libs/ios/libskparagraph.xcframework',
|
36
|
-
'libs/ios/libskunicode.xcframework',
|
36
|
+
#'libs/ios/libskparagraph.xcframework',
|
37
|
+
#'libs/ios/libskunicode.xcframework',
|
37
38
|
]
|
38
39
|
|
39
40
|
# All iOS cpp/h files
|
package/src/renderer/Canvas.tsx
CHANGED
@@ -59,7 +59,10 @@ export interface CanvasProps extends ComponentProps<typeof SkiaDomView> {
|
|
59
59
|
}
|
60
60
|
|
61
61
|
export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
|
62
|
-
(
|
62
|
+
(
|
63
|
+
{ children, style, debug, mode, onTouch, onSize, ...props },
|
64
|
+
forwardedRef
|
65
|
+
) => {
|
63
66
|
const innerRef = useCanvasRef();
|
64
67
|
const ref = useCombinedRefs(forwardedRef, innerRef);
|
65
68
|
const [, setTick] = useState(0);
|
@@ -128,6 +131,7 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
|
|
128
131
|
onSize={onSize}
|
129
132
|
mode={mode}
|
130
133
|
debug={debug}
|
134
|
+
{...props}
|
131
135
|
/>
|
132
136
|
);
|
133
137
|
}
|
@@ -56,6 +56,10 @@ export abstract class SkiaBaseWebView<
|
|
56
56
|
this._canvas = this._surface.getCanvas();
|
57
57
|
this.redraw();
|
58
58
|
}
|
59
|
+
// Call onLayout callback if it exists
|
60
|
+
if (this.props.onLayout) {
|
61
|
+
this.props.onLayout(evt);
|
62
|
+
}
|
59
63
|
}
|
60
64
|
|
61
65
|
protected getSize() {
|
@@ -102,6 +106,7 @@ export abstract class SkiaBaseWebView<
|
|
102
106
|
if (this._canvas) {
|
103
107
|
const touches = [...this._touches];
|
104
108
|
this._touches = [];
|
109
|
+
this._canvas!.clear(CanvasKit.TRANSPARENT);
|
105
110
|
this.renderInCanvas(this._canvas!, touches);
|
106
111
|
this._surface?.ref.flush();
|
107
112
|
}
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,42 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
-
<plist version="1.0">
|
4
|
-
<dict>
|
5
|
-
<key>AvailableLibraries</key>
|
6
|
-
<array>
|
7
|
-
<dict>
|
8
|
-
<key>LibraryIdentifier</key>
|
9
|
-
<string>ios-arm64_arm64e_x86_64-simulator</string>
|
10
|
-
<key>LibraryPath</key>
|
11
|
-
<string>libskparagraph.a</string>
|
12
|
-
<key>SupportedArchitectures</key>
|
13
|
-
<array>
|
14
|
-
<string>arm64</string>
|
15
|
-
<string>arm64e</string>
|
16
|
-
<string>x86_64</string>
|
17
|
-
</array>
|
18
|
-
<key>SupportedPlatform</key>
|
19
|
-
<string>ios</string>
|
20
|
-
<key>SupportedPlatformVariant</key>
|
21
|
-
<string>simulator</string>
|
22
|
-
</dict>
|
23
|
-
<dict>
|
24
|
-
<key>LibraryIdentifier</key>
|
25
|
-
<string>ios-arm64_arm64e</string>
|
26
|
-
<key>LibraryPath</key>
|
27
|
-
<string>libskparagraph.a</string>
|
28
|
-
<key>SupportedArchitectures</key>
|
29
|
-
<array>
|
30
|
-
<string>arm64</string>
|
31
|
-
<string>arm64e</string>
|
32
|
-
</array>
|
33
|
-
<key>SupportedPlatform</key>
|
34
|
-
<string>ios</string>
|
35
|
-
</dict>
|
36
|
-
</array>
|
37
|
-
<key>CFBundlePackageType</key>
|
38
|
-
<string>XFWK</string>
|
39
|
-
<key>XCFrameworkFormatVersion</key>
|
40
|
-
<string>1.0</string>
|
41
|
-
</dict>
|
42
|
-
</plist>
|
Binary file
|
package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a
DELETED
Binary file
|
@@ -1,42 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
-
<plist version="1.0">
|
4
|
-
<dict>
|
5
|
-
<key>AvailableLibraries</key>
|
6
|
-
<array>
|
7
|
-
<dict>
|
8
|
-
<key>LibraryIdentifier</key>
|
9
|
-
<string>ios-arm64_arm64e</string>
|
10
|
-
<key>LibraryPath</key>
|
11
|
-
<string>libskunicode.a</string>
|
12
|
-
<key>SupportedArchitectures</key>
|
13
|
-
<array>
|
14
|
-
<string>arm64</string>
|
15
|
-
<string>arm64e</string>
|
16
|
-
</array>
|
17
|
-
<key>SupportedPlatform</key>
|
18
|
-
<string>ios</string>
|
19
|
-
</dict>
|
20
|
-
<dict>
|
21
|
-
<key>LibraryIdentifier</key>
|
22
|
-
<string>ios-arm64_arm64e_x86_64-simulator</string>
|
23
|
-
<key>LibraryPath</key>
|
24
|
-
<string>libskunicode.a</string>
|
25
|
-
<key>SupportedArchitectures</key>
|
26
|
-
<array>
|
27
|
-
<string>arm64</string>
|
28
|
-
<string>arm64e</string>
|
29
|
-
<string>x86_64</string>
|
30
|
-
</array>
|
31
|
-
<key>SupportedPlatform</key>
|
32
|
-
<string>ios</string>
|
33
|
-
<key>SupportedPlatformVariant</key>
|
34
|
-
<string>simulator</string>
|
35
|
-
</dict>
|
36
|
-
</array>
|
37
|
-
<key>CFBundlePackageType</key>
|
38
|
-
<string>XFWK</string>
|
39
|
-
<key>XCFrameworkFormatVersion</key>
|
40
|
-
<string>1.0</string>
|
41
|
-
</dict>
|
42
|
-
</plist>
|
Binary file
|