From 70073c425c72d7e3a62ed2bb749c896b0cff832b Mon Sep 17 00:00:00 2001 From: Michael Gangolf Date: Thu, 17 Oct 2024 19:04:33 +0200 Subject: [PATCH] feat(android): add x/y to ScrollView drag events (#14102) * feat(android): add x/y to ScrollView drag events * docs * docs --- .../titanium/ui/widget/TiUIScrollView.java | 17 +++++++++++++++++ apidoc/Titanium/UI/ScrollView.yml | 15 +++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIScrollView.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIScrollView.java index 4dded6d0761..7dc6474ab45 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIScrollView.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIScrollView.java @@ -53,6 +53,8 @@ public class TiUIScrollView extends TiUIView private static int verticalAttrId = -1; private static int horizontalAttrId = -1; private int type; + private TiDimension xDimension; + private TiDimension yDimension; public class TiScrollViewLayout extends TiCompositeLayout { @@ -405,6 +407,9 @@ public TiScrollViewLayout getLayout() @Override public boolean onTouchEvent(MotionEvent event) { + xDimension = new TiDimension((double) event.getX(), TiDimension.TYPE_LEFT); + yDimension = new TiDimension((double) event.getY(), TiDimension.TYPE_TOP); + if (event.getAction() == MotionEvent.ACTION_MOVE && !mScrollingEnabled) { return false; } @@ -416,6 +421,9 @@ public boolean onTouchEvent(MotionEvent event) isTouching = false; KrollDict data = new KrollDict(); data.put("decelerate", true); + + data.put(TiC.EVENT_PROPERTY_X, xDimension.getAsDefault(scrollView)); + data.put(TiC.EVENT_PROPERTY_Y, yDimension.getAsDefault(scrollView)); getProxy().fireEvent(TiC.EVENT_DRAGEND, data); } //There's a known Android bug (version 3.1 and above) that will throw an exception when we use 3+ fingers to touch the scrollview. @@ -475,6 +483,8 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt) if (!isScrolling && isTouching) { isScrolling = true; KrollDict data = new KrollDict(); + data.put(TiC.EVENT_PROPERTY_X, xDimension.getAsDefault(scrollView)); + data.put(TiC.EVENT_PROPERTY_Y, yDimension.getAsDefault(scrollView)); getProxy().fireEvent(TiC.EVENT_DRAGSTART, data); } @@ -553,6 +563,9 @@ public TiScrollViewLayout getLayout() @Override public boolean onTouchEvent(MotionEvent event) { + xDimension = new TiDimension((double) event.getX(), TiDimension.TYPE_LEFT); + yDimension = new TiDimension((double) event.getY(), TiDimension.TYPE_TOP); + if (event.getAction() == MotionEvent.ACTION_MOVE && !mScrollingEnabled) { return false; } @@ -564,6 +577,8 @@ public boolean onTouchEvent(MotionEvent event) isTouching = false; KrollDict data = new KrollDict(); data.put("decelerate", true); + data.put(TiC.EVENT_PROPERTY_X, xDimension.getAsDefault(scrollView)); + data.put(TiC.EVENT_PROPERTY_Y, yDimension.getAsDefault(scrollView)); getProxy().fireEvent(TiC.EVENT_DRAGEND, data); } //There's a known Android bug (version 3.1 and above) that will throw an exception when we use 3+ fingers to touch the scrollview. @@ -603,6 +618,8 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt) if (!isScrolling && isTouching) { isScrolling = true; + data.put(TiC.EVENT_PROPERTY_X, xDimension.getAsDefault(scrollView)); + data.put(TiC.EVENT_PROPERTY_Y, yDimension.getAsDefault(scrollView)); getProxy().fireEvent(TiC.EVENT_DRAGSTART, data); } diff --git a/apidoc/Titanium/UI/ScrollView.yml b/apidoc/Titanium/UI/ScrollView.yml index 9121ebabc8d..ab0d72c79b9 100644 --- a/apidoc/Titanium/UI/ScrollView.yml +++ b/apidoc/Titanium/UI/ScrollView.yml @@ -198,6 +198,14 @@ events: A dragging gesture is when a touch remains in contact with the display to physically drag the view, as opposed to it being the result of scrolling momentum. platforms: [android, iphone, ipad, macos] + properties: + - name: x + summary: X coordinate from the scrollable touch position. + type: Number + + - name: y + summary: Y coordinate from the scrollable touch position. + type: Number since: { iphone: "3.0.0", ipad: "3.0.0", android: "6.2.0" } - name: dragend @@ -213,6 +221,13 @@ events: been released by the touch. If `false`, scrolling will stop immediately. Is always `true` on Android. type: Boolean + - name: x + summary: X coordinate from the scrollable touch position. + type: Number + + - name: y + summary: Y coordinate from the scrollable touch position. + type: Number since: { iphone: "3.0.0", ipad: "3.0.0", android: "6.2.0" } properties: