From f0017f6dcfb7c21da91c3186e220a35fef586db2 Mon Sep 17 00:00:00 2001 From: Michael Gangolf Date: Mon, 2 Sep 2024 21:47:03 +0200 Subject: [PATCH 1/3] feat(android): add x/y to ScrollView drag events --- .../titanium/ui/widget/TiUIScrollView.java | 17 +++++++++++++++++ 1 file changed, 17 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); } From 1c0f7a110d0273ae4147856720aff94c358a2710 Mon Sep 17 00:00:00 2001 From: Michael Gangolf Date: Mon, 7 Oct 2024 19:59:21 +0200 Subject: [PATCH 2/3] docs --- apidoc/Titanium/UI/ScrollView.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/apidoc/Titanium/UI/ScrollView.yml b/apidoc/Titanium/UI/ScrollView.yml index 9121ebabc8d..4a4b69b7d4b 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 @@ -212,7 +220,13 @@ events: Indicates whether scrolling will continue but decelerate, now that the drag gesture has 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: From f2d95f6211a72a55b4419cbd3387a01cd332ae6b Mon Sep 17 00:00:00 2001 From: Michael Gangolf Date: Mon, 7 Oct 2024 20:00:56 +0200 Subject: [PATCH 3/3] docs --- apidoc/Titanium/UI/ScrollView.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/apidoc/Titanium/UI/ScrollView.yml b/apidoc/Titanium/UI/ScrollView.yml index 4a4b69b7d4b..ab0d72c79b9 100644 --- a/apidoc/Titanium/UI/ScrollView.yml +++ b/apidoc/Titanium/UI/ScrollView.yml @@ -220,6 +220,7 @@ events: Indicates whether scrolling will continue but decelerate, now that the drag gesture has 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