Skip to content

Commit c7564a7

Browse files
Internal Commit Uploaded
PiperOrigin-RevId: 463388614
1 parent 60a7805 commit c7564a7

File tree

4 files changed

+91
-9
lines changed

4 files changed

+91
-9
lines changed

AppFramework/Action/GREYPathGestureUtils.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ NSArray<NSValue *> *GREYTouchPathForGestureInView(UIView *view, CGPoint startPoi
6262
GREYDirection direction, CGFloat length,
6363
CGFloat *outRemainingAmountOrNull);
6464

65+
/**
66+
* Generates a touch path in the given @c view from @c startPoint to @c endPoint in view-relative
67+
* coordinates.
68+
*
69+
* @param window The window in which the touch path is generated.
70+
* @param startPointInWindowCoordinates The start point in screen coordinates.
71+
* @param endPointInWindowCoordinates The end point in screen coordinates.
72+
* @param duration How long the gesture should last (in seconds).
73+
*
74+
* @return NSArray of CGPoints that denote the points in the touch path.
75+
*/
76+
NSArray<NSValue *> *GREYTouchPathForGestureBetweenPoints(CGPoint startPointInScreenCoordinates,
77+
CGPoint endPointInScreenCoordinates,
78+
CFTimeInterval duration);
79+
6580
/**
6681
* Generates a touch path in the @c window from the given @c startPoint and the given @c
6782
* endPoint.

AppFramework/Action/GREYPathGestureUtils.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@
106106
return GREYGenerateTouchPath(startPointInWindowCoordinates, endPointInWindowCoords, duration, NO);
107107
}
108108

109+
NSArray<NSValue *> *GREYTouchPathForGestureBetweenPoints(CGPoint startPointInWindowCoordinates,
110+
CGPoint endPointInWindowCoordinates,
111+
CFTimeInterval duration) {
112+
return GREYGenerateTouchPath(startPointInWindowCoordinates, endPointInWindowCoords, duration, NO);
113+
}
114+
109115
NSArray<NSValue *> *GREYTouchPathForDragGestureInScreen(CGPoint startPoint, CGPoint endPoint,
110116
BOOL cancelInertia) {
111117
return GREYGenerateTouchPath(startPoint, endPoint, NAN, cancelInertia);

AppFramework/Action/GREYSwipeAction.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
*
5353
* @param direction The direction of the swipe.
5454
* @param duration The time interval for which the swipe takes place.
55-
* @param startPercents @c startPercents.x sets the value of the x-coordinate of the start point
56-
* by interpolating between left(for 0.0) and right(for 1.0) edge similarly
55+
* @param startPercents @c startPercents.x sets the value of the x coordinate of the start point
56+
* by interpolating between left(for 0.0) and right(for 1.0) edge. Similarly,
5757
* @c startPercents.y determines the y coordinate.
5858
*
5959
* @return An instance of GREYSwipeAction, initialized with the provided direction, duration
@@ -62,4 +62,27 @@
6262
- (instancetype)initWithDirection:(GREYDirection)direction
6363
duration:(CFTimeInterval)duration
6464
startPercents:(CGPoint)startPercents;
65+
66+
/**
67+
* Performs a swipe in the given @c direction in the given @c duration. The start of the swipe is
68+
* specified by @c startPercents. The end of the swipe is specified by @c endPercents. Because
69+
* swipes must begin inside the element and not on the edge of it, the values in @c startPercents
70+
* must be in the range (0,1) exclusive. All coordinates are relative to the element's visible
71+
* area on-screen (accessibility frame).
72+
*
73+
* @param direction The direction of the swipe.
74+
* @param duration The time interval for which the swipe takes place.
75+
* @param startPercents @c startPercents.x sets the value of the x coordinate of the start point
76+
* by interpolating between left(for 0.0) and right(for 1.0) edge. Similarly,
77+
* @c startPercents.y determines the y coordinate.
78+
* @param endPercents @c endPercents.x sets the value of the x coordinate of the end point
79+
* by interpolating between left(for 0.0) and right(for 1.0) edge. Similarly,
80+
* @c endPercents.y determines the y coordinate.
81+
*
82+
* @return An instance of GREYSwipeAction, initialized with the provided direction, duration
83+
* and information for the start point.
84+
*/
85+
- (instancetype)initWithDuration:(CFTimeInterval)duration
86+
startPercents:(CGPoint)startPercents
87+
endPercents:(CGPoint)startPercents;
6588
@end

AppFramework/Action/GREYSwipeAction.m

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,25 @@ @implementation GREYSwipeAction {
4949
* Start point for the swipe specified as percentage of swipped element's accessibility frame.
5050
*/
5151
CGPoint _startPercents;
52+
/**
53+
* Start point for the swipe specified as percentage of swipped element's accessibility frame.
54+
*/
55+
CGPoint _endPercents;
56+
/**
57+
* YES if end point is specified, else NO.
58+
*/
59+
BOOL _endPointSpecified;
5260
}
5361

5462
- (instancetype)initWithDirection:(GREYDirection)direction
5563
duration:(CFTimeInterval)duration
56-
percentPoint:(CGPoint)percents {
57-
GREYThrowOnFailedConditionWithMessage(percents.x > 0.0f && percents.x < 1.0f,
64+
startPercentPoint:(CGPoint)startPercents
65+
endPercentPoint:(CGPoint)percents
66+
endPointSpecified:(BOOL)endPointSpecified {
67+
GREYThrowOnFailedConditionWithMessage(startPercents.x > 0.0f && startPercents.x < 1.0f,
5868
@"xOriginStartPercentage must be between 0 and 1, "
5969
@"exclusively");
60-
GREYThrowOnFailedConditionWithMessage(percents.y > 0.0f && percents.y < 1.0f,
70+
GREYThrowOnFailedConditionWithMessage(startPercents.y > 0.0f && startPercents.y < 1.0f,
6171
@"yOriginStartPercentage must be between 0 and 1, "
6272
@"exclusively");
6373

@@ -82,20 +92,40 @@ - (instancetype)initWithDirection:(GREYDirection)direction
8292
if (self) {
8393
_direction = direction;
8494
_duration = duration;
85-
_startPercents = percents;
95+
_startPercents = startPercents;
96+
_endPercents = endPercents;
97+
_endPointSpecified = endPointSpecified;
8698
}
8799
return self;
88100
}
89101

90102
- (instancetype)initWithDirection:(GREYDirection)direction duration:(CFTimeInterval)duration {
91103
// TODO: Pick a visible point instead of picking the center of the view.
92-
return [self initWithDirection:direction duration:duration percentPoint:CGPointMake(0.5, 0.5)];
104+
return [self initWithDirection:direction
105+
duration:duration
106+
startPercentPoint:CGPointMake(0.5, 0.5)
107+
endPercentPoint:CGPointMake(0.0, 0.0)
108+
endPointSpecified:NO];
93109
}
94110

95111
- (instancetype)initWithDirection:(GREYDirection)direction
96112
duration:(CFTimeInterval)duration
97113
startPercents:(CGPoint)startPercents {
98-
return [self initWithDirection:direction duration:duration percentPoint:startPercents];
114+
return [self initWithDirection:direction
115+
duration:duration
116+
startPercentPoint:startPercents
117+
endPercentPoint:CGPointMake(0.0, 0.0)
118+
endPointSpecified:NO];
119+
}
120+
121+
- (instancetype)initWithDuration:(CFTimeInterval)duration
122+
startPercents:(CGPoint)startPercents
123+
endPercents:(CGPoint)endPercents {
124+
return [self initWithDirection:GREYDirectionLeft
125+
duration:duration
126+
startPercentPoint:startPercents
127+
endPercentPoint:endPercents
128+
endPointSpecified:YES];
99129
}
100130

101131
#pragma mark - GREYAction
@@ -150,7 +180,15 @@ - (NSArray *)touchPath:(UIView *)element forWindow:(UIWindow *)window {
150180
CGPointMake(accessibilityFrame.origin.x + accessibilityFrame.size.width * _startPercents.x,
151181
accessibilityFrame.origin.y + accessibilityFrame.size.height * _startPercents.y);
152182

153-
return GREYTouchPathForGestureInWindow(window, startPoint, _direction, _duration);
183+
if (!_endPointSpecified) {
184+
return GREYTouchPathForGestureInWindow(window, startPoint, _direction, _duration);
185+
}
186+
187+
CGPoint endPoint =
188+
CGPointMake(accessibilityFrame.origin.x + accessibilityFrame.size.width * _endPercents.x,
189+
accessibilityFrame.origin.y + accessibilityFrame.size.height * _endPercents.y);
190+
191+
return GREYTouchPathForGestureBetweenPoints(startPoint, endPoint, _duration);
154192
}
155193

156194
- (BOOL)shouldRunOnMainThread {

0 commit comments

Comments
 (0)