@shopify/react-native-skia 1.4.2 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. package/android/CMakeLists.txt +38 -6
  2. package/android/build.gradle +1 -0
  3. package/android/cpp/jni/include/JniSkiaBaseView.h +0 -3
  4. package/android/cpp/jni/include/JniSkiaDomView.h +0 -6
  5. package/android/cpp/jni/include/JniSkiaPictureView.h +0 -5
  6. package/android/cpp/rnskia-android/RNSkAndroidView.h +0 -20
  7. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +0 -72
  8. package/cpp/rnskia/RNSkDomView.cpp +0 -79
  9. package/cpp/rnskia/RNSkDomView.h +1 -39
  10. package/cpp/rnskia/RNSkPictureView.h +0 -1
  11. package/cpp/rnskia/RNSkView.h +0 -17
  12. package/ios/RNSkia-iOS/SkiaUIView.mm +0 -51
  13. package/lib/commonjs/mock/index.js +0 -1
  14. package/lib/commonjs/mock/index.js.map +1 -1
  15. package/lib/commonjs/renderer/Canvas.d.ts +1 -2
  16. package/lib/commonjs/renderer/Canvas.js +0 -3
  17. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  18. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  19. package/lib/commonjs/views/SkiaBaseWebView.d.ts +2 -11
  20. package/lib/commonjs/views/SkiaBaseWebView.js +3 -31
  21. package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
  22. package/lib/commonjs/views/SkiaDomView.js +0 -12
  23. package/lib/commonjs/views/SkiaDomView.js.map +1 -1
  24. package/lib/commonjs/views/SkiaDomView.web.d.ts +2 -2
  25. package/lib/commonjs/views/SkiaDomView.web.js +1 -6
  26. package/lib/commonjs/views/SkiaDomView.web.js.map +1 -1
  27. package/lib/commonjs/views/SkiaJSDomView.js +0 -12
  28. package/lib/commonjs/views/SkiaJSDomView.js.map +1 -1
  29. package/lib/commonjs/views/index.d.ts +0 -1
  30. package/lib/commonjs/views/index.js +0 -11
  31. package/lib/commonjs/views/index.js.map +1 -1
  32. package/lib/commonjs/views/types.d.ts +0 -26
  33. package/lib/commonjs/views/types.js +0 -8
  34. package/lib/commonjs/views/types.js.map +1 -1
  35. package/lib/module/mock/index.js +0 -1
  36. package/lib/module/mock/index.js.map +1 -1
  37. package/lib/module/renderer/Canvas.d.ts +1 -2
  38. package/lib/module/renderer/Canvas.js +0 -3
  39. package/lib/module/renderer/Canvas.js.map +1 -1
  40. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  41. package/lib/module/views/SkiaBaseWebView.d.ts +2 -11
  42. package/lib/module/views/SkiaBaseWebView.js +3 -31
  43. package/lib/module/views/SkiaBaseWebView.js.map +1 -1
  44. package/lib/module/views/SkiaDomView.js +0 -12
  45. package/lib/module/views/SkiaDomView.js.map +1 -1
  46. package/lib/module/views/SkiaDomView.web.d.ts +2 -2
  47. package/lib/module/views/SkiaDomView.web.js +1 -6
  48. package/lib/module/views/SkiaDomView.web.js.map +1 -1
  49. package/lib/module/views/SkiaJSDomView.js +0 -12
  50. package/lib/module/views/SkiaJSDomView.js.map +1 -1
  51. package/lib/module/views/index.d.ts +0 -1
  52. package/lib/module/views/index.js +0 -1
  53. package/lib/module/views/index.js.map +1 -1
  54. package/lib/module/views/types.d.ts +0 -26
  55. package/lib/module/views/types.js +1 -7
  56. package/lib/module/views/types.js.map +1 -1
  57. package/lib/typescript/lib/commonjs/mock/index.d.ts +0 -1
  58. package/lib/typescript/lib/commonjs/views/SkiaBaseWebView.d.ts +0 -3
  59. package/lib/typescript/lib/commonjs/views/SkiaDomView.web.d.ts +1 -1
  60. package/lib/typescript/lib/commonjs/views/types.d.ts +0 -1
  61. package/lib/typescript/lib/module/mock/index.d.ts +0 -1
  62. package/lib/typescript/lib/module/views/SkiaBaseWebView.d.ts +0 -3
  63. package/lib/typescript/lib/module/views/SkiaDomView.web.d.ts +1 -1
  64. package/lib/typescript/lib/module/views/index.d.ts +0 -1
  65. package/lib/typescript/lib/module/views/types.d.ts +1 -1
  66. package/lib/typescript/src/renderer/Canvas.d.ts +1 -2
  67. package/lib/typescript/src/views/SkiaBaseWebView.d.ts +2 -11
  68. package/lib/typescript/src/views/SkiaDomView.web.d.ts +2 -2
  69. package/lib/typescript/src/views/index.d.ts +0 -1
  70. package/lib/typescript/src/views/types.d.ts +0 -26
  71. package/package.json +1 -1
  72. package/src/mock/index.ts +0 -1
  73. package/src/renderer/Canvas.tsx +1 -5
  74. package/src/renderer/__tests__/setup.tsx +0 -2
  75. package/src/skia/web/JsiSkia.ts +1 -1
  76. package/src/views/SkiaBaseWebView.tsx +5 -42
  77. package/src/views/SkiaDomView.tsx +2 -14
  78. package/src/views/SkiaDomView.web.tsx +2 -9
  79. package/src/views/SkiaJSDomView.tsx +2 -14
  80. package/src/views/index.ts +0 -1
  81. package/src/views/types.ts +0 -32
  82. package/cpp/rnskia/RNSkInfoParameter.h +0 -92
  83. package/lib/commonjs/renderer/__tests__/TouchHandler.spec.d.ts +0 -1
  84. package/lib/commonjs/views/useTouchHandler.d.ts +0 -22
  85. package/lib/commonjs/views/useTouchHandler.js +0 -83
  86. package/lib/commonjs/views/useTouchHandler.js.map +0 -1
  87. package/lib/module/renderer/__tests__/TouchHandler.spec.d.ts +0 -1
  88. package/lib/module/views/useTouchHandler.d.ts +0 -22
  89. package/lib/module/views/useTouchHandler.js +0 -75
  90. package/lib/module/views/useTouchHandler.js.map +0 -1
  91. package/lib/typescript/lib/commonjs/views/useTouchHandler.d.ts +0 -12
  92. package/lib/typescript/lib/module/views/useTouchHandler.d.ts +0 -2
  93. package/lib/typescript/src/renderer/__tests__/TouchHandler.spec.d.ts +0 -1
  94. package/lib/typescript/src/views/useTouchHandler.d.ts +0 -22
  95. package/src/renderer/__tests__/TouchHandler.spec.tsx +0 -113
  96. package/src/views/useTouchHandler.ts +0 -107
@@ -155,10 +155,13 @@ endif()
155
155
  message("-- JSI : " ${JSI_LIB})
156
156
 
157
157
  unset(REACT_LIB CACHE)
158
- if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
158
+ if(${REACT_NATIVE_VERSION} GREATER_EQUAL 76)
159
+ # RN 0.76 packs react_nativemodule_core into ReactAndroid::reactnative
160
+ set (REACT_LIB ReactAndroid::reactnative)
161
+ elseif(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
159
162
  # RN 0.71 distributes prebuilt binaries.
160
163
  set (REACT_LIB ReactAndroid::react_nativemodule_core)
161
- else()
164
+ else()
162
165
  find_library(
163
166
  REACT_LIB
164
167
  react_nativemodule_core
@@ -183,7 +186,10 @@ endif()
183
186
  message("-- FBJNI : " ${FBJNI_LIBRARY})
184
187
 
185
188
  unset(REACTNATIVEJNI_LIB CACHE)
186
- if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
189
+ if(${REACT_NATIVE_VERSION} GREATER_EQUAL 76)
190
+ # RN 0.76 doesn't have reactnativejni
191
+ # DO NOTHING, we'll not link these libraries
192
+ elseif(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
187
193
  # RN 0.71 distributes prebuilt binaries.
188
194
  set (REACTNATIVEJNI_LIB "ReactAndroid::reactnativejni")
189
195
  else()
@@ -197,7 +203,10 @@ endif()
197
203
  message("-- REACTNATIVEJNI : " ${REACTNATIVEJNI_LIB})
198
204
 
199
205
  unset(RUNTIMEEXECUTOR_LIB CACHE)
200
- if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
206
+ if(${REACT_NATIVE_VERSION} GREATER_EQUAL 76)
207
+ # RN 0.76 doesn't have runtimeexecutor
208
+ # DO NOTHING, we'll not link these libraries
209
+ elseif(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
201
210
  # RN 0.71 distributes prebuilt binaries.
202
211
  set (RUNTIMEEXECUTOR_LIB "ReactAndroid::runtimeexecutor")
203
212
  else()
@@ -211,7 +220,10 @@ endif()
211
220
  message("-- RUNTIMEEXECUTOR : " ${RUNTIMEEXECUTOR_LIB})
212
221
 
213
222
  unset(TURBOMODULES_LIB CACHE)
214
- if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
223
+ if(${REACT_NATIVE_VERSION} GREATER_EQUAL 76)
224
+ # RN 0.76 doesn't have turbomodulejsijni
225
+ # DO NOTHING, we'll not link these libraries
226
+ elseif(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
215
227
  # RN 0.71 distributes prebuilt binaries.
216
228
  set (TURBOMODULES_LIB "ReactAndroid::turbomodulejsijni")
217
229
  else()
@@ -227,7 +239,26 @@ message("-- TURBO : " ${TURBOMODULES_LIB})
227
239
  add_definitions(-DREACT_NATIVE_VERSION=${REACT_NATIVE_VERSION})
228
240
 
229
241
  # Link
230
- target_link_libraries(
242
+ if(${REACT_NATIVE_VERSION} GREATER_EQUAL 76)
243
+ target_link_libraries(
244
+ ${PACKAGE_NAME}
245
+ ${LOG_LIB}
246
+ ${REACT_LIB}
247
+ ${FBJNI_LIBRARY}
248
+ ${JSI_LIB}
249
+ ${SKIA_SVG_LIB}
250
+ ${SKIA_SKSHAPER_LIB}
251
+ ${SKIA_SKPARAGRAPH_LIB}
252
+ ${SKIA_SKUNICODE_CORE_LIB}
253
+ ${SKIA_SKUNICODE_ICU_LIB}
254
+ ${SKIA_LIB}
255
+ -ljnigraphics
256
+ -lGLESv2
257
+ -lEGL
258
+ -landroid
259
+ )
260
+ else()
261
+ target_link_libraries(
231
262
  ${PACKAGE_NAME}
232
263
  ${LOG_LIB}
233
264
  ${FBJNI_LIBRARY}
@@ -247,3 +278,4 @@ target_link_libraries(
247
278
  -lEGL
248
279
  -landroid
249
280
  )
281
+ endif()
@@ -201,6 +201,7 @@ android {
201
201
  "**/libreactnativejni.so",
202
202
  "**/libruntimeexecutor.so",
203
203
  "**/libturbomodulejsijni.so",
204
+ "**/libreactnative.so",
204
205
  "META-INF/**"
205
206
  ]
206
207
  }
@@ -29,9 +29,6 @@ public:
29
29
  }
30
30
 
31
31
  protected:
32
- virtual void updateTouchPoints(jni::JArrayDouble touches) {
33
- _skiaAndroidView->updateTouchPoints(touches);
34
- }
35
32
 
36
33
  virtual void surfaceAvailable(jobject surface, int width, int height) {
37
34
  _skiaAndroidView->surfaceAvailable(surface, width, height);
@@ -42,17 +42,11 @@ public:
42
42
  JniSkiaDomView::surfaceSizeChanged),
43
43
  makeNativeMethod("setMode", JniSkiaDomView::setMode),
44
44
  makeNativeMethod("setDebugMode", JniSkiaDomView::setDebugMode),
45
- makeNativeMethod("updateTouchPoints",
46
- JniSkiaDomView::updateTouchPoints),
47
45
  makeNativeMethod("registerView", JniSkiaDomView::registerView),
48
46
  makeNativeMethod("unregisterView", JniSkiaDomView::unregisterView)});
49
47
  }
50
48
 
51
49
  protected:
52
- void updateTouchPoints(jni::JArrayDouble touches) override {
53
- JniSkiaBaseView::updateTouchPoints(touches);
54
- }
55
-
56
50
  void surfaceAvailable(jobject surface, int width, int height) override {
57
51
  JniSkiaBaseView::surfaceAvailable(surface, width, height);
58
52
  }
@@ -43,17 +43,12 @@ public:
43
43
  JniSkiaPictureView::surfaceSizeChanged),
44
44
  makeNativeMethod("setMode", JniSkiaPictureView::setMode),
45
45
  makeNativeMethod("setDebugMode", JniSkiaPictureView::setDebugMode),
46
- makeNativeMethod("updateTouchPoints",
47
- JniSkiaPictureView::updateTouchPoints),
48
46
  makeNativeMethod("registerView", JniSkiaPictureView::registerView),
49
47
  makeNativeMethod("unregisterView",
50
48
  JniSkiaPictureView::unregisterView)});
51
49
  }
52
50
 
53
51
  protected:
54
- void updateTouchPoints(jni::JArrayDouble touches) override {
55
- JniSkiaBaseView::updateTouchPoints(touches);
56
- }
57
52
 
58
53
  void surfaceAvailable(jobject surface, int width, int height) override {
59
54
  JniSkiaBaseView::surfaceAvailable(surface, width, height);
@@ -19,8 +19,6 @@ public:
19
19
 
20
20
  virtual float getPixelDensity() = 0;
21
21
 
22
- virtual void updateTouchPoints(jni::JArrayDouble touches) = 0;
23
-
24
22
  virtual void setMode(std::string mode) = 0;
25
23
 
26
24
  virtual void setShowDebugInfo(bool show) = 0;
@@ -76,24 +74,6 @@ public:
76
74
 
77
75
  void viewDidUnmount() override { T::endDrawingLoop(); }
78
76
 
79
- void updateTouchPoints(jni::JArrayDouble touches) override {
80
- // Create touch points
81
- std::vector<RNSkia::RNSkTouchInfo> points;
82
- auto pin = touches.pin();
83
- auto scale = getPixelDensity();
84
- points.reserve(pin.size() / 5);
85
- for (size_t i = 0; i < pin.size(); i += 5) {
86
- RNSkTouchInfo point;
87
- point.x = pin[i] / scale;
88
- point.y = pin[i + 1] / scale;
89
- point.force = pin[i + 2];
90
- point.type = (RNSkia::RNSkTouchInfo::TouchType)pin[i + 3];
91
- point.id = pin[i + 4];
92
- points.push_back(point);
93
- }
94
- T::updateTouchState(points);
95
- }
96
-
97
77
  std::shared_ptr<RNSkView> getSkiaView() override {
98
78
  return T::shared_from_this();
99
79
  }
@@ -53,76 +53,6 @@ public abstract class SkiaBaseView extends ReactViewGroup implements TextureView
53
53
  mTexture.layout(0, 0, this.getMeasuredWidth(), this.getMeasuredHeight());
54
54
  }
55
55
 
56
- @Override
57
- public boolean onTouchEvent(MotionEvent ev) {
58
- // https://developer.android.com/training/gestures/multi
59
- int action = ev.getActionMasked();
60
-
61
- MotionEvent.PointerCoords r = new MotionEvent.PointerCoords();
62
-
63
- double[] points;
64
-
65
- // If this is a pointer_up/down event we need to handle it a bit specialized
66
- switch (action) {
67
- case MotionEvent.ACTION_POINTER_DOWN:
68
- case MotionEvent.ACTION_POINTER_UP: {
69
- points = new double[5];
70
- int pointerIndex = ev.getActionIndex();
71
- ev.getPointerCoords(pointerIndex, r);
72
- points[0] = r.x;
73
- points[1] = r.y;
74
- points[2] = ev.getPressure(pointerIndex);
75
- points[3] = motionActionToType(action);
76
- points[4] = ev.getPointerId(pointerIndex);
77
-
78
- updateTouchPoints(points);
79
-
80
- break;
81
- }
82
- default: {
83
- // For the rest we can just handle it like expected
84
- int count = ev.getPointerCount();
85
- int pointerIndex = 0;
86
- points = new double[5 * count];
87
- for (int i = 0; i < count; i++) {
88
- ev.getPointerCoords(i, r);
89
- points[pointerIndex++] = r.x;
90
- points[pointerIndex++] = r.y;
91
- points[pointerIndex++] = ev.getPressure(i);
92
- points[pointerIndex++] = motionActionToType(action);
93
- points[pointerIndex++] = ev.getPointerId(i);
94
- }
95
-
96
- updateTouchPoints(points);
97
-
98
- break;
99
- }
100
- }
101
-
102
- return true;
103
- }
104
-
105
- private static int motionActionToType(int action) {
106
- int actionType = 3;
107
- switch (action) {
108
- case MotionEvent.ACTION_DOWN:
109
- case MotionEvent.ACTION_POINTER_DOWN:
110
- actionType = 0;
111
- break;
112
- case MotionEvent.ACTION_MOVE:
113
- actionType = 1;
114
- break;
115
- case MotionEvent.ACTION_UP:
116
- case MotionEvent.ACTION_POINTER_UP:
117
- actionType = 2;
118
- break;
119
- case MotionEvent.ACTION_CANCEL:
120
- actionType = 3;
121
- break;
122
- }
123
- return actionType;
124
- }
125
-
126
56
  @Override
127
57
  public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
128
58
  Log.i(tag, "onSurfaceTextureAvailable " + width + "/" + height);
@@ -172,8 +102,6 @@ public abstract class SkiaBaseView extends ReactViewGroup implements TextureView
172
102
 
173
103
  protected abstract void setDebugMode(boolean show);
174
104
 
175
- protected abstract void updateTouchPoints(double[] points);
176
-
177
105
  protected abstract void registerView(int nativeId);
178
106
 
179
107
  protected abstract void unregisterView();
@@ -17,7 +17,6 @@ RNSkDomRenderer::RNSkDomRenderer(std::function<void()> requestRedraw,
17
17
  std::shared_ptr<RNSkPlatformContext> context)
18
18
  : RNSkRenderer(requestRedraw), _platformContext(std::move(context)),
19
19
  _renderLock(std::make_shared<std::timed_mutex>()),
20
- _touchCallbackLock(std::make_shared<std::timed_mutex>()),
21
20
  _renderTimingInfo("SKIA/RENDER") {}
22
21
 
23
22
  RNSkDomRenderer::~RNSkDomRenderer() {
@@ -29,10 +28,6 @@ RNSkDomRenderer::~RNSkDomRenderer() {
29
28
 
30
29
  bool RNSkDomRenderer::tryRender(
31
30
  std::shared_ptr<RNSkCanvasProvider> canvasProvider) {
32
- // If we have touches we need to call the touch callback as well
33
- if (_currentTouches.size() > 0) {
34
- callOnTouch();
35
- }
36
31
 
37
32
  // We render on the main thread
38
33
  if (_renderLock->try_lock()) {
@@ -70,11 +65,6 @@ void RNSkDomRenderer::setRoot(std::shared_ptr<JsiDomRenderNode> node) {
70
65
  _root = node;
71
66
  }
72
67
 
73
- void RNSkDomRenderer::setOnTouchCallback(
74
- std::shared_ptr<jsi::Function> onTouchCallback) {
75
- _touchCallback = onTouchCallback;
76
- }
77
-
78
68
  void RNSkDomRenderer::renderCanvas(SkCanvas *canvas, float scaledWidth,
79
69
  float scaledHeight) {
80
70
  _renderTimingInfo.beginTiming();
@@ -125,75 +115,6 @@ void RNSkDomRenderer::renderCanvas(SkCanvas *canvas, float scaledWidth,
125
115
  _renderTimingInfo.stopTiming();
126
116
  }
127
117
 
128
- void RNSkDomRenderer::updateTouches(std::vector<RNSkTouchInfo> &touches) {
129
- std::lock_guard<std::mutex> lock(_touchMutex);
130
- // Add timestamp
131
- auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
132
- std::chrono::system_clock::now().time_since_epoch())
133
- .count();
134
-
135
- for (size_t i = 0; i < touches.size(); i++) {
136
- touches.at(i).timestamp = ms;
137
- }
138
- _currentTouches.push_back(std::move(touches));
139
- }
140
-
141
- void RNSkDomRenderer::callOnTouch() {
142
-
143
- if (_touchCallback == nullptr) {
144
- return;
145
- }
146
-
147
- if (_touchCallbackLock->try_lock()) {
148
-
149
- {
150
- std::lock_guard<std::mutex> lock(_touchMutex);
151
- _touchesCache.clear();
152
- _touchesCache.reserve(_currentTouches.size());
153
- for (size_t i = 0; i < _currentTouches.size(); ++i) {
154
- _touchesCache.push_back(_currentTouches.at(i));
155
- }
156
- _currentTouches.clear();
157
- }
158
-
159
- // We have an onDraw method - use it to render since we don't have a
160
- // DOM-node yet.
161
- _platformContext->runOnJavascriptThread([weakSelf = weak_from_this()]() {
162
- auto self = weakSelf.lock();
163
- if (self) {
164
- jsi::Runtime &runtime = *self->_platformContext->getJsRuntime();
165
- // Set up touches
166
- auto size = self->_touchesCache.size();
167
- auto ops = jsi::Array(runtime, size);
168
- for (size_t i = 0; i < size; i++) {
169
- auto cur = self->_touchesCache.at(i);
170
- auto curSize = cur.size();
171
- auto touches = jsi::Array(runtime, curSize);
172
- for (size_t n = 0; n < curSize; n++) {
173
- auto touchObj = jsi::Object(runtime);
174
- auto t = cur.at(n);
175
- touchObj.setProperty(runtime, "x", t.x);
176
- touchObj.setProperty(runtime, "y", t.y);
177
- touchObj.setProperty(runtime, "force", t.force);
178
- touchObj.setProperty(runtime, "type", static_cast<double>(t.type));
179
- touchObj.setProperty(runtime, "timestamp",
180
- static_cast<double>(t.timestamp) / 1000.0);
181
- touchObj.setProperty(runtime, "id", static_cast<double>(t.id));
182
- touches.setValueAtIndex(runtime, n, touchObj);
183
- }
184
- ops.setValueAtIndex(runtime, i, touches);
185
- }
186
- // Call on touch callback
187
- self->_touchCallback->call(runtime, ops, 1);
188
- }
189
- self->_touchCallbackLock->unlock();
190
- });
191
- } else {
192
- // We'll try next time - schedule a new redraw
193
- _requestRedraw();
194
- }
195
- }
196
-
197
118
  void RNSkDomRenderer::renderDebugOverlays(SkCanvas *canvas) {
198
119
  if (!getShowDebugOverlays()) {
199
120
  return;
@@ -13,7 +13,6 @@
13
13
  #include "RNSkView.h"
14
14
 
15
15
  #include "JsiDomRenderNode.h"
16
- #include "RNSkInfoParameter.h"
17
16
  #include "RNSkLog.h"
18
17
  #include "RNSkPlatformContext.h"
19
18
  #include "RNSkTimingInfo.h"
@@ -50,29 +49,19 @@ public:
50
49
 
51
50
  void setRoot(std::shared_ptr<JsiDomRenderNode> node);
52
51
 
53
- void setOnTouchCallback(std::shared_ptr<jsi::Function> onTouchCallback);
54
-
55
- void updateTouches(std::vector<RNSkTouchInfo> &touches);
56
-
57
52
  private:
58
- void callOnTouch();
59
53
  void renderCanvas(SkCanvas *canvas, float scaledWidth, float scaledHeight);
60
54
  void renderDebugOverlays(SkCanvas *canvas);
61
55
 
62
56
  std::shared_ptr<RNSkPlatformContext> _platformContext;
63
- std::shared_ptr<jsi::Function> _touchCallback;
64
57
 
65
58
  std::shared_ptr<std::timed_mutex> _renderLock;
66
- std::shared_ptr<std::timed_mutex> _touchCallbackLock;
67
59
 
68
60
  std::shared_ptr<JsiDomRenderNode> _root;
69
61
  std::shared_ptr<DrawingContext> _drawingContext;
70
62
 
71
63
  RNSkTimingInfo _renderTimingInfo;
72
64
 
73
- std::mutex _touchMutex;
74
- std::vector<std::vector<RNSkTouchInfo>> _currentTouches;
75
- std::vector<std::vector<RNSkTouchInfo>> _touchesCache;
76
65
  std::mutex _rootLock;
77
66
  };
78
67
 
@@ -87,40 +76,13 @@ public:
87
76
  std::make_shared<RNSkDomRenderer>(
88
77
  std::bind(&RNSkView::requestRedraw, this), context)) {}
89
78
 
90
- void updateTouchState(std::vector<RNSkTouchInfo> &touches) override {
91
- std::static_pointer_cast<RNSkDomRenderer>(getRenderer())
92
- ->updateTouches(touches);
93
- RNSkView::updateTouchState(touches);
94
- }
95
-
96
79
  void setJsiProperties(
97
80
  std::unordered_map<std::string, JsiValueWrapper> &props) override {
98
81
 
99
82
  RNSkView::setJsiProperties(props);
100
83
 
101
84
  for (auto &prop : props) {
102
- if (prop.first == "onTouch") {
103
- if (prop.second.isUndefinedOrNull()) {
104
- // Clear touchCallback
105
- std::static_pointer_cast<RNSkDomRenderer>(getRenderer())
106
- ->setOnTouchCallback(nullptr);
107
- requestRedraw();
108
- continue;
109
-
110
- } else if (prop.second.getType() != JsiWrapperValueType::Function) {
111
- // We expect a function for the draw callback custom property
112
- throw std::runtime_error(
113
- "Expected a function for the onTouch property.");
114
- }
115
-
116
- // Save callback
117
- std::static_pointer_cast<RNSkDomRenderer>(getRenderer())
118
- ->setOnTouchCallback(prop.second.getAsFunction());
119
-
120
- // Request redraw
121
- requestRedraw();
122
-
123
- } else if (prop.first == "root") {
85
+ if (prop.first == "root") {
124
86
  // Save root
125
87
  if (prop.second.isUndefined() || prop.second.isNull()) {
126
88
  std::static_pointer_cast<RNSkDomRenderer>(getRenderer())
@@ -13,7 +13,6 @@
13
13
  #include "RNSkView.h"
14
14
 
15
15
  #include "JsiSkPicture.h"
16
- #include "RNSkInfoParameter.h"
17
16
  #include "RNSkLog.h"
18
17
  #include "RNSkPlatformContext.h"
19
18
  #include "RNSkTimingInfo.h"
@@ -138,16 +138,6 @@ private:
138
138
 
139
139
  enum RNSkDrawingMode { Default, Continuous };
140
140
 
141
- using RNSkTouchInfo = struct {
142
- enum TouchType { Start, Active, End, Cancelled };
143
- double x;
144
- double y;
145
- double force;
146
- TouchType type;
147
- size_t id;
148
- long timestamp;
149
- };
150
-
151
141
  class RNSkView : public std::enable_shared_from_this<RNSkView> {
152
142
  public:
153
143
  /**
@@ -218,13 +208,6 @@ public:
218
208
  requestRedraw();
219
209
  }
220
210
 
221
- /**
222
- Update touch state with new touch points
223
- */
224
- virtual void updateTouchState(std::vector<RNSkTouchInfo> &) {
225
- requestRedraw();
226
- }
227
-
228
211
  /**
229
212
  Renders the view into an SkImage instead of the screen.
230
213
  */
@@ -177,55 +177,4 @@
177
177
  return _impl;
178
178
  }
179
179
 
180
- #pragma mark Touch handling
181
-
182
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
183
- [self handleTouches:touches withEvent:event];
184
- }
185
-
186
- - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
187
- [self handleTouches:touches withEvent:event];
188
- }
189
-
190
- - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
191
- [self handleTouches:touches withEvent:event];
192
- }
193
-
194
- - (void)handleTouches:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
195
- if (event.type == UIEventTypeTouches) {
196
- std::vector<RNSkia::RNSkTouchInfo> nextTouches;
197
- for (UITouch *touch in touches) {
198
- auto position = [touch preciseLocationInView:self];
199
- RNSkia::RNSkTouchInfo nextTouch;
200
- nextTouch.x = position.x;
201
- nextTouch.y = position.y;
202
- nextTouch.force = [touch force];
203
- nextTouch.id = [touch hash];
204
- auto phase = [touch phase];
205
- switch (phase) {
206
- case UITouchPhaseBegan:
207
- nextTouch.type = RNSkia::RNSkTouchInfo::TouchType::Start;
208
- break;
209
- case UITouchPhaseMoved:
210
- nextTouch.type = RNSkia::RNSkTouchInfo::TouchType::Active;
211
- break;
212
- case UITouchPhaseEnded:
213
- nextTouch.type = RNSkia::RNSkTouchInfo::TouchType::End;
214
- break;
215
- case UITouchPhaseCancelled:
216
- nextTouch.type = RNSkia::RNSkTouchInfo::TouchType::Cancelled;
217
- break;
218
- default:
219
- nextTouch.type = RNSkia::RNSkTouchInfo::TouchType::Active;
220
- break;
221
- }
222
-
223
- nextTouches.push_back(nextTouch);
224
- }
225
- if (_impl != nullptr) {
226
- _impl->getDrawView()->updateTouchState(nextTouches);
227
- }
228
- }
229
- }
230
-
231
180
  @end
@@ -32,7 +32,6 @@ const Mock = CanvasKit => {
32
32
  // Skia Animations
33
33
  useValue: NoopValue,
34
34
  useComputedValue: NoopValue,
35
- useTouchHandler: Noop,
36
35
  useTiming: NoopValue,
37
36
  useLoop: NoopValue,
38
37
  useSpring: NoopValue,
@@ -1 +1 @@
1
- {"version":3,"names":["_web","require","Noop","undefined","NoopValue","current","NoopSharedValue","value","Mock","CanvasKit","global","SkiaApi","JsiSkApi","Skia","Canvas","useValue","useComputedValue","useTouchHandler","useTiming","useLoop","useSpring","useClockValue","useValueEffect","useClock","usePathInterpolation","useImageAsTexture","useTextureValue","useTextureValueFromPicture","useRSXformBuffer","usePointBuffer","useColorBuffer","useRectBuffer","useBuffer","useRawData","useData","useFont","Font","useFonts","useTypeface","useImage","useSVG","useVideo","exports"],"sources":["index.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport { JsiSkApi } from \"../skia/web\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst Noop: () => any = () => undefined;\nconst NoopValue = () => ({ current: 0 });\nconst NoopSharedValue = () => ({ value: 0 });\n\nexport const Mock = (CanvasKit: CanvasKit) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n global.SkiaApi = JsiSkApi(CanvasKit);\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const Skia = global.SkiaApi;\n return {\n Skia,\n ...require(\"../renderer/components\"),\n ...require(\"../skia\"),\n ...require(\"../animation\"),\n ...require(\"../dom/types\"),\n ...require(\"../dom/nodes\"),\n // We could use the real Canvas if we mock the SkiaView component for node\n Canvas: Noop,\n // Skia Animations\n useValue: NoopValue,\n useComputedValue: NoopValue,\n useTouchHandler: Noop,\n useTiming: NoopValue,\n useLoop: NoopValue,\n useSpring: NoopValue,\n useClockValue: NoopValue,\n useValueEffect: Noop,\n // Reanimated hooks\n useClock: NoopSharedValue,\n usePathInterpolation: NoopSharedValue,\n useImageAsTexture: NoopSharedValue,\n useTextureValue: NoopSharedValue,\n useTextureValueFromPicture: NoopSharedValue,\n useRSXformBuffer: NoopSharedValue,\n usePointBuffer: NoopSharedValue,\n useColorBuffer: NoopSharedValue,\n useRectBuffer: NoopSharedValue,\n useBuffer: NoopSharedValue,\n useRawData: Noop,\n useData: Noop,\n useFont: () => Skia.Font(undefined, 0),\n useFonts: Noop,\n useTypeface: () => null,\n useImage: () => null,\n useSVG: () => null,\n useVideo: () => null,\n };\n};\n"],"mappings":";;;;;;AAEA,IAAAA,IAAA,GAAAC,OAAA;AAEA;AACA,MAAMC,IAAe,GAAGA,CAAA,KAAMC,SAAS;AACvC,MAAMC,SAAS,GAAGA,CAAA,MAAO;EAAEC,OAAO,EAAE;AAAE,CAAC,CAAC;AACxC,MAAMC,eAAe,GAAGA,CAAA,MAAO;EAAEC,KAAK,EAAE;AAAE,CAAC,CAAC;AAErC,MAAMC,IAAI,GAAIC,SAAoB,IAAK;EAC5C;EACA;EACAC,MAAM,CAACC,OAAO,GAAG,IAAAC,aAAQ,EAACH,S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AA,IAAA","ignoreList":[]}
1
+ {"version":3,"names":["_web","require","Noop","undefined","NoopValue","current","NoopSharedValue","value","Mock","CanvasKit","global","SkiaApi","JsiSkApi","Skia","Canvas","useValue","useComputedValue","useTiming","useLoop","useSpring","useClockValue","useValueEffect","useClock","usePathInterpolation","useImageAsTexture","useTextureValue","useTextureValueFromPicture","useRSXformBuffer","usePointBuffer","useColorBuffer","useRectBuffer","useBuffer","useRawData","useData","useFont","Font","useFonts","useTypeface","useImage","useSVG","useVideo","exports"],"sources":["index.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport { JsiSkApi } from \"../skia/web\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst Noop: () => any = () => undefined;\nconst NoopValue = () => ({ current: 0 });\nconst NoopSharedValue = () => ({ value: 0 });\n\nexport const Mock = (CanvasKit: CanvasKit) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n global.SkiaApi = JsiSkApi(CanvasKit);\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const Skia = global.SkiaApi;\n return {\n Skia,\n ...require(\"../renderer/components\"),\n ...require(\"../skia\"),\n ...require(\"../animation\"),\n ...require(\"../dom/types\"),\n ...require(\"../dom/nodes\"),\n // We could use the real Canvas if we mock the SkiaView component for node\n Canvas: Noop,\n // Skia Animations\n useValue: NoopValue,\n useComputedValue: NoopValue,\n useTiming: NoopValue,\n useLoop: NoopValue,\n useSpring: NoopValue,\n useClockValue: NoopValue,\n useValueEffect: Noop,\n // Reanimated hooks\n useClock: NoopSharedValue,\n usePathInterpolation: NoopSharedValue,\n useImageAsTexture: NoopSharedValue,\n useTextureValue: NoopSharedValue,\n useTextureValueFromPicture: NoopSharedValue,\n useRSXformBuffer: NoopSharedValue,\n usePointBuffer: NoopSharedValue,\n useColorBuffer: NoopSharedValue,\n useRectBuffer: NoopSharedValue,\n useBuffer: NoopSharedValue,\n useRawData: Noop,\n useData: Noop,\n useFont: () => Skia.Font(undefined, 0),\n useFonts: Noop,\n useTypeface: () => null,\n useImage: () => null,\n useSVG: () => null,\n useVideo: () => null,\n };\n};\n"],"mappings":";;;;;;AAEA,IAAAA,IAAA,GAAAC,OAAA;AAEA;AACA,MAAMC,IAAe,GAAGA,CAAA,KAAMC,SAAS;AACvC,MAAMC,SAAS,GAAGA,CAAA,MAAO;EAAEC,OAAO,EAAE;AAAE,CAAC,CAAC;AACxC,MAAMC,eAAe,GAAGA,CAAA,MAAO;EAAEC,KAAK,EAAE;AAAE,CAAC,CAAC;AAErC,MAAMC,IAAI,GAAIC,SAAoB,IAAK;EAC5C;EACA;EACAC,MAAM,CAACC,OAAO,GAAG,IAAAC,aAAQ,EAACH,SAAS,CAAC;EACpC;EACA;EACA,MAAMI,IAAI,GAAGH,MAAM,CAACC,OAAO;EAC3B,OAAO;IACLE,IAAI;IACJ,GAAGZ,OAAO,CAAC,wBAAwB,CAAC;IACpC,GAAGA,OAAO,CAAC,SAAS,CAAC;IACrB,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1B,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1B,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1B;IACAa,MAAM,EAAEZ,IAAI;IACZ;IACAa,QAAQ,EAAEX,SAAS;IACnBY,gBAAgB,EAAEZ,SAAS;IAC3Ba,SAAS,EAAEb,SAAS;IACpBc,OAAO,EAAEd,SAAS;IAClBe,SAAS,EAAEf,SAAS;IACpBgB,aAAa,EAAEhB,SAAS;IACxBiB,cAAc,EAAEnB,IAAI;IACpB;IACAoB,QAAQ,EAAEhB,eAAe;IACzBiB,oBAAoB,EAAEjB,eAAe;IACrCkB,iBAAiB,EAAElB,eAAe;IAClCmB,eAAe,EAAEnB,eAAe;IAChCoB,0BAA0B,EAAEpB,eAAe;IAC3CqB,gBAAgB,EAAErB,eAAe;IACjCsB,cAAc,EAAEtB,eAAe;IAC/BuB,cAAc,EAAEvB,eAAe;IAC/BwB,aAAa,EAAExB,eAAe;IAC9ByB,SAAS,EAAEzB,eAAe;IAC1B0B,UAAU,EAAE9B,IAAI;IAChB+B,OAAO,EAAE/B,IAAI;IACbgC,OAAO,EAAEA,CAAA,KAAMrB,IAAI,CAACsB,IAAI,CAAChC,SAAS,EAAE,CAAC,CAAC;IACtCiC,QAAQ,EAAElC,IAAI;IACdmC,WAAW,EAAEA,CAAA,KAAM,IAAI;IACvBC,QAAQ,EAAEA,CAAA,KAAM,IAAI;IACpBC,MAAM,EAAEA,CAAA,KAAM,IAAI;IAClBC,QAAQ,EAAEA,CAAA,KAAM;EAClB,CAAC;AACH,CAAC;AAACC,OAAA,CAAAjC,IAAA,GAAAA,IAAA","ignoreList":[]}
@@ -1,11 +1,10 @@
1
1
  import React from "react";
2
2
  import type { RefObject, ReactNode, FunctionComponent } from "react";
3
3
  import { SkiaDomView } from "../views";
4
- import type { TouchHandler, SkiaBaseViewProps } from "../views";
4
+ import type { SkiaBaseViewProps } from "../views";
5
5
  export declare const useCanvasRef: () => React.RefObject<SkiaDomView>;
6
6
  export interface CanvasProps extends SkiaBaseViewProps {
7
7
  ref?: RefObject<SkiaDomView>;
8
8
  children: ReactNode;
9
- onTouch?: TouchHandler;
10
9
  }
11
10
  export declare const Canvas: FunctionComponent<CanvasProps & React.RefAttributes<SkiaDomView>>;
@@ -37,7 +37,6 @@ const Canvas = exports.Canvas = /*#__PURE__*/(0, _react.forwardRef)(({
37
37
  style,
38
38
  debug,
39
39
  mode,
40
- onTouch,
41
40
  onSize: _onSize,
42
41
  onLayout: _onLayout,
43
42
  ...props
@@ -70,7 +69,6 @@ const Canvas = exports.Canvas = /*#__PURE__*/(0, _react.forwardRef)(({
70
69
  ref: ref,
71
70
  style: style,
72
71
  root: root.dom,
73
- onTouch: onTouch,
74
72
  onLayout: onLayout,
75
73
  mode: mode,
76
74
  debug: debug
@@ -83,7 +81,6 @@ const Canvas = exports.Canvas = /*#__PURE__*/(0, _react.forwardRef)(({
83
81
  ref: ref,
84
82
  style: style,
85
83
  root: root.dom,
86
- onTouch: onTouch,
87
84
  onLayout: onLayout,
88
85
  mode: mode,
89
86
  debug: debug
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_views","_Skia","_SkiaJSDomView","_Reconciler","_HostComponents","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","_extends","assign","bind","arguments","length","apply","useCanvasRef","useRef","exports","useOnSizeEvent","resultValue","onLayout","useCallback","event","width","height","nativeEvent","layout","value","Canvas","forwardRef","children","style","debug","mode","onTouch","onSize","_onSize","_onLayout","props","forwardedRef","innerRef","ref","useCombinedRefs","redraw","_innerRef$current","current","getNativeId","_innerRef$current$nat","_innerRef$current2","id","nativeId","root","useMemo","SkiaRoot","Skia","NATIVE_DOM","useEffect","render","unmount","createElement","SkiaDomView","dom","SkiaJSDomView","refs","targetRef","React","forEach"],"sources":["Canvas.tsx"],"sourcesContent":["import React, {\n useEffect,\n useCallback,\n useMemo,\n forwardRef,\n useRef,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n MutableRefObject,\n ForwardedRef,\n FunctionComponent,\n} from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\n\nimport { SkiaDomView } from \"../views\";\nimport { Skia } from \"../skia/Skia\";\nimport type { TouchHandler, SkiaBaseViewProps } from \"../views\";\nimport { SkiaJSDomView } from \"../views/SkiaJSDomView\";\n\nimport { SkiaRoot } from \"./Reconciler\";\nimport { NATIVE_DOM } from \"./HostComponents\";\n\nexport const useCanvasRef = () => useRef<SkiaDomView>(null);\n\nexport interface CanvasProps extends SkiaBaseViewProps {\n ref?: RefObject<SkiaDomView>;\n children: ReactNode;\n onTouch?: TouchHandler;\n}\n\nconst useOnSizeEvent = (\n resultValue: SkiaBaseViewProps[\"onSize\"],\n onLayout?: (event: LayoutChangeEvent) => void\n) => {\n return useCallback(\n (event: LayoutChangeEvent) => {\n if (onLayout) {\n onLayout(event);\n }\n const { width, height } = event.nativeEvent.layout;\n\n if (resultValue) {\n resultValue.value = { width, height };\n }\n },\n [onLayout, resultValue]\n );\n};\n\nexport const Canvas = forwardRef<SkiaDomView, CanvasProps>(\n (\n {\n children,\n style,\n debug,\n mode,\n onTouch,\n onSize: _onSize,\n onLayout: _onLayout,\n ...props\n },\n forwardedRef\n ) => {\n const onLayout = useOnSizeEvent(_onSize, _onLayout);\n const innerRef = useCanvasRef();\n const ref = useCombinedRefs(forwardedRef, innerRef);\n const redraw = useCallback(() => {\n innerRef.current?.redraw();\n }, [innerRef]);\n const getNativeId = useCallback(() => {\n const id = innerRef.current?.nativeId ?? -1;\n return id;\n }, [innerRef]);\n\n const root = useMemo(\n () => new SkiaRoot(Skia, NATIVE_DOM, redraw, getNativeId),\n [redraw, getNativeId]\n );\n\n // Render effect\n useEffect(() => {\n root.render(children);\n }, [children, root, redraw]);\n\n useEffect(() => {\n return () => {\n root.unmount();\n };\n }, [root]);\n\n if (NATIVE_DOM) {\n return (\n <SkiaDomView\n ref={ref}\n style={style}\n root={root.dom}\n onTouch={onTouch}\n onLayout={onLayout}\n mode={mode}\n debug={debug}\n {...props}\n />\n );\n } else {\n return (\n <SkiaJSDomView\n Skia={Skia}\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ref={ref as any}\n style={style}\n root={root.dom}\n onTouch={onTouch}\n onLayout={onLayout}\n mode={mode}\n debug={debug}\n {...props}\n />\n );\n }\n }\n) as FunctionComponent<CanvasProps & React.RefAttributes<SkiaDomView>>;\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) {\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AAE,CAACkB,IAAI,CAAC,CAAC;EACV,OAAOC,SAAS;AAClB,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_views","_Skia","_SkiaJSDomView","_Reconciler","_HostComponents","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","_extends","assign","bind","arguments","length","apply","useCanvasRef","useRef","exports","useOnSizeEvent","resultValue","onLayout","useCallback","event","width","height","nativeEvent","layout","value","Canvas","forwardRef","children","style","debug","mode","onSize","_onSize","_onLayout","props","forwardedRef","innerRef","ref","useCombinedRefs","redraw","_innerRef$current","current","getNativeId","_innerRef$current$nat","_innerRef$current2","id","nativeId","root","useMemo","SkiaRoot","Skia","NATIVE_DOM","useEffect","render","unmount","createElement","SkiaDomView","dom","SkiaJSDomView","refs","targetRef","React","forEach"],"sources":["Canvas.tsx"],"sourcesContent":["import React, {\n useEffect,\n useCallback,\n useMemo,\n forwardRef,\n useRef,\n} from \"react\";\nimport type {\n RefObject,\n ReactNode,\n MutableRefObject,\n ForwardedRef,\n FunctionComponent,\n} from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\n\nimport { SkiaDomView } from \"../views\";\nimport { Skia } from \"../skia/Skia\";\nimport type { SkiaBaseViewProps } from \"../views\";\nimport { SkiaJSDomView } from \"../views/SkiaJSDomView\";\n\nimport { SkiaRoot } from \"./Reconciler\";\nimport { NATIVE_DOM } from \"./HostComponents\";\n\nexport const useCanvasRef = () => useRef<SkiaDomView>(null);\n\nexport interface CanvasProps extends SkiaBaseViewProps {\n ref?: RefObject<SkiaDomView>;\n children: ReactNode;\n}\n\nconst useOnSizeEvent = (\n resultValue: SkiaBaseViewProps[\"onSize\"],\n onLayout?: (event: LayoutChangeEvent) => void\n) => {\n return useCallback(\n (event: LayoutChangeEvent) => {\n if (onLayout) {\n onLayout(event);\n }\n const { width, height } = event.nativeEvent.layout;\n\n if (resultValue) {\n resultValue.value = { width, height };\n }\n },\n [onLayout, resultValue]\n );\n};\n\nexport const Canvas = forwardRef<SkiaDomView, CanvasProps>(\n (\n {\n children,\n style,\n debug,\n mode,\n onSize: _onSize,\n onLayout: _onLayout,\n ...props\n },\n forwardedRef\n ) => {\n const onLayout = useOnSizeEvent(_onSize, _onLayout);\n const innerRef = useCanvasRef();\n const ref = useCombinedRefs(forwardedRef, innerRef);\n const redraw = useCallback(() => {\n innerRef.current?.redraw();\n }, [innerRef]);\n const getNativeId = useCallback(() => {\n const id = innerRef.current?.nativeId ?? -1;\n return id;\n }, [innerRef]);\n\n const root = useMemo(\n () => new SkiaRoot(Skia, NATIVE_DOM, redraw, getNativeId),\n [redraw, getNativeId]\n );\n\n // Render effect\n useEffect(() => {\n root.render(children);\n }, [children, root, redraw]);\n\n useEffect(() => {\n return () => {\n root.unmount();\n };\n }, [root]);\n\n if (NATIVE_DOM) {\n return (\n <SkiaDomView\n ref={ref}\n style={style}\n root={root.dom}\n onLayout={onLayout}\n mode={mode}\n debug={debug}\n {...props}\n />\n );\n } else {\n return (\n <SkiaJSDomView\n Skia={Skia}\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ref={ref as any}\n style={style}\n root={root.dom}\n onLayout={onLayout}\n mode={mode}\n debug={debug}\n {...props}\n />\n );\n }\n }\n) as FunctionComponent<CanvasProps & React.RefAttributes<SkiaDomView>>;\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":";;;;;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