@shopify/react-native-skia 1.4.2 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +38 -6
- package/android/build.gradle +1 -0
- package/android/cpp/jni/include/JniSkiaBaseView.h +0 -4
- package/android/cpp/jni/include/JniSkiaDomView.h +0 -6
- package/android/cpp/jni/include/JniSkiaPictureView.h +0 -6
- package/android/cpp/rnskia-android/RNSkAndroidView.h +0 -20
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +0 -72
- package/cpp/rnskia/RNSkDomView.cpp +0 -79
- package/cpp/rnskia/RNSkDomView.h +1 -39
- package/cpp/rnskia/RNSkPictureView.h +0 -1
- package/cpp/rnskia/RNSkView.h +0 -17
- package/ios/RNSkia-iOS/DisplayLink.mm +7 -0
- package/ios/RNSkia-iOS/SkiaUIView.mm +0 -51
- package/lib/commonjs/mock/index.js +0 -1
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.d.ts +1 -2
- package/lib/commonjs/renderer/Canvas.js +0 -3
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/views/SkiaBaseWebView.d.ts +2 -11
- package/lib/commonjs/views/SkiaBaseWebView.js +3 -31
- package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
- package/lib/commonjs/views/SkiaDomView.js +0 -12
- package/lib/commonjs/views/SkiaDomView.js.map +1 -1
- package/lib/commonjs/views/SkiaDomView.web.d.ts +2 -2
- package/lib/commonjs/views/SkiaDomView.web.js +1 -6
- package/lib/commonjs/views/SkiaDomView.web.js.map +1 -1
- package/lib/commonjs/views/SkiaJSDomView.js +0 -12
- package/lib/commonjs/views/SkiaJSDomView.js.map +1 -1
- package/lib/commonjs/views/index.d.ts +0 -1
- package/lib/commonjs/views/index.js +0 -11
- package/lib/commonjs/views/index.js.map +1 -1
- package/lib/commonjs/views/types.d.ts +0 -26
- package/lib/commonjs/views/types.js +0 -8
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/commonjs/web/WithSkiaWeb.js +4 -1
- package/lib/commonjs/web/WithSkiaWeb.js.map +1 -1
- package/lib/module/mock/index.js +0 -1
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +1 -2
- package/lib/module/renderer/Canvas.js +0 -3
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/views/SkiaBaseWebView.d.ts +2 -11
- package/lib/module/views/SkiaBaseWebView.js +3 -31
- package/lib/module/views/SkiaBaseWebView.js.map +1 -1
- package/lib/module/views/SkiaDomView.js +0 -12
- package/lib/module/views/SkiaDomView.js.map +1 -1
- package/lib/module/views/SkiaDomView.web.d.ts +2 -2
- package/lib/module/views/SkiaDomView.web.js +1 -6
- package/lib/module/views/SkiaDomView.web.js.map +1 -1
- package/lib/module/views/SkiaJSDomView.js +0 -12
- package/lib/module/views/SkiaJSDomView.js.map +1 -1
- package/lib/module/views/index.d.ts +0 -1
- package/lib/module/views/index.js +0 -1
- package/lib/module/views/index.js.map +1 -1
- package/lib/module/views/types.d.ts +0 -26
- package/lib/module/views/types.js +1 -7
- package/lib/module/views/types.js.map +1 -1
- package/lib/module/web/WithSkiaWeb.js +4 -1
- package/lib/module/web/WithSkiaWeb.js.map +1 -1
- package/lib/typescript/lib/commonjs/mock/index.d.ts +0 -1
- package/lib/typescript/lib/commonjs/views/SkiaBaseWebView.d.ts +0 -3
- package/lib/typescript/lib/commonjs/views/SkiaDomView.web.d.ts +1 -1
- package/lib/typescript/lib/commonjs/views/types.d.ts +0 -1
- package/lib/typescript/lib/module/mock/index.d.ts +0 -1
- package/lib/typescript/lib/module/views/SkiaBaseWebView.d.ts +0 -3
- package/lib/typescript/lib/module/views/SkiaDomView.web.d.ts +1 -1
- package/lib/typescript/lib/module/views/index.d.ts +0 -1
- package/lib/typescript/lib/module/views/types.d.ts +1 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +1 -2
- package/lib/typescript/src/views/SkiaBaseWebView.d.ts +2 -11
- package/lib/typescript/src/views/SkiaDomView.web.d.ts +2 -2
- package/lib/typescript/src/views/index.d.ts +0 -1
- package/lib/typescript/src/views/types.d.ts +0 -26
- 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/Info.plist +5 -5
- 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/libskparagraph.xcframework/Info.plist +5 -5
- 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/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/libskunicode_core.xcframework/ios-arm64_arm64e/libskunicode_core.a +0 -0
- package/libs/ios/libskunicode_core.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode_core.a +0 -0
- package/libs/ios/libskunicode_libgrapheme.xcframework/ios-arm64_arm64e/libskunicode_libgrapheme.a +0 -0
- package/libs/ios/libskunicode_libgrapheme.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode_libgrapheme.a +0 -0
- package/libs/ios/libsvg.xcframework/Info.plist +5 -5
- 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 +3 -6
- package/src/mock/index.ts +0 -1
- package/src/renderer/Canvas.tsx +1 -5
- package/src/renderer/__tests__/setup.tsx +0 -2
- package/src/skia/web/JsiSkia.ts +1 -1
- package/src/views/SkiaBaseWebView.tsx +5 -42
- package/src/views/SkiaDomView.tsx +2 -14
- package/src/views/SkiaDomView.web.tsx +2 -9
- package/src/views/SkiaJSDomView.tsx +2 -14
- package/src/views/index.ts +0 -1
- package/src/views/types.ts +0 -32
- package/src/web/WithSkiaWeb.tsx +3 -1
- package/cpp/rnskia/RNSkInfoParameter.h +0 -92
- package/lib/commonjs/renderer/__tests__/TouchHandler.spec.d.ts +0 -1
- package/lib/commonjs/views/useTouchHandler.d.ts +0 -22
- package/lib/commonjs/views/useTouchHandler.js +0 -83
- package/lib/commonjs/views/useTouchHandler.js.map +0 -1
- package/lib/module/renderer/__tests__/TouchHandler.spec.d.ts +0 -1
- package/lib/module/views/useTouchHandler.d.ts +0 -22
- package/lib/module/views/useTouchHandler.js +0 -75
- package/lib/module/views/useTouchHandler.js.map +0 -1
- package/lib/typescript/lib/commonjs/views/useTouchHandler.d.ts +0 -12
- package/lib/typescript/lib/module/views/useTouchHandler.d.ts +0 -2
- package/lib/typescript/src/renderer/__tests__/TouchHandler.spec.d.ts +0 -1
- package/lib/typescript/src/views/useTouchHandler.d.ts +0 -22
- package/src/renderer/__tests__/TouchHandler.spec.tsx +0 -113
- package/src/views/useTouchHandler.ts +0 -107
package/android/CMakeLists.txt
CHANGED
@@ -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
|
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
|
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
|
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
|
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
|
-
|
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()
|
package/android/build.gradle
CHANGED
@@ -29,10 +29,6 @@ public:
|
|
29
29
|
}
|
30
30
|
|
31
31
|
protected:
|
32
|
-
virtual void updateTouchPoints(jni::JArrayDouble touches) {
|
33
|
-
_skiaAndroidView->updateTouchPoints(touches);
|
34
|
-
}
|
35
|
-
|
36
32
|
virtual void surfaceAvailable(jobject surface, int width, int height) {
|
37
33
|
_skiaAndroidView->surfaceAvailable(surface, width, height);
|
38
34
|
}
|
@@ -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,18 +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
|
-
|
58
52
|
void surfaceAvailable(jobject surface, int width, int height) override {
|
59
53
|
JniSkiaBaseView::surfaceAvailable(surface, width, height);
|
60
54
|
}
|
@@ -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;
|
package/cpp/rnskia/RNSkDomView.h
CHANGED
@@ -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 == "
|
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())
|
package/cpp/rnskia/RNSkView.h
CHANGED
@@ -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
|
*/
|
@@ -10,6 +10,13 @@
|
|
10
10
|
_displayLink = [CADisplayLink displayLinkWithTarget:self
|
11
11
|
selector:@selector(update:)];
|
12
12
|
|
13
|
+
if (@available(iOS 15.0, *)) {
|
14
|
+
CAFrameRateRange rate = CAFrameRateRangeMake(60, 120, 120);
|
15
|
+
_displayLink.preferredFrameRateRange = rate;
|
16
|
+
} else {
|
17
|
+
_displayLink.preferredFramesPerSecond = 60;
|
18
|
+
}
|
19
|
+
|
13
20
|
// add the display link to the main run loop
|
14
21
|
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop]
|
15
22
|
forMode:NSRunLoopCommonModes];
|
@@ -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
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_web","require","Noop","undefined","NoopValue","current","NoopSharedValue","value","Mock","CanvasKit","global","SkiaApi","JsiSkApi","Skia","Canvas","useValue","useComputedValue","
|
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 {
|
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
|