Skip to content

Commit

Permalink
Add a test that would hit the failure from kif-framework#1080
Browse files Browse the repository at this point in the history
Add some generics to the arrays to make it a bit more clear
Enforce that we always send at least 2 points for the path in 'twoFingerRotateAtPoint:angle:'.
Add more safety in 'dragPointsAlongPaths:'.
  • Loading branch information
justinseanmartin committed Aug 2, 2018
1 parent d3dfd90 commit 1440d37
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
27 changes: 15 additions & 12 deletions Additions/UIView-KIFAdditions.m
Expand Up @@ -571,14 +571,14 @@ - (void)dragAlongPathWithPoints:(CGPoint *)points count:(NSInteger)count;
[self dragPointsAlongPaths:@[[array copy]]];
}

- (void)dragPointsAlongPaths:(NSArray *)arrayOfPaths {
// must have at least one path, and each path must have the same number of points
if (arrayOfPaths.count == 0)
- (void)dragPointsAlongPaths:(NSArray<NSArray<NSValue *> *> *)arrayOfPaths {
// There must be at least one path with at least one point
if (arrayOfPaths.count == 0 || arrayOfPaths.firstObject.count == 0)
{
return;
}

// all paths must have similar number of points
// all paths must have the same number of points
NSUInteger pointsInPath = [arrayOfPaths[0] count];
for (NSArray *path in arrayOfPaths)
{
Expand All @@ -588,14 +588,14 @@ - (void)dragPointsAlongPaths:(NSArray *)arrayOfPaths {
}
}

NSMutableArray *touches = [NSMutableArray array];
NSMutableArray<UITouch *> *touches = [NSMutableArray array];

// Convert paths to be in window coordinates before we start, because the view may
// move relative to the window.
NSMutableArray *newPaths = [[NSMutableArray alloc] init];
NSMutableArray<NSArray<NSValue *> *> *newPaths = [[NSMutableArray alloc] init];

for (NSArray * path in arrayOfPaths) {
NSMutableArray *newPath = [[NSMutableArray alloc] init];
NSMutableArray<NSValue *> *newPath = [[NSMutableArray alloc] init];
for (NSValue *pointValue in path) {
CGPoint point = [pointValue CGPointValue];
[newPath addObject:[NSValue valueWithCGPoint:[self.window convertPoint:point fromView:self]]];
Expand All @@ -609,7 +609,7 @@ - (void)dragPointsAlongPaths:(NSArray *)arrayOfPaths {
// create initial touch event and send touch down event
if (pointIndex == 0)
{
for (NSArray *path in arrayOfPaths)
for (NSArray<NSValue *> *path in arrayOfPaths)
{
CGPoint point = [path[pointIndex] CGPointValue];
// The starting point needs to be relative to the view receiving the UITouch event.
Expand All @@ -628,7 +628,7 @@ - (void)dragPointsAlongPaths:(NSArray *)arrayOfPaths {
UITouch *touch;
for (NSUInteger pathIndex = 0; pathIndex < arrayOfPaths.count; pathIndex++)
{
NSArray *path = arrayOfPaths[pathIndex];
NSArray<NSValue *> *path = arrayOfPaths[pathIndex];
CGPoint point = [path[pointIndex] CGPointValue];
touch = touches[pathIndex];
[touch setLocationInWindow:point];
Expand Down Expand Up @@ -709,12 +709,15 @@ - (void)zoomAtPoint:(CGPoint)centerPoint distance:(CGFloat)distance steps:(NSUIn
}

- (void)twoFingerRotateAtPoint:(CGPoint)centerPoint angle:(CGFloat)angleInDegrees {
NSInteger stepCount = ABS(angleInDegrees)/2; // very rough approximation. 90deg = ~45 steps, 360 deg = ~180 steps
// Very rough approximation. 90deg = ~45 steps, 360 deg = ~180 steps
// Enforce a minimum of 2 steps.
NSInteger stepCount = MAX(ABS(angleInDegrees)/2, 2);

CGFloat radius = kTwoFingerConstantWidth*2;
double angleInRadians = KIFDegreesToRadians(angleInDegrees);

NSMutableArray *finger1Path = [NSMutableArray array];
NSMutableArray *finger2Path = [NSMutableArray array];
NSMutableArray<NSValue *> *finger1Path = [NSMutableArray array];
NSMutableArray<NSValue *> *finger2Path = [NSMutableArray array];
for (NSUInteger i = 0; i < stepCount; i++) {
double currentAngle = 0;
if (i == stepCount - 1) {
Expand Down
1 change: 1 addition & 0 deletions KIF Tests/MultiFingerTests.m
Expand Up @@ -125,6 +125,7 @@ - (void)testRotate {

[scrollView addGestureRecognizer:rotateRecognizer];

[self assertThatLatestRotationIsWithinThreshold:1];
[self assertThatLatestRotationIsWithinThreshold:45];
[self assertThatLatestRotationIsWithinThreshold:90];
[self assertThatLatestRotationIsWithinThreshold:180];
Expand Down

0 comments on commit 1440d37

Please sign in to comment.