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

Support gesture margin for default Scroll #51

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -302,12 +302,34 @@ public boolean pinchOpen(Selector selector, int percent, @RpcOptional Integer sp

@Rpc(description = "Performs a scroll gesture in pixels per second on this object.")
public boolean scroll(
Selector selector, String directionStr, int percent, @RpcOptional Integer speed)
Selector selector,
String directionStr,
int percent,
@RpcOptional Integer speed,
@RpcOptional Integer gestureMargin,
@RpcOptional Integer gestureMarginPercent)
throws SelectorException {
Direction direction = Direction.valueOf(directionStr);
return speed == null
? operate(selector, uiObject2 -> uiObject2.scroll(direction, percent / 100f))
: operate(selector, uiObject2 -> uiObject2.scroll(direction, percent / 100f, speed));
UiObject2 uiObject2 = selector.toUiObject2();
if (uiObject2 == null) {
return false;
}
if (gestureMargin != null) {
Log.i("Setting gesture margin to " + gestureMargin);
uiObject2.setGestureMargin(gestureMargin);
} else if (gestureMarginPercent != null) {
Log.i("Setting gesture margin percentage to " + gestureMarginPercent);
uiObject2.setGestureMarginPercentage(gestureMarginPercent / 100f);
}
try {
if (speed == null) {
return uiObject2.scroll(direction, percent / 100f);
} else {
return uiObject2.scroll(direction, percent / 100f, speed);
}
} finally {
uiObject2.recycle();
}
}

@Rpc(description = "Scrolls to the end of a scrollable layout element.")
Expand Down
Binary file modified snippet_uiautomator/android/app/uiautomator.apk
dshiroma marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
7 changes: 6 additions & 1 deletion snippet_uiautomator/uiobject2.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,12 @@ def __call__(
)
elif percent is not None and not kwargs:
return self._ui.scroll(
self._selector.to_dict(), self._direction, percent, speed
self._selector.to_dict(),
self._direction,
percent,
speed,
self._margin,
self._percent,
)
else:
raise errors.ApiError(
Expand Down