@@ -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