From 56bf3bb4a1ad760b47aaab8bf4fb8a2e9577baba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Wed, 22 Sep 2021 15:30:46 +0800 Subject: [PATCH] Android: implement touch api --- .../doric/shader/GestureContainerNode.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/doric-android/doric/src/main/java/pub/doric/shader/GestureContainerNode.java b/doric-android/doric/src/main/java/pub/doric/shader/GestureContainerNode.java index c0e4663f..bcfc5d77 100644 --- a/doric-android/doric/src/main/java/pub/doric/shader/GestureContainerNode.java +++ b/doric-android/doric/src/main/java/pub/doric/shader/GestureContainerNode.java @@ -52,6 +52,11 @@ public class GestureContainerNode extends StackNode { } } + private String onTouchDown; + private String onTouchMove; + private String onTouchUp; + private String onTouchCancel; + private String onSingleTap; private String onDoubleTap; private String onLongPress; @@ -113,6 +118,30 @@ public class GestureContainerNode extends StackNode { } else { onSwipe = null; } + } else if ("onTouchDown".equals(name)) { + if (prop.isString()) { + onTouchDown = prop.asString().value(); + } else { + onTouchDown = null; + } + } else if ("onTouchMove".equals(name)) { + if (prop.isString()) { + onTouchMove = prop.asString().value(); + } else { + onTouchMove = null; + } + } else if ("onTouchUp".equals(name)) { + if (prop.isString()) { + onTouchUp = prop.asString().value(); + } else { + onTouchUp = null; + } + } else if ("onTouchCancel".equals(name)) { + if (prop.isString()) { + onTouchCancel = prop.asString().value(); + } else { + onTouchCancel = null; + } } else { super.blend(view, name, prop); } @@ -230,13 +259,26 @@ public class GestureContainerNode extends StackNode { @Override public boolean onTouchEvent(MotionEvent event) { // handle touch event conflict when in a scroll view or other similar containers + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: + if (onTouchDown != null) + callJSResponse(onTouchDown, DoricUtils.px2dp(event.getX()), DoricUtils.px2dp(event.getY())); + break; case MotionEvent.ACTION_MOVE: getParent().requestDisallowInterceptTouchEvent(true); + + if (onTouchMove != null) + callJSResponse(onTouchMove, DoricUtils.px2dp(event.getX()), DoricUtils.px2dp(event.getY())); break; case MotionEvent.ACTION_UP: + if (onTouchUp != null) + callJSResponse(onTouchUp, DoricUtils.px2dp(event.getX()), DoricUtils.px2dp(event.getY())); case MotionEvent.ACTION_CANCEL: getParent().requestDisallowInterceptTouchEvent(false); + + if (onTouchCancel != null) + callJSResponse(onTouchCancel, DoricUtils.px2dp(event.getX()), DoricUtils.px2dp(event.getY())); break; }