-
Notifications
You must be signed in to change notification settings - Fork 739
Add precise swipe actions for swipes from a start to an end point #675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
steviki
wants to merge
10
commits into
google:master
Choose a base branch
from
PSPDFKit-labs:precise-swipe-action
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d704d48
Add precise swipe action for swipes from a start to an end point
steviki 0bdd2ca
Make the start and end point based on the view's origin
steviki 67faf2c
More indention
steviki 9476634
Make GREYSwipeAction.h privately available
steviki 2f238a1
Fix capitalization
steviki 1060ec0
Add precise swipe action unit tests
steviki 078b9cc
Add functional precise swipe tests
steviki 8dd0077
Address code style feedback
steviki edd869e
Add nullability macros
steviki 51ae4fc
Fix typo
steviki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// Copyright 2018 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#import <EarlGrey/GREYBaseAction.h> | ||
#import <EarlGrey/GREYConstants.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** | ||
* A GREYAction that swipes/flicks the matched element from a concrete start point to an end point. | ||
*/ | ||
@interface GREYPreciseSwipeAction : GREYBaseAction | ||
|
||
/** | ||
* @remark init is not an available initializer. Use the other initializers. | ||
*/ | ||
- (instancetype)init NS_UNAVAILABLE; | ||
|
||
/** | ||
* @remark initWithName:constraints: is overridden from its superclass. | ||
*/ | ||
- (instancetype)initWithName:(NSString *)name | ||
constraints:(id<GREYMatcher>)constraints NS_UNAVAILABLE; | ||
|
||
/** | ||
* Performs a swipe from the given @c startPoint to the given @c endPoint. | ||
* | ||
* @param startPoint The point where the swipe should begin. Relative to the matched view's origin. | ||
* @param endPoint The point where the swipe should end. Relative to the matched view's origin. | ||
* @param duration The time interval for which the swipe takes place. | ||
* | ||
* @return An instance of GREYPreciseSwipeAction, initialized with the provided start point, | ||
* end point and duration. | ||
*/ | ||
- (instancetype)initWithStartPoint:(CGPoint)startPoint | ||
endPoint:(CGPoint)endPoint | ||
duration:(CFTimeInterval)duration; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// | ||
// Copyright 2018 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#import "Action/GREYPreciseSwipeAction.h" | ||
|
||
#import "Action/GREYPathGestureUtils.h" | ||
#import "Additions/NSError+GREYAdditions.h" | ||
#import "Additions/NSObject+GREYAdditions.h" | ||
#import "Additions/NSString+GREYAdditions.h" | ||
#import "Assertion/GREYAssertionDefines.h" | ||
#import "Assertion/GREYAssertions+Internal.h" | ||
#import "Common/GREYError.h" | ||
#import "Common/GREYThrowDefines.h" | ||
#import "Event/GREYSyntheticEvents.h" | ||
#import "Matcher/GREYAllOf.h" | ||
#import "Matcher/GREYMatcher.h" | ||
#import "Matcher/GREYMatchers.h" | ||
#import "Matcher/GREYNot.h" | ||
|
||
@implementation GREYPreciseSwipeAction { | ||
/** | ||
* The point where the swipe should begin. | ||
*/ | ||
CGPoint _startPoint; | ||
/** | ||
* The point where the swipe should end. | ||
*/ | ||
CGPoint _endPoint; | ||
/** | ||
* The duration within which the swipe action must be complete. | ||
*/ | ||
CFTimeInterval _duration; | ||
} | ||
|
||
- (instancetype)initWithStartPoint:(CGPoint)startPoint | ||
endPoint:(CGPoint)endPoint | ||
duration:(CFTimeInterval)duration { | ||
|
||
NSString *name = | ||
[NSString stringWithFormat:@"Precise swipe from %@ to %@ for duration %g", | ||
NSStringFromCGPoint(startPoint), | ||
NSStringFromCGPoint(endPoint), | ||
duration]; | ||
self = [super initWithName:name | ||
constraints:grey_allOf(grey_interactable(), | ||
grey_not(grey_systemAlertViewShown()), | ||
grey_kindOfClass([UIView class]), | ||
grey_respondsToSelector(@selector(accessibilityFrame)), | ||
nil)]; | ||
if (self) { | ||
_startPoint = startPoint; | ||
_endPoint = endPoint; | ||
_duration = duration; | ||
} | ||
return self; | ||
} | ||
|
||
#pragma mark - GREYAction | ||
|
||
- (BOOL)perform:(id)element error:(__strong NSError **)errorOrNil { | ||
if (![self satisfiesConstraintsForElement:element error:errorOrNil]) { | ||
return NO; | ||
} | ||
CGRect accessibilityFrame = [element accessibilityFrame]; | ||
CGPoint startPoint = | ||
CGPointMake(_startPoint.x + accessibilityFrame.origin.x, | ||
_startPoint.y + accessibilityFrame.origin.y); | ||
CGPoint endPoint = | ||
CGPointMake(_endPoint.x + accessibilityFrame.origin.x, | ||
_endPoint.y + accessibilityFrame.origin.y); | ||
|
||
UIWindow *window = [element window]; | ||
if (!window) { | ||
if ([element isKindOfClass:[UIWindow class]]) { | ||
window = (UIWindow *)element; | ||
} else { | ||
NSString *errorDescription = | ||
[NSString stringWithFormat:@"Cannot swipe on view [V], as it has no window and " | ||
@"it isn't a window itself."]; | ||
NSDictionary *glossary = @{ @"V" : [element grey_description] }; | ||
GREYError *error; | ||
error = GREYErrorMake(kGREYSyntheticEventInjectionErrorDomain, | ||
kGREYOrientationChangeFailedErrorCode, | ||
errorDescription); | ||
error.descriptionGlossary = glossary; | ||
if (errorOrNil) { | ||
*errorOrNil = error; | ||
} else { | ||
[GREYAssertions grey_raiseExceptionNamed:kGREYGenericFailureException | ||
exceptionDetails:@"" | ||
withError:error]; | ||
} | ||
return NO; | ||
} | ||
} | ||
NSArray *touchPath = [GREYPathGestureUtils touchPathForDragGestureWithStartPoint:startPoint | ||
endPoint:endPoint | ||
cancelInertia:NO]; | ||
|
||
[GREYSyntheticEvents touchAlongPath:touchPath | ||
relativeToWindow:window | ||
forDuration:_duration | ||
expendable:YES]; | ||
return YES; | ||
} | ||
|
||
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.