@shopify/react-native-skia 0.1.233 → 0.1.234
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +0 -1
- package/android/cpp/jni/JniSkiaManager.cpp +0 -1
- package/android/cpp/rnskia-android/RNSkAndroidView.h +0 -1
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +1 -1
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +1 -2
- package/lib/commonjs/external/reanimated/interpolators.js +3 -1
- package/lib/commonjs/external/reanimated/interpolators.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.js +5 -4
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPath.d.ts +2 -2
- package/lib/commonjs/skia/web/JsiSkPath.js +10 -2
- package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
- package/lib/commonjs/views/SkiaJSDomView.d.ts +31 -0
- package/lib/commonjs/views/SkiaJSDomView.js +161 -0
- package/lib/commonjs/views/SkiaJSDomView.js.map +1 -0
- package/lib/commonjs/views/SkiaJSDomView.web.d.ts +1 -0
- package/lib/commonjs/views/SkiaJSDomView.web.js +14 -0
- package/lib/commonjs/views/SkiaJSDomView.web.js.map +1 -0
- package/lib/module/external/reanimated/interpolators.js +2 -1
- package/lib/module/external/reanimated/interpolators.js.map +1 -1
- package/lib/module/renderer/Canvas.js +4 -3
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/skia/web/JsiSkPath.d.ts +2 -2
- package/lib/module/skia/web/JsiSkPath.js +10 -2
- package/lib/module/skia/web/JsiSkPath.js.map +1 -1
- package/lib/module/views/SkiaJSDomView.d.ts +31 -0
- package/lib/module/views/SkiaJSDomView.js +136 -0
- package/lib/module/views/SkiaJSDomView.js.map +1 -0
- package/lib/module/views/SkiaJSDomView.web.d.ts +1 -0
- package/lib/module/views/SkiaJSDomView.web.js +2 -0
- package/lib/module/views/SkiaJSDomView.web.js.map +1 -0
- package/lib/typescript/src/skia/web/JsiSkPath.d.ts +2 -2
- package/lib/typescript/src/views/SkiaJSDomView.d.ts +31 -0
- package/lib/typescript/src/views/SkiaJSDomView.web.d.ts +1 -0
- package/package.json +1 -1
- package/src/external/reanimated/interpolators.ts +2 -1
- package/src/renderer/Canvas.tsx +3 -2
- package/src/skia/web/JsiSkPath.ts +23 -3
- package/src/views/SkiaJSDomView.tsx +126 -0
- package/src/views/SkiaJSDomView.web.tsx +1 -0
- package/android/cpp/jni/include/JniSkiaDrawView.h +0 -90
- package/cpp/rnskia/RNSkJsView.cpp +0 -236
- package/cpp/rnskia/RNSkJsView.h +0 -121
@@ -1,90 +0,0 @@
|
|
1
|
-
#pragma once
|
2
|
-
|
3
|
-
#include <memory>
|
4
|
-
#include <string>
|
5
|
-
|
6
|
-
#include <fbjni/fbjni.h>
|
7
|
-
#include <jni.h>
|
8
|
-
#include <jsi/jsi.h>
|
9
|
-
|
10
|
-
#include <JniSkiaBaseView.h>
|
11
|
-
#include <JniSkiaManager.h>
|
12
|
-
#include <RNSkAndroidView.h>
|
13
|
-
#include <RNSkJsView.h>
|
14
|
-
|
15
|
-
#include <android/native_window.h>
|
16
|
-
#include <android/native_window_jni.h>
|
17
|
-
#include <fbjni/detail/Hybrid.h>
|
18
|
-
|
19
|
-
namespace RNSkia {
|
20
|
-
namespace jsi = facebook::jsi;
|
21
|
-
namespace jni = facebook::jni;
|
22
|
-
|
23
|
-
class JniSkiaDrawView : public jni::HybridClass<JniSkiaDrawView>,
|
24
|
-
public JniSkiaBaseView {
|
25
|
-
public:
|
26
|
-
static auto constexpr kJavaDescriptor =
|
27
|
-
"Lcom/shopify/reactnative/skia/SkiaDrawView;";
|
28
|
-
|
29
|
-
static jni::local_ref<jhybriddata>
|
30
|
-
initHybrid(jni::alias_ref<jhybridobject> jThis,
|
31
|
-
jni::alias_ref<JniSkiaManager::javaobject> skiaManager) {
|
32
|
-
return makeCxxInstance(jThis, skiaManager);
|
33
|
-
}
|
34
|
-
|
35
|
-
static void registerNatives() {
|
36
|
-
registerHybrid(
|
37
|
-
{makeNativeMethod("initHybrid", JniSkiaDrawView::initHybrid),
|
38
|
-
makeNativeMethod("surfaceAvailable",
|
39
|
-
JniSkiaDrawView::surfaceAvailable),
|
40
|
-
makeNativeMethod("surfaceDestroyed",
|
41
|
-
JniSkiaDrawView::surfaceDestroyed),
|
42
|
-
makeNativeMethod("surfaceSizeChanged",
|
43
|
-
JniSkiaDrawView::surfaceSizeChanged),
|
44
|
-
makeNativeMethod("setMode", JniSkiaDrawView::setMode),
|
45
|
-
makeNativeMethod("setDebugMode", JniSkiaDrawView::setDebugMode),
|
46
|
-
makeNativeMethod("updateTouchPoints",
|
47
|
-
JniSkiaDrawView::updateTouchPoints),
|
48
|
-
makeNativeMethod("registerView", JniSkiaDrawView::registerView),
|
49
|
-
makeNativeMethod("unregisterView", JniSkiaDrawView::unregisterView)});
|
50
|
-
}
|
51
|
-
|
52
|
-
protected:
|
53
|
-
void updateTouchPoints(jni::JArrayDouble touches) override {
|
54
|
-
JniSkiaBaseView::updateTouchPoints(touches);
|
55
|
-
}
|
56
|
-
|
57
|
-
void surfaceAvailable(jobject surface, int width, int height) override {
|
58
|
-
JniSkiaBaseView::surfaceAvailable(surface, width, height);
|
59
|
-
}
|
60
|
-
|
61
|
-
void surfaceSizeChanged(int width, int height) override {
|
62
|
-
JniSkiaBaseView::surfaceSizeChanged(width, height);
|
63
|
-
}
|
64
|
-
|
65
|
-
void surfaceDestroyed() override { JniSkiaBaseView::surfaceDestroyed(); }
|
66
|
-
|
67
|
-
void setMode(std::string mode) override { JniSkiaBaseView::setMode(mode); }
|
68
|
-
|
69
|
-
void setDebugMode(bool show) override { JniSkiaBaseView::setDebugMode(show); }
|
70
|
-
|
71
|
-
void registerView(int nativeId) override {
|
72
|
-
JniSkiaBaseView::registerView(nativeId);
|
73
|
-
}
|
74
|
-
|
75
|
-
void unregisterView() override { JniSkiaBaseView::unregisterView(); }
|
76
|
-
|
77
|
-
private:
|
78
|
-
friend HybridBase;
|
79
|
-
|
80
|
-
explicit JniSkiaDrawView(
|
81
|
-
jni::alias_ref<jhybridobject> jThis,
|
82
|
-
jni::alias_ref<JniSkiaManager::javaobject> skiaManager)
|
83
|
-
: JniSkiaBaseView(skiaManager,
|
84
|
-
std::make_shared<RNSkAndroidView<RNSkia::RNSkJsView>>(
|
85
|
-
skiaManager->cthis()->getPlatformContext())) {}
|
86
|
-
|
87
|
-
jni::global_ref<javaobject> javaPart_;
|
88
|
-
};
|
89
|
-
|
90
|
-
} // namespace RNSkia
|
@@ -1,236 +0,0 @@
|
|
1
|
-
#include <utility>
|
2
|
-
|
3
|
-
#include "RNSkJsView.h"
|
4
|
-
|
5
|
-
namespace RNSkia {
|
6
|
-
|
7
|
-
RNSkJsRenderer::RNSkJsRenderer(std::function<void()> requestRedraw,
|
8
|
-
std::shared_ptr<RNSkPlatformContext> context)
|
9
|
-
: RNSkRenderer(requestRedraw),
|
10
|
-
_jsiCanvas(std::make_shared<JsiSkCanvas>(context)),
|
11
|
-
_platformContext(context),
|
12
|
-
_infoObject(std::make_shared<RNSkInfoObject>()),
|
13
|
-
_jsDrawingLock(std::make_shared<std::timed_mutex>()),
|
14
|
-
_gpuDrawingLock(std::make_shared<std::timed_mutex>()),
|
15
|
-
_jsTimingInfo("SKIA/JS"), _gpuTimingInfo("SKIA/GPU") {}
|
16
|
-
|
17
|
-
bool RNSkJsRenderer::tryRender(
|
18
|
-
std::shared_ptr<RNSkCanvasProvider> canvasProvider) {
|
19
|
-
// We render on the javascript thread.
|
20
|
-
if (_jsDrawingLock->try_lock()) {
|
21
|
-
_platformContext->runOnJavascriptThread(
|
22
|
-
[weakSelf = weak_from_this(), canvasProvider]() {
|
23
|
-
auto self = weakSelf.lock();
|
24
|
-
if (self) {
|
25
|
-
self->performDraw(canvasProvider);
|
26
|
-
}
|
27
|
-
});
|
28
|
-
return true;
|
29
|
-
} else {
|
30
|
-
#ifdef DEBUG
|
31
|
-
_jsTimingInfo.markSkipped();
|
32
|
-
#endif
|
33
|
-
return false;
|
34
|
-
}
|
35
|
-
}
|
36
|
-
|
37
|
-
void RNSkJsRenderer::renderImmediate(
|
38
|
-
std::shared_ptr<RNSkCanvasProvider> canvasProvider) {
|
39
|
-
// Get start time to be able to calculate animations etc.
|
40
|
-
std::chrono::milliseconds ms =
|
41
|
-
std::chrono::duration_cast<std::chrono::milliseconds>(
|
42
|
-
std::chrono::system_clock::now().time_since_epoch());
|
43
|
-
|
44
|
-
std::condition_variable cv;
|
45
|
-
std::mutex m;
|
46
|
-
std::unique_lock<std::mutex> lock(m);
|
47
|
-
|
48
|
-
// We need to render on the javascript thread but block
|
49
|
-
// until we're done rendering. Render immediate is used
|
50
|
-
// to make images from the canvas.
|
51
|
-
_platformContext->runOnJavascriptThread([canvasProvider, ms, &cv, &m,
|
52
|
-
weakSelf = weak_from_this()]() {
|
53
|
-
// Lock
|
54
|
-
std::unique_lock<std::mutex> lock(m);
|
55
|
-
|
56
|
-
auto self = weakSelf.lock();
|
57
|
-
if (self) {
|
58
|
-
canvasProvider->renderToCanvas([self, ms,
|
59
|
-
canvasProvider](SkCanvas *canvas) {
|
60
|
-
// Create jsi canvas
|
61
|
-
auto jsiCanvas = std::make_shared<JsiSkCanvas>(self->_platformContext);
|
62
|
-
jsiCanvas->setCanvas(canvas);
|
63
|
-
|
64
|
-
self->drawInJsiCanvas(
|
65
|
-
std::move(jsiCanvas), canvasProvider->getScaledWidth(),
|
66
|
-
canvasProvider->getScaledHeight(), ms.count() / 1000);
|
67
|
-
});
|
68
|
-
}
|
69
|
-
|
70
|
-
cv.notify_one();
|
71
|
-
});
|
72
|
-
|
73
|
-
cv.wait(lock);
|
74
|
-
}
|
75
|
-
|
76
|
-
void RNSkJsRenderer::setDrawCallback(
|
77
|
-
std::shared_ptr<jsi::Function> drawCallback) {
|
78
|
-
_drawCallback = drawCallback;
|
79
|
-
}
|
80
|
-
|
81
|
-
std::shared_ptr<RNSkInfoObject> RNSkJsRenderer::getInfoObject() {
|
82
|
-
return _infoObject;
|
83
|
-
}
|
84
|
-
|
85
|
-
void RNSkJsRenderer::performDraw(
|
86
|
-
std::shared_ptr<RNSkCanvasProvider> canvasProvider) {
|
87
|
-
// Start timing
|
88
|
-
_jsTimingInfo.beginTiming();
|
89
|
-
|
90
|
-
// Record the drawing operations on the JS thread so that we can
|
91
|
-
// move the actual drawing onto the render thread later
|
92
|
-
SkPictureRecorder recorder;
|
93
|
-
SkRTreeFactory factory;
|
94
|
-
SkCanvas *canvas =
|
95
|
-
recorder.beginRecording(canvasProvider->getScaledWidth(),
|
96
|
-
canvasProvider->getScaledHeight(), &factory);
|
97
|
-
|
98
|
-
_jsiCanvas->setCanvas(canvas);
|
99
|
-
|
100
|
-
// Get current milliseconds
|
101
|
-
std::chrono::milliseconds ms =
|
102
|
-
std::chrono::duration_cast<std::chrono::milliseconds>(
|
103
|
-
std::chrono::system_clock::now().time_since_epoch());
|
104
|
-
|
105
|
-
try {
|
106
|
-
// Perform the javascript drawing
|
107
|
-
drawInJsiCanvas(_jsiCanvas, canvasProvider->getScaledWidth(),
|
108
|
-
canvasProvider->getScaledHeight(), ms.count() / 1000.0);
|
109
|
-
|
110
|
-
} catch (...) {
|
111
|
-
_jsTimingInfo.stopTiming();
|
112
|
-
_jsDrawingLock->unlock();
|
113
|
-
throw;
|
114
|
-
}
|
115
|
-
|
116
|
-
// Finish drawing operations
|
117
|
-
auto p = recorder.finishRecordingAsPicture();
|
118
|
-
|
119
|
-
_jsiCanvas->setCanvas(nullptr);
|
120
|
-
|
121
|
-
// Calculate duration
|
122
|
-
_jsTimingInfo.stopTiming();
|
123
|
-
|
124
|
-
if (_gpuDrawingLock->try_lock()) {
|
125
|
-
|
126
|
-
// Post drawing message to the main thread where the picture recorded
|
127
|
-
// will be sent to the GPU/backend for rendering to screen.
|
128
|
-
// TODO: Which thread should we render on? I think it should be main thread!
|
129
|
-
auto gpuLock = _gpuDrawingLock;
|
130
|
-
_platformContext->runOnMainThread([weakSelf = weak_from_this(),
|
131
|
-
p = std::move(p), gpuLock,
|
132
|
-
canvasProvider]() {
|
133
|
-
auto self = weakSelf.lock();
|
134
|
-
if (self) {
|
135
|
-
// Draw the picture recorded on the real GPU canvas
|
136
|
-
self->_gpuTimingInfo.beginTiming();
|
137
|
-
|
138
|
-
canvasProvider->renderToCanvas(
|
139
|
-
[p = std::move(p)](SkCanvas *canvas) { canvas->drawPicture(p); });
|
140
|
-
|
141
|
-
self->_gpuTimingInfo.stopTiming();
|
142
|
-
}
|
143
|
-
// Unlock GPU drawing
|
144
|
-
gpuLock->unlock();
|
145
|
-
});
|
146
|
-
} else {
|
147
|
-
#ifdef DEBUG
|
148
|
-
_gpuTimingInfo.markSkipped();
|
149
|
-
#endif
|
150
|
-
// Request a new redraw since the last frame was skipped.
|
151
|
-
_requestRedraw();
|
152
|
-
}
|
153
|
-
|
154
|
-
// Unlock JS drawing
|
155
|
-
_jsDrawingLock->unlock();
|
156
|
-
}
|
157
|
-
|
158
|
-
void RNSkJsRenderer::callJsDrawCallback(std::shared_ptr<JsiSkCanvas> jsiCanvas,
|
159
|
-
int width, int height,
|
160
|
-
double timestamp) {
|
161
|
-
|
162
|
-
if (_drawCallback == nullptr) {
|
163
|
-
return;
|
164
|
-
}
|
165
|
-
|
166
|
-
// Reset timing info
|
167
|
-
_jsTimingInfo.reset();
|
168
|
-
_gpuTimingInfo.reset();
|
169
|
-
|
170
|
-
auto runtime = _platformContext->getJsRuntime();
|
171
|
-
|
172
|
-
// Update info parameter
|
173
|
-
_infoObject->beginDrawOperation(width, height, timestamp);
|
174
|
-
|
175
|
-
// Set up arguments array
|
176
|
-
std::vector<jsi::Value> args(2);
|
177
|
-
args[0] = jsi::Object::createFromHostObject(*runtime, jsiCanvas);
|
178
|
-
args[1] = jsi::Object::createFromHostObject(*runtime, _infoObject);
|
179
|
-
|
180
|
-
// To be able to call the drawing function we'll wrap it once again
|
181
|
-
_drawCallback->call(*runtime, static_cast<const jsi::Value *>(args.data()),
|
182
|
-
static_cast<size_t>(2));
|
183
|
-
|
184
|
-
// Reset touches
|
185
|
-
_infoObject->endDrawOperation();
|
186
|
-
|
187
|
-
// Draw debug overlays
|
188
|
-
if (getShowDebugOverlays()) {
|
189
|
-
|
190
|
-
// Display average rendering timer
|
191
|
-
auto jsAvg = _jsTimingInfo.getAverage();
|
192
|
-
// auto jsFps = _jsTimingInfo.getFps();
|
193
|
-
|
194
|
-
auto gpuAvg = _gpuTimingInfo.getAverage();
|
195
|
-
// auto gpuFps = _gpuTimingInfo.getFps();
|
196
|
-
|
197
|
-
auto total = jsAvg + gpuAvg;
|
198
|
-
|
199
|
-
// Build string
|
200
|
-
std::ostringstream stream;
|
201
|
-
stream << "js: " << jsAvg << "ms gpu: " << gpuAvg << "ms "
|
202
|
-
<< " total: " << total << "ms";
|
203
|
-
|
204
|
-
std::string debugString = stream.str();
|
205
|
-
|
206
|
-
// Set up debug font/paints
|
207
|
-
auto font = SkFont();
|
208
|
-
font.setSize(14);
|
209
|
-
auto paint = SkPaint();
|
210
|
-
paint.setColor(SkColors::kRed);
|
211
|
-
jsiCanvas->getCanvas()->drawSimpleText(
|
212
|
-
debugString.c_str(), debugString.size(), SkTextEncoding::kUTF8, 8, 18,
|
213
|
-
font, paint);
|
214
|
-
}
|
215
|
-
}
|
216
|
-
|
217
|
-
void RNSkJsRenderer::drawInJsiCanvas(std::shared_ptr<JsiSkCanvas> jsiCanvas,
|
218
|
-
int width, int height, double time) {
|
219
|
-
|
220
|
-
// Call the draw drawCallback and perform js based drawing
|
221
|
-
auto skCanvas = jsiCanvas->getCanvas();
|
222
|
-
if (_drawCallback != nullptr && skCanvas != nullptr) {
|
223
|
-
// Make sure to scale correctly
|
224
|
-
auto pd = _platformContext->getPixelDensity();
|
225
|
-
skCanvas->clear(SK_ColorTRANSPARENT);
|
226
|
-
skCanvas->save();
|
227
|
-
skCanvas->scale(pd, pd);
|
228
|
-
|
229
|
-
// Call draw function.
|
230
|
-
callJsDrawCallback(jsiCanvas, width / pd, height / pd, time);
|
231
|
-
|
232
|
-
skCanvas->restore();
|
233
|
-
}
|
234
|
-
}
|
235
|
-
|
236
|
-
} // namespace RNSkia
|
package/cpp/rnskia/RNSkJsView.h
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
#pragma once
|
2
|
-
|
3
|
-
#include <functional>
|
4
|
-
#include <memory>
|
5
|
-
#include <mutex>
|
6
|
-
#include <string>
|
7
|
-
#include <unordered_map>
|
8
|
-
#include <vector>
|
9
|
-
|
10
|
-
#include <jsi/jsi.h>
|
11
|
-
|
12
|
-
#include "JsiValueWrapper.h"
|
13
|
-
#include "RNSkView.h"
|
14
|
-
|
15
|
-
#include "JsiSkCanvas.h"
|
16
|
-
#include "RNSkInfoParameter.h"
|
17
|
-
#include "RNSkLog.h"
|
18
|
-
#include "RNSkPlatformContext.h"
|
19
|
-
#include "RNSkTimingInfo.h"
|
20
|
-
|
21
|
-
#pragma clang diagnostic push
|
22
|
-
#pragma clang diagnostic ignored "-Wdocumentation"
|
23
|
-
|
24
|
-
#include "SkBBHFactory.h"
|
25
|
-
#include "SkCanvas.h"
|
26
|
-
#include "SkPictureRecorder.h"
|
27
|
-
|
28
|
-
#pragma clang diagnostic pop
|
29
|
-
|
30
|
-
class SkPicture;
|
31
|
-
class SkRect;
|
32
|
-
class SkImage;
|
33
|
-
|
34
|
-
namespace RNSkia {
|
35
|
-
class JsiSkCanvas;
|
36
|
-
namespace jsi = facebook::jsi;
|
37
|
-
|
38
|
-
class RNSkJsRenderer : public RNSkRenderer,
|
39
|
-
public std::enable_shared_from_this<RNSkJsRenderer> {
|
40
|
-
public:
|
41
|
-
RNSkJsRenderer(std::function<void()> requestRedraw,
|
42
|
-
std::shared_ptr<RNSkPlatformContext> context);
|
43
|
-
|
44
|
-
bool tryRender(std::shared_ptr<RNSkCanvasProvider> canvasProvider) override;
|
45
|
-
|
46
|
-
void
|
47
|
-
renderImmediate(std::shared_ptr<RNSkCanvasProvider> canvasProvider) override;
|
48
|
-
|
49
|
-
void setDrawCallback(std::shared_ptr<jsi::Function> drawCallback);
|
50
|
-
|
51
|
-
std::shared_ptr<RNSkInfoObject> getInfoObject();
|
52
|
-
|
53
|
-
private:
|
54
|
-
void performDraw(std::shared_ptr<RNSkCanvasProvider> canvasProvider);
|
55
|
-
|
56
|
-
void callJsDrawCallback(std::shared_ptr<JsiSkCanvas> jsiCanvas, int width,
|
57
|
-
int height, double timestamp);
|
58
|
-
|
59
|
-
void drawInJsiCanvas(std::shared_ptr<JsiSkCanvas> jsiCanvas, int width,
|
60
|
-
int height, double time);
|
61
|
-
|
62
|
-
std::shared_ptr<RNSkPlatformContext> _platformContext;
|
63
|
-
std::shared_ptr<jsi::Function> _drawCallback;
|
64
|
-
std::shared_ptr<JsiSkCanvas> _jsiCanvas;
|
65
|
-
std::shared_ptr<std::timed_mutex> _jsDrawingLock;
|
66
|
-
std::shared_ptr<std::timed_mutex> _gpuDrawingLock;
|
67
|
-
std::shared_ptr<RNSkInfoObject> _infoObject;
|
68
|
-
RNSkTimingInfo _jsTimingInfo;
|
69
|
-
RNSkTimingInfo _gpuTimingInfo;
|
70
|
-
};
|
71
|
-
|
72
|
-
class RNSkJsView : public RNSkView {
|
73
|
-
public:
|
74
|
-
/**
|
75
|
-
* Constructor
|
76
|
-
*/
|
77
|
-
RNSkJsView(std::shared_ptr<RNSkPlatformContext> context,
|
78
|
-
std::shared_ptr<RNSkCanvasProvider> canvasProvider)
|
79
|
-
: RNSkView(context, canvasProvider,
|
80
|
-
std::make_shared<RNSkJsRenderer>(
|
81
|
-
std::bind(&RNSkJsView::requestRedraw, this), context)) {}
|
82
|
-
|
83
|
-
void updateTouchState(std::vector<RNSkTouchInfo> &touches) override {
|
84
|
-
std::static_pointer_cast<RNSkJsRenderer>(getRenderer())
|
85
|
-
->getInfoObject()
|
86
|
-
->updateTouches(touches);
|
87
|
-
RNSkView::updateTouchState(touches);
|
88
|
-
}
|
89
|
-
|
90
|
-
void setJsiProperties(
|
91
|
-
std::unordered_map<std::string, RNJsi::JsiValueWrapper> &props) override {
|
92
|
-
|
93
|
-
RNSkView::setJsiProperties(props);
|
94
|
-
|
95
|
-
for (auto &prop : props) {
|
96
|
-
if (prop.first == "drawCallback") {
|
97
|
-
if (prop.second.isUndefinedOrNull()) {
|
98
|
-
// Clear drawcallback
|
99
|
-
std::static_pointer_cast<RNSkJsRenderer>(getRenderer())
|
100
|
-
->setDrawCallback(nullptr);
|
101
|
-
requestRedraw();
|
102
|
-
continue;
|
103
|
-
|
104
|
-
} else if (prop.second.getType() !=
|
105
|
-
RNJsi::JsiWrapperValueType::Function) {
|
106
|
-
// We expect a function for the draw callback custom property
|
107
|
-
throw std::runtime_error(
|
108
|
-
"Expected a function for the drawCallback custom property.");
|
109
|
-
}
|
110
|
-
|
111
|
-
// Save callback
|
112
|
-
std::static_pointer_cast<RNSkJsRenderer>(getRenderer())
|
113
|
-
->setDrawCallback(prop.second.getAsFunction());
|
114
|
-
|
115
|
-
// Request redraw
|
116
|
-
requestRedraw();
|
117
|
-
}
|
118
|
-
}
|
119
|
-
}
|
120
|
-
};
|
121
|
-
} // namespace RNSkia
|