Skip to content

Commit d2b5e8b

Browse files
authored
feat(🔥): Remove deprecated onTouch prop (#2669)
1 parent fe24c03 commit d2b5e8b

File tree

22 files changed

+16
-682
lines changed

22 files changed

+16
-682
lines changed

‎packages/skia/android/cpp/jni/include/JniSkiaBaseView.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ class JniSkiaBaseView {
2929
}
3030

3131
protected:
32-
virtual void updateTouchPoints(jni::JArrayDouble touches) {
33-
_skiaAndroidView->updateTouchPoints(touches);
34-
}
3532

3633
virtual void surfaceAvailable(jobject surface, int width, int height) {
3734
_skiaAndroidView->surfaceAvailable(surface, width, height);

‎packages/skia/android/cpp/jni/include/JniSkiaDomView.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,11 @@ class JniSkiaDomView : public jni::HybridClass<JniSkiaDomView>,
4242
JniSkiaDomView::surfaceSizeChanged),
4343
makeNativeMethod("setMode", JniSkiaDomView::setMode),
4444
makeNativeMethod("setDebugMode", JniSkiaDomView::setDebugMode),
45-
makeNativeMethod("updateTouchPoints",
46-
JniSkiaDomView::updateTouchPoints),
4745
makeNativeMethod("registerView", JniSkiaDomView::registerView),
4846
makeNativeMethod("unregisterView", JniSkiaDomView::unregisterView)});
4947
}
5048

5149
protected:
52-
void updateTouchPoints(jni::JArrayDouble touches) override {
53-
JniSkiaBaseView::updateTouchPoints(touches);
54-
}
55-
5650
void surfaceAvailable(jobject surface, int width, int height) override {
5751
JniSkiaBaseView::surfaceAvailable(surface, width, height);
5852
}

‎packages/skia/android/cpp/jni/include/JniSkiaPictureView.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,12 @@ class JniSkiaPictureView : public jni::HybridClass<JniSkiaPictureView>,
4343
JniSkiaPictureView::surfaceSizeChanged),
4444
makeNativeMethod("setMode", JniSkiaPictureView::setMode),
4545
makeNativeMethod("setDebugMode", JniSkiaPictureView::setDebugMode),
46-
makeNativeMethod("updateTouchPoints",
47-
JniSkiaPictureView::updateTouchPoints),
4846
makeNativeMethod("registerView", JniSkiaPictureView::registerView),
4947
makeNativeMethod("unregisterView",
5048
JniSkiaPictureView::unregisterView)});
5149
}
5250

5351
protected:
54-
void updateTouchPoints(jni::JArrayDouble touches) override {
55-
JniSkiaBaseView::updateTouchPoints(touches);
56-
}
5752

5853
void surfaceAvailable(jobject surface, int width, int height) override {
5954
JniSkiaBaseView::surfaceAvailable(surface, width, height);

‎packages/skia/android/cpp/rnskia-android/RNSkAndroidView.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ class RNSkBaseAndroidView {
1919

2020
virtual float getPixelDensity() = 0;
2121

22-
virtual void updateTouchPoints(jni::JArrayDouble touches) = 0;
23-
2422
virtual void setMode(std::string mode) = 0;
2523

2624
virtual void setShowDebugInfo(bool show) = 0;
@@ -76,24 +74,6 @@ class RNSkAndroidView : public T, public RNSkBaseAndroidView {
7674

7775
void viewDidUnmount() override { T::endDrawingLoop(); }
7876

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-
9777
std::shared_ptr<RNSkView> getSkiaView() override {
9878
return T::shared_from_this();
9979
}

‎packages/skia/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -53,76 +53,6 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
5353
mTexture.layout(0, 0, this.getMeasuredWidth(), this.getMeasuredHeight());
5454
}
5555

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-
12656
@Override
12757
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
12858
Log.i(tag, "onSurfaceTextureAvailable " + width + "/" + height);
@@ -172,8 +102,6 @@ public void onSurfaceTextureUpdated(SurfaceTexture surface) {
172102

173103
protected abstract void setDebugMode(boolean show);
174104

175-
protected abstract void updateTouchPoints(double[] points);
176-
177105
protected abstract void registerView(int nativeId);
178106

179107
protected abstract void unregisterView();

‎packages/skia/cpp/rnskia/RNSkDomView.cpp

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ RNSkDomRenderer::RNSkDomRenderer(std::function<void()> requestRedraw,
1717
std::shared_ptr<RNSkPlatformContext> context)
1818
: RNSkRenderer(requestRedraw), _platformContext(std::move(context)),
1919
_renderLock(std::make_shared<std::timed_mutex>()),
20-
_touchCallbackLock(std::make_shared<std::timed_mutex>()),
2120
_renderTimingInfo("SKIA/RENDER") {}
2221

2322
RNSkDomRenderer::~RNSkDomRenderer() {
@@ -29,10 +28,6 @@ RNSkDomRenderer::~RNSkDomRenderer() {
2928

3029
bool RNSkDomRenderer::tryRender(
3130
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-
}
3631

3732
// We render on the main thread
3833
if (_renderLock->try_lock()) {
@@ -70,11 +65,6 @@ void RNSkDomRenderer::setRoot(std::shared_ptr<JsiDomRenderNode> node) {
7065
_root = node;
7166
}
7267

73-
void RNSkDomRenderer::setOnTouchCallback(
74-
std::shared_ptr<jsi::Function> onTouchCallback) {
75-
_touchCallback = onTouchCallback;
76-
}
77-
7868
void RNSkDomRenderer::renderCanvas(SkCanvas *canvas, float scaledWidth,
7969
float scaledHeight) {
8070
_renderTimingInfo.beginTiming();
@@ -125,75 +115,6 @@ void RNSkDomRenderer::renderCanvas(SkCanvas *canvas, float scaledWidth,
125115
_renderTimingInfo.stopTiming();
126116
}
127117

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-
197118
void RNSkDomRenderer::renderDebugOverlays(SkCanvas *canvas) {
198119
if (!getShowDebugOverlays()) {
199120
return;

‎packages/skia/cpp/rnskia/RNSkDomView.h

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,19 @@ class RNSkDomRenderer : public RNSkRenderer,
5050

5151
void setRoot(std::shared_ptr<JsiDomRenderNode> node);
5252

53-
void setOnTouchCallback(std::shared_ptr<jsi::Function> onTouchCallback);
54-
55-
void updateTouches(std::vector<RNSkTouchInfo> &touches);
56-
5753
private:
58-
void callOnTouch();
5954
void renderCanvas(SkCanvas *canvas, float scaledWidth, float scaledHeight);
6055
void renderDebugOverlays(SkCanvas *canvas);
6156

6257
std::shared_ptr<RNSkPlatformContext> _platformContext;
63-
std::shared_ptr<jsi::Function> _touchCallback;
6458

6559
std::shared_ptr<std::timed_mutex> _renderLock;
66-
std::shared_ptr<std::timed_mutex> _touchCallbackLock;
6760

6861
std::shared_ptr<JsiDomRenderNode> _root;
6962
std::shared_ptr<DrawingContext> _drawingContext;
7063

7164
RNSkTimingInfo _renderTimingInfo;
7265

73-
std::mutex _touchMutex;
74-
std::vector<std::vector<RNSkTouchInfo>> _currentTouches;
75-
std::vector<std::vector<RNSkTouchInfo>> _touchesCache;
7666
std::mutex _rootLock;
7767
};
7868

@@ -87,40 +77,13 @@ class RNSkDomView : public RNSkView {
8777
std::make_shared<RNSkDomRenderer>(
8878
std::bind(&RNSkView::requestRedraw, this), context)) {}
8979

90-
void updateTouchState(std::vector<RNSkTouchInfo> &touches) override {
91-
std::static_pointer_cast<RNSkDomRenderer>(getRenderer())
92-
->updateTouches(touches);
93-
RNSkView::updateTouchState(touches);
94-
}
95-
9680
void setJsiProperties(
9781
std::unordered_map<std::string, JsiValueWrapper> &props) override {
9882

9983
RNSkView::setJsiProperties(props);
10084

10185
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") {
86+
if (prop.first == "root") {
12487
// Save root
12588
if (prop.second.isUndefined() || prop.second.isNull()) {
12689
std::static_pointer_cast<RNSkDomRenderer>(getRenderer())

0 commit comments

Comments
 (0)