Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): add x/y to ScrollView drag events #14102

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading