Skip to content

Commit

Permalink
feat(android): add x/y to ScrollView drag events (#14102)
Browse files Browse the repository at this point in the history
* feat(android): add x/y to ScrollView drag events

* docs

* docs
  • Loading branch information
m1ga authored Oct 17, 2024
1 parent 62e9d4a commit 70073c4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}
Expand All @@ -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.
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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.
Expand Down Expand Up @@ -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);
}

Expand Down
15 changes: 15 additions & 0 deletions apidoc/Titanium/UI/ScrollView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 70073c4

Please sign in to comment.