Skip to content

Commit d4bf1e1

Browse files
committed
Merge pull request #112 from BJap/pinch_zoom_fix
Fixed methods that use dimensions relative to a given WebElement
2 parents 8666224 + 133c575 commit d4bf1e1

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

src/main/java/io/appium/java_client/AppiumDriver.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,10 @@ public void pinch(WebElement el) {
401401
Dimension dimensions = el.getSize();
402402
Point upperLeft = el.getLocation();
403403
Point center = new Point(upperLeft.getX() + dimensions.getWidth() / 2, upperLeft.getY() + dimensions.getHeight() / 2);
404+
int yOffset = center.getY() - upperLeft.getY();
404405

405-
TouchAction action0 = new TouchAction(this).press(el, center.getX(), center.getY() - 100).moveTo(el).release();
406-
TouchAction action1 = new TouchAction(this).press(el, center.getX(), center.getY() + 100).moveTo(el).release();
406+
TouchAction action0 = new TouchAction(this).press(el, center.getX(), center.getY() - yOffset).moveTo(el).release();
407+
TouchAction action1 = new TouchAction(this).press(el, center.getX(), center.getY() + yOffset).moveTo(el).release();
407408

408409
multiTouch.add(action0).add(action1);
409410

@@ -423,9 +424,18 @@ public void pinch(WebElement el) {
423424
*/
424425
public void pinch(int x, int y) {
425426
MultiTouchAction multiTouch = new MultiTouchAction(this);
427+
428+
int scrHeight = manage().window().getSize().getHeight();
429+
int yOffset = 100;
430+
431+
if (y - 100 < 0) {
432+
yOffset = y;
433+
} else if (y + 100 > scrHeight) {
434+
yOffset = scrHeight - y;
435+
}
426436

427-
TouchAction action0 = new TouchAction(this).press(x, y-100).moveTo(x, y).release();
428-
TouchAction action1 = new TouchAction(this).press(x, y+100).moveTo(x, y).release();
437+
TouchAction action0 = new TouchAction(this).press(x, y - yOffset).moveTo(x, y).release();
438+
TouchAction action1 = new TouchAction(this).press(x, y + yOffset).moveTo(x, y).release();
429439

430440
multiTouch.add(action0).add(action1);
431441

@@ -448,9 +458,10 @@ public void zoom(WebElement el) {
448458
Dimension dimensions = el.getSize();
449459
Point upperLeft = el.getLocation();
450460
Point center = new Point(upperLeft.getX() + dimensions.getWidth() / 2, upperLeft.getY() + dimensions.getHeight() / 2);
461+
int yOffset = center.getY() - upperLeft.getY();
451462

452-
TouchAction action0 = new TouchAction(this).press(el).moveTo(el, center.getX(), center.getY() - 100).release();
453-
TouchAction action1 = new TouchAction(this).press(el).moveTo(el, center.getX(), center.getY() + 100).release();
463+
TouchAction action0 = new TouchAction(this).press(el).moveTo(el, center.getX(), center.getY() - yOffset).release();
464+
TouchAction action1 = new TouchAction(this).press(el).moveTo(el, center.getX(), center.getY() + yOffset).release();
454465

455466
multiTouch.add(action0).add(action1);
456467

@@ -470,9 +481,18 @@ public void zoom(WebElement el) {
470481
*/
471482
public void zoom(int x, int y) {
472483
MultiTouchAction multiTouch = new MultiTouchAction(this);
484+
485+
int scrHeight = manage().window().getSize().getHeight();
486+
int yOffset = 100;
487+
488+
if (y - 100 < 0) {
489+
yOffset = y;
490+
} else if (y + 100 > scrHeight) {
491+
yOffset = scrHeight - y;
492+
}
473493

474-
TouchAction action0 = new TouchAction(this).press(x, y).moveTo(x, y-100).release();
475-
TouchAction action1 = new TouchAction(this).press(x, y).moveTo(x, y+100).release();
494+
TouchAction action0 = new TouchAction(this).press(x, y).moveTo(x, y - yOffset).release();
495+
TouchAction action1 = new TouchAction(this).press(x, y).moveTo(x, y + yOffset).release();
476496

477497
multiTouch.add(action0).add(action1);
478498

0 commit comments

Comments
 (0)