Skip to content

Commit

Permalink
Fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-wix authored and asafkorem committed Jan 8, 2024
1 parent d52c3d6 commit 728d8b3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 46 deletions.
36 changes: 15 additions & 21 deletions detox/ios/Detox/Actions/UIScrollView+DetoxActions.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ @implementation UIScrollView (DetoxActions)
[self setContentOffset:pointMakeMacro(target) animated:YES]; \
[NSRunLoop.currentRunLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:[[self valueForKeyPath:@"animation.duration"] doubleValue] + 0.05]];

- (void)dtx_scrollToEdge:(UIRectEdge)edge
- (CGPoint)_edgeToNormalizedEdge:(UIRectEdge)edge
{
CGPoint normalizedEdge;
switch (edge) {
Expand All @@ -100,10 +100,19 @@ - (void)dtx_scrollToEdge:(UIRectEdge)edge
normalizedEdge = CGPointMake(1, 0);
break;
default:
normalizedEdge= CGPointMake(0, 0);
DTXAssert(NO, @"Incorect edge provided.");
return;
}

return normalizedEdge;
}


- (void)dtx_scrollToEdge:(UIRectEdge)edge
{
CGPoint normalizedEdge = [self _edgeToNormalizedEdge:edge];
if(normalizedEdge.x == 0 && normalizedEdge.y == 0)
return;

[self _dtx_scrollToNormalizedEdge:normalizedEdge];
}

Expand All @@ -124,24 +133,9 @@ - (void)_dtx_scrollToNormalizedEdge:(CGPoint)edge
- (void)dtx_scrollToEdge:(UIRectEdge)edge
normalizedStartingPoint:(CGPoint)normalizedStartingPoint
{
CGPoint normalizedEdge;
switch (edge) {
case UIRectEdgeTop:
normalizedEdge = CGPointMake(0, -1);
break;
case UIRectEdgeBottom:
normalizedEdge = CGPointMake(0, 1);
break;
case UIRectEdgeLeft:
normalizedEdge = CGPointMake(-1, 0);
break;
case UIRectEdgeRight:
normalizedEdge = CGPointMake(1, 0);
break;
default:
DTXAssert(NO, @"Incorect edge provided.");
return;
}
CGPoint normalizedEdge = [self _edgeToNormalizedEdge:edge];
if(normalizedEdge.x == 0 && normalizedEdge.y == 0)
return;

[self _dtx_scrollToNormalizedEdge:normalizedEdge normalizedStartingPoint: normalizedStartingPoint ];
}
Expand Down
40 changes: 15 additions & 25 deletions detox/ios/Detox/Invocation/Action.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ class Action : CustomStringConvertible {
}
}

func startPosition(forIndex index: Int, in params: [Any]?) -> Double {
guard params?.count ?? 0 > index,
let param = params?[index] as? Double,
param.isNaN == false else {
return Double.nan
}
return param
}

var description: String {
let paramsDescription: String
if let params = params {
Expand Down Expand Up @@ -434,19 +443,9 @@ class ScrollToEdgeAction : Action {
fatalError("Unknown scroll direction")
break;
}

let startPositionX : Double
if params?.count ?? 0 > 1, let param1 = params?[1] as? Double, param1.isNaN == false {
startPositionX = param1
} else {
startPositionX = Double.nan
}
let startPositionY : Double
if params?.count ?? 0 > 2, let param2 = params?[2] as? Double, param2.isNaN == false {
startPositionY = param2
} else {
startPositionY = Double.nan
}

let startPositionX = startPosition(forIndex: 1, in: params)
let startPositionY = startPosition(forIndex: 2, in: params)
let normalizedStartingPoint = CGPoint(x: startPositionX, y: startPositionY)

element.scroll(to: targetEdge, normalizedStartingPoint: normalizedStartingPoint)
Expand Down Expand Up @@ -501,18 +500,9 @@ class SwipeAction : Action {
targetNormalizedOffset.x *= CGFloat(appliedPercentage)
targetNormalizedOffset.y *= CGFloat(appliedPercentage)

let startPositionX : Double
if params?.count ?? 0 > 3, let param2 = params?[3] as? Double, param2.isNaN == false {
startPositionX = param2
} else {
startPositionX = Double.nan
}
let startPositionY : Double
if params?.count ?? 0 > 4, let param3 = params?[4] as? Double, param3.isNaN == false {
startPositionY = param3
} else {
startPositionY = Double.nan
}

let startPositionX = startPosition(forIndex: 3, in: params)
let startPositionY = startPosition(forIndex: 4, in: params)
let normalizedStartingPoint = CGPoint(x: startPositionX, y: startPositionY)

element.swipe(normalizedOffset: targetNormalizedOffset, velocity: velocity, normalizedStartingPoint: normalizedStartingPoint)
Expand Down

0 comments on commit 728d8b3

Please sign in to comment.