Skip to content

Commit

Permalink
Internal Commit Uploaded
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 463388614
  • Loading branch information
mobile-devx-github-bot committed Jul 26, 2022
1 parent 60a7805 commit 1a054d7
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 9 deletions.
15 changes: 15 additions & 0 deletions AppFramework/Action/GREYPathGestureUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ NSArray<NSValue *> *GREYTouchPathForGestureInView(UIView *view, CGPoint startPoi
GREYDirection direction, CGFloat length,
CGFloat *outRemainingAmountOrNull);

/**
* Generates a touch path in the given @c view from @c startPoint to @c endPoint in view-relative
* coordinates.
*
* @param window The window in which the touch path is generated.
* @param startPointInWindowCoordinates The start point in screen coordinates.
* @param endPointInWindowCoordinates The end point in screen coordinates.
* @param duration How long the gesture should last (in seconds).
*
* @return NSArray of CGPoints that denote the points in the touch path.
*/
NSArray<NSValue *> *GREYTouchPathForGestureBetweenPoints(CGPoint startPointInScreenCoordinates,
CGPoint endPointInScreenCoordinates,
CFTimeInterval duration);

/**
* Generates a touch path in the @c window from the given @c startPoint and the given @c
* endPoint.
Expand Down
6 changes: 6 additions & 0 deletions AppFramework/Action/GREYPathGestureUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
return GREYGenerateTouchPath(startPointInWindowCoordinates, endPointInWindowCoords, duration, NO);
}

NSArray<NSValue *> *GREYTouchPathForGestureBetweenPoints(CGPoint startPointInWindowCoordinates,
CGPoint endPointInWindowCoordinates,
CFTimeInterval duration) {
return GREYGenerateTouchPath(startPointInWindowCoordinates, endPointInWindowCoords, duration, NO);
}

NSArray<NSValue *> *GREYTouchPathForDragGestureInScreen(CGPoint startPoint, CGPoint endPoint,
BOOL cancelInertia) {
return GREYGenerateTouchPath(startPoint, endPoint, NAN, cancelInertia);
Expand Down
27 changes: 25 additions & 2 deletions AppFramework/Action/GREYSwipeAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
*
* @param direction The direction of the swipe.
* @param duration The time interval for which the swipe takes place.
* @param startPercents @c startPercents.x sets the value of the x-coordinate of the start point
* by interpolating between left(for 0.0) and right(for 1.0) edge similarly
* @param startPercents @c startPercents.x sets the value of the x coordinate of the start point
* by interpolating between left(for 0.0) and right(for 1.0) edge. Similarly,
* @c startPercents.y determines the y coordinate.
*
* @return An instance of GREYSwipeAction, initialized with the provided direction, duration
Expand All @@ -62,4 +62,27 @@
- (instancetype)initWithDirection:(GREYDirection)direction
duration:(CFTimeInterval)duration
startPercents:(CGPoint)startPercents;

/**
* Performs a swipe in the given @c direction in the given @c duration. The start of the swipe is
* specified by @c startPercents. The end of the swipe is specified by @c endPercents. Because
* swipes must begin inside the element and not on the edge of it, the values in @c startPercents
* must be in the range (0,1) exclusive. All coordinates are relative to the element's visible
* area on-screen (accessibility frame).
*
* @param direction The direction of the swipe.
* @param duration The time interval for which the swipe takes place.
* @param startPercents @c startPercents.x sets the value of the x coordinate of the start point
* by interpolating between left(for 0.0) and right(for 1.0) edge. Similarly,
* @c startPercents.y determines the y coordinate.
* @param endPercents @c endPercents.x sets the value of the x coordinate of the end point
* by interpolating between left(for 0.0) and right(for 1.0) edge. Similarly,
* @c endPercents.y determines the y coordinate.
*
* @return An instance of GREYSwipeAction, initialized with the provided direction, duration
* and information for the start point.
*/
- (instancetype)initWithDuration:(CFTimeInterval)duration
startPercents:(CGPoint)startPercents
endPercents:(CGPoint)startPercents;
@end
46 changes: 39 additions & 7 deletions AppFramework/Action/GREYSwipeAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,25 @@ @implementation GREYSwipeAction {
* Start point for the swipe specified as percentage of swipped element's accessibility frame.
*/
CGPoint _startPercents;
/**
* Start point for the swipe specified as percentage of swipped element's accessibility frame.
*/
CGPoint _endPercents;
/**
* YES if end point is specified, else NO.
*/
BOOL _endPointSpecified;
}

- (instancetype)initWithDirection:(GREYDirection)direction
duration:(CFTimeInterval)duration
percentPoint:(CGPoint)percents {
GREYThrowOnFailedConditionWithMessage(percents.x > 0.0f && percents.x < 1.0f,
startPercentPoint:(CGPoint)startPercents
endPercentPoint:(CGPoint)percents
endPointSpecified:(BOOL)endPointSpecified {
GREYThrowOnFailedConditionWithMessage(startPercents.x > 0.0f && startPercents.x < 1.0f,
@"xOriginStartPercentage must be between 0 and 1, "
@"exclusively");
GREYThrowOnFailedConditionWithMessage(percents.y > 0.0f && percents.y < 1.0f,
GREYThrowOnFailedConditionWithMessage(startPercents.y > 0.0f && startPercents.y < 1.0f,
@"yOriginStartPercentage must be between 0 and 1, "
@"exclusively");

Expand All @@ -82,20 +92,34 @@ - (instancetype)initWithDirection:(GREYDirection)direction
if (self) {
_direction = direction;
_duration = duration;
_startPercents = percents;
_startPercents = startPercents;
_endPercents = endPercents;
_endPointSpecified = endPointSpecified;
}
return self;
}

- (instancetype)initWithDirection:(GREYDirection)direction duration:(CFTimeInterval)duration {
// TODO: Pick a visible point instead of picking the center of the view.
return [self initWithDirection:direction duration:duration percentPoint:CGPointMake(0.5, 0.5)];
return [self initWithDirection:direction duration:duration startPercentPoint:CGPointMake(0.5, 0.5)
endPercentPoint:CGPointMake(0.0, 0.0)
endPointSpecified:NO];
}

- (instancetype)initWithDirection:(GREYDirection)direction
duration:(CFTimeInterval)duration
startPercents:(CGPoint)startPercents {
return [self initWithDirection:direction duration:duration percentPoint:startPercents];
return [self initWithDirection:direction duration:duration startPercentPoint:startPercents
endPercentPoint:CGPointMake(0.0, 0.0)
endPointSpecified:NO];
}

- (instancetype)initWithDuration:(CFTimeInterval)duration
startPercents:(CGPoint)startPercents
endPercents:(CGPoint)endPercents {
return [self initWithDirection:GREYDirectionLeft duration:duration startPercentPoint:startPercents
endPercentPoint:endPercents
endPointSpecified:YES];
}

#pragma mark - GREYAction
Expand Down Expand Up @@ -150,7 +174,15 @@ - (NSArray *)touchPath:(UIView *)element forWindow:(UIWindow *)window {
CGPointMake(accessibilityFrame.origin.x + accessibilityFrame.size.width * _startPercents.x,
accessibilityFrame.origin.y + accessibilityFrame.size.height * _startPercents.y);

return GREYTouchPathForGestureInWindow(window, startPoint, _direction, _duration);
if (!_endPointSpecified) {
return GREYTouchPathForGestureInWindow(window, startPoint, _direction, _duration);
}

CGPoint endPoint =
CGPointMake(accessibilityFrame.origin.x + accessibilityFrame.size.width * _endPercents.x,
accessibilityFrame.origin.y + accessibilityFrame.size.height * _endPercents.y);

return GREYTouchPathForGestureBetweenPoints(startPoint, endPoint, _duration);
}

- (BOOL)shouldRunOnMainThread {
Expand Down

0 comments on commit 1a054d7

Please sign in to comment.