Skip to content

Commit

Permalink
fix: 尝试修复了操作反馈过慢的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
SamDivine committed May 6, 2019
1 parent 959ad30 commit f2dd2d0
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions WebDriverAgentLib/Commands/FBElementCommands.m
Expand Up @@ -320,8 +320,10 @@ + (NSArray *)routes
CGPoint startPoint = CGPointMake((CGFloat)[request.arguments[@"fromX"] doubleValue], (CGFloat)[request.arguments[@"fromY"] doubleValue]);
CGPoint endPoint = CGPointMake((CGFloat)[request.arguments[@"toX"] doubleValue], (CGFloat)[request.arguments[@"toY"] doubleValue]);
NSTimeInterval duration = [request.arguments[@"duration"] doubleValue];
XCUICoordinate *endCoordinate = [self.class gestureCoordinateWithCoordinate:endPoint application:session.activeApplication shouldApplyOrientationWorkaround:isSDKVersionLessThan(@"11.0")];
XCUICoordinate *startCoordinate = [self.class gestureCoordinateWithCoordinate:startPoint application:session.activeApplication shouldApplyOrientationWorkaround:isSDKVersionLessThan(@"11.0")];
//XCUICoordinate *endCoordinate = [self.class gestureCoordinateWithCoordinate:endPoint application:session.activeApplication shouldApplyOrientationWorkaround:isSDKVersionLessThan(@"11.0")];
//XCUICoordinate *startCoordinate = [self.class gestureCoordinateWithCoordinate:startPoint application:session.activeApplication shouldApplyOrientationWorkaround:isSDKVersionLessThan(@"11.0")];
XCUICoordinate *startCoordinate = [self.class getGlobalCoordinateWithPoint:startPoint application:session.activeApplication shouldApplyOrientationWorkaround:isSDKVersionLessThan(@"11.0")];
XCUICoordinate *endCoordinate = [self.class getGlobalCoordinateWithPoint:endPoint application:session.activeApplication shouldApplyOrientationWorkaround:isSDKVersionLessThan(@"11.0")];
[startCoordinate pressForDuration:duration thenDragToCoordinate:endCoordinate];
return FBResponseWithOK();
}
Expand Down Expand Up @@ -363,12 +365,31 @@ + (NSArray *)routes
return FBResponseWithOK();
}

+ (XCUICoordinate*)getGlobalCoordinateWithPoint:(CGPoint)point application:(XCUIApplication*)application shouldApplyOrientationWorkaround:(BOOL)shouldApplyOrientationWorkaround
{
if (shouldApplyOrientationWorkaround) {
point = FBInvertPointForApplication(point, application.frame.size, application.interfaceOrientation);
}
return [[application coordinateWithNormalizedOffset:CGVectorMake(0.0, 0.0)] coordinateWithOffset:CGVectorMake(point.x, point.y)];
}

+ (id<FBResponsePayload>)customTapWithPoint:(CGPoint)point request:(FBRouteRequest*)request
{
XCUICoordinate *coordinate = [self.class getGlobalCoordinateWithPoint:point application:request.session.activeApplication shouldApplyOrientationWorkaround:isSDKVersionLessThan(@"11.0")];
[coordinate tap];
return FBResponseWithOK();
}


+ (id<FBResponsePayload>)handleTap:(FBRouteRequest *)request
{
FBElementCache *elementCache = request.session.elementCache;
CGPoint tapPoint = CGPointMake((CGFloat)[request.arguments[@"x"] doubleValue], (CGFloat)[request.arguments[@"y"] doubleValue]);
XCUIElement *element = [elementCache elementForUUID:request.parameters[@"uuid"]];
if (nil == element) {
if ([request.parameters[@"uuid"] isEqualToString:@"0"]) {
return [self.class customTapWithPoint:tapPoint request:request];
}
XCUICoordinate *tapCoordinate = [self.class gestureCoordinateWithCoordinate:tapPoint application:request.session.activeApplication shouldApplyOrientationWorkaround:isSDKVersionLessThan(@"11.0")];
[tapCoordinate tap];
} else {
Expand Down

0 comments on commit f2dd2d0

Please sign in to comment.