Skip to content
This repository has been archived by the owner on Dec 26, 2019. It is now read-only.

Support different gestures in landscape mode #411

Closed
wants to merge 25 commits into from
Closed

Support different gestures in landscape mode #411

wants to merge 25 commits into from

Conversation

mykola-mokhnach
Copy link
Contributor

Fixes #362

@@ -58,6 +59,8 @@ + (NSArray *)routes
[[FBRoute POST:@"/uiaElement/:uuid/twoFingerTap"] respondWithTarget:self action:@selector(handleTwoFingerTap:)],
[[FBRoute POST:@"/uiaElement/:uuid/touchAndHold"] respondWithTarget:self action:@selector(handleTouchAndHold:)],
[[FBRoute POST:@"/uiaElement/:uuid/scroll"] respondWithTarget:self action:@selector(handleScroll:)],
[[FBRoute POST:@"/dragfromtoforduration"] respondWithTarget:self action:@selector(handleDrag:)],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you not use different endpoint something like /wda/dragfromtoforduration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have just created it based on existing API methods examples, like "/touchAndHold" and "/doubleTap". Shouldn't we follow the same template there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are legacy stuff, that should die.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok then I will use wda/ prefix as you suggested

@@ -58,6 +59,8 @@ + (NSArray *)routes
[[FBRoute POST:@"/uiaElement/:uuid/twoFingerTap"] respondWithTarget:self action:@selector(handleTwoFingerTap:)],
[[FBRoute POST:@"/uiaElement/:uuid/touchAndHold"] respondWithTarget:self action:@selector(handleTouchAndHold:)],
[[FBRoute POST:@"/uiaElement/:uuid/scroll"] respondWithTarget:self action:@selector(handleScroll:)],
[[FBRoute POST:@"/dragfromtoforduration"] respondWithTarget:self action:@selector(handleDrag:)],
// TODO: remove obsolete endpoint
[[FBRoute POST:@"/uiaTarget/:uuid/dragfromtoforduration"] respondWithTarget:self action:@selector(handleDrag:)],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should split those handler. I don't like that we try to handle both cases in one handle and being smart about element presence.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no pb - I will implement both methods

CGSize FBAdjustDimensionsForApplication(CGSize actualSize, UIInterfaceOrientation orientation)
{
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
if (actualSize.height > actualSize.width) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XCTest bug is, that it returns exchanged dimensions for landscape mode. This verification is just to make sure the bug is still there (since height is never greater than width in landscape) and to make it still working properly after XCTest itself starts to respect landscape.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you and comment on that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

XCUICoordinate *gestureCoordinate = [[XCUICoordinate alloc] initWithCoordinate:appCoordinate pointsOffset:point];
return gestureCoordinate;
// TODO: handle this properly after XCTest starts to respect landscape interface orientation
CGPoint point = FBInvertPointForApplication(coordinate, application.frame.size, application.interfaceOrientation);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. You should check for iOS version here as well.
  2. Instead of forcing those checks everywhere, you might want to consider adding FBUICoordinate class and patch coordinates on the go?

Copy link
Contributor Author

@mykola-mokhnach mykola-mokhnach Dec 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check for iOS version here as well.

This might be a bad idea, because you never know whether given coordinates were calculated based on some element position or just based on the actual screen size. I would prefer to keep it like this, because this is generic method and only have such verification for methods, where we explicitly calculate offset based on element location (like tap)

Copy link
Contributor Author

@mykola-mokhnach mykola-mokhnach Dec 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Instead of forcing those checks everywhere, you might want to consider adding FBUICoordinate class and patch coordinates on the go?

I think this might be too complicated. There are many places where you can read these coordinates (wdRect, wdFrame). Plus these a widely used for internal calculations and we need to cover the case, that iOS9.3 properly calculates them

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but all versions checks etc, would happen in that class. So final product would be "transparent" for all clients. All of them should expect correct values anyway. Only problem would be argument you made in first point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it simple. Most of users don't even use 20% of features we have here. I could think about improving this if there are enough complains in Appium forum. But for now it might take a lot of time to just create a workaround for the stuff, which is not widely used. And time is money 💯

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also noticed one more thing, that is not going to be resolved if we just transform element coordinates. All the methods of XCUIElement, like doubleTap, pinch, etc will still fail in landscape. We anyway need to replace them with something, that does the same action by coordinates (actually, this is what you've already done for click) :-(

Copy link
Contributor

@marekcirkos marekcirkos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, however I think we can do much better.

@marekcirkos
Copy link
Contributor

I am sorry @mykola-mokhnach, I will not be able to merge this before Christmas. There are few things I would like do differently, but I wouldn't have time to sit to properly.

@codeskyblue
Copy link

@marekcirkos Any progress on this pr?

Copy link
Contributor

@marekcirkos marekcirkos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, Let's get done with it :).

@param relativeCoordinate hit point coordinate relative to the current element position
@return YES if the operation succeeds, otherwise NO.
*/
- (BOOL)fb_tapCoordinateWithError:(NSError **)error relativeCoordinate:(CGPoint)relativeCoordinate;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error parameter should be last.

- (BOOL)fb_tapAtRelativeCoordinate:(CGPoint)relativeCoordinate error:(NSError **)error;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

CGPoint hitPoint = hitpointValue ? hitpointValue.CGPointValue : [self coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.5)].screenPoint;
hitPoint = FBInvertPointForApplication(hitPoint, self.application.frame.size, self.application.interfaceOrientation);
CGPoint hitPoint = CGPointMake(self.frame.origin.x + relativeCoordinate.x, self.frame.origin.y + relativeCoordinate.y);
// TODO: Change that after XCTest starts to respect landscape orientation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of todo I would add comment why this is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added detailed comment

@@ -206,7 +208,8 @@ + (NSArray *)routes

+ (id<FBResponsePayload>)handleDoubleTapCoordinate:(FBRouteRequest *)request
{
XCUICoordinate *doubleTapCoordinate = [self.class getGestureCoordinate:request];
CGPoint doubleTapPoint = CGPointMake((CGFloat)[request.arguments[@"x"] doubleValue], (CGFloat)[request.arguments[@"y"] doubleValue]);
XCUICoordinate *doubleTapCoordinate = [self.class gestureCoordinateWithCoordinate:doubleTapPoint application:request.session.application shouldApplyOrientationWorkaround:YES];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you always apply changes here without iOS check? Would it be better to make iOS check inside that method?

Copy link
Contributor Author

@mykola-mokhnach mykola-mokhnach Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, please ignore my recent comment. This is done, because in iOS 9.3 drag coordinates are also inverted. So the current implementation works properly if one provides absolute coordinates based on the actual screen width/height, but will not work if relative coordinates based on some element position are provided. I think the first case is more relevant for such method call. If one wanted to have a thing that performs drag on element by its relative coordinates, then he would create some other method (something like tap for clicking). But the method above only accepts absolute coordinates

@imurchie what is your opinion on it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to summarise what we know:

  1. On iOS 9.x coordinates are not inverted
  2. On iOS 10.x coordinates are inverted
  3. We can assume that coordinates passed by user are correct (meaning they are in reference to current orientation). This is mainly because we give them the coordinates or they manually calculate them.
    Is that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. On iOS 9.x coordinates are not inverted

Yes, but only coordinates we get when we want to know XCUIElement frame. All the other XCUIElement methods have the same bug as in 10.0+

On iOS 10.x coordinates are inverted

Yes, but this might be fixed in any of upcoming iOS releases.

  1. We can assume that coordinates passed by user are correct (meaning they are in reference to current orientation). This is mainly because we give them the coordinates or they manually calculate them.

I want to discuss this point with @imurchie, because most of WDA calls where we do operations with absolute screen coordinates cannot be invoked directly from Appium, but rather via TouchAction interface. And we need to be in sync about our expectations here.

@marekcirkos
Copy link
Contributor

@mykola-mokhnach is it ready for review or we are waiting for @imurchie?

@mykola-mokhnach
Copy link
Contributor Author

Yes, this is ready from my side. I just want @imurchie to take a final look at this PR, because he was working on TouchAction interface in Appium, which, actually, is the main consumer of fixed WDA API methods.

@imurchie
Copy link
Contributor

Looks good to me! This will be awesome to get in!

@mykola-mokhnach
Copy link
Contributor Author

Hi @marekcirkos
Can you please initiate marge procedure for this PR? I'd like to create another PR for visibility fi, but it uses some stuff from this one.

XCUICoordinate *appCoordinate = [[XCUICoordinate alloc] initWithElement:session.application normalizedOffset:CGVectorMake(0, 0)];
XCUICoordinate *endCoordinate = [[XCUICoordinate alloc] initWithCoordinate:appCoordinate pointsOffset:endPoint];
XCUICoordinate *startCoordinate = [[XCUICoordinate alloc] initWithCoordinate:appCoordinate pointsOffset:startPoint];
BOOL shouldApplyOrientationWorkaround = SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we care about iOS version if we are handling coordinates there that are always buggy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we calculate coordinates based on element's position, which is calculated properly for iOS 9.3 and is broken for iOS10.0+
In other cases coordinates are passed as absolute values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's do this then!

@facebook-github-bot
Copy link

@marekcirkos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@mykola-mokhnach mykola-mokhnach deleted the landscape_tap branch August 14, 2017 12:01
imurchie referenced this pull request in appium/WebDriverAgent Nov 16, 2017
dpgraham pushed a commit to dpgraham/appium-ios that referenced this pull request Sep 9, 2020
Summary:
Fixes facebookarchive/WebDriverAgent#362
Closes facebookarchive/WebDriverAgent#411

Differential Revision: D4461734

Pulled By: marekcirkos

fbshipit-source-id: b388682e70d11a498e6a5fa8eb33172514371dab
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants