Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Jan 14, 2025
1 parent b263b02 commit 5921b53
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions WebDriverAgentLib/Categories/XCUIElement+FBScrolling.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ - (BOOL)fb_scrollToVisibleWithError:(NSError **)error
return [self fb_scrollToVisibleWithNormalizedScrollDistance:FBScrollToVisibleNormalizedDistance error:error];
}

- (BOOL)fb_scrollToVisibleWithNormalizedScrollDistance:(CGFloat)normalizedScrollDistance error:(NSError **)error
- (BOOL)fb_scrollToVisibleWithNormalizedScrollDistance:(CGFloat)normalizedScrollDistance
error:(NSError **)error
{
return [self fb_scrollToVisibleWithNormalizedScrollDistance:normalizedScrollDistance
scrollDirection:FBXCUIElementScrollDirectionUnknown
Expand Down Expand Up @@ -130,12 +131,12 @@ - (BOOL)fb_scrollToVisibleWithNormalizedScrollDistance:(CGFloat)normalizedScroll
FBXCElementSnapshotWrapper *wrappedCellSnapshot = [FBXCElementSnapshotWrapper ensureWrapped:cellSnapshot];
if (wrappedCellSnapshot.wdVisible) {
[visibleCellSnapshots addObject:cellSnapshot];
if (visibleCellSnapshots.count > 1) {
return YES;
}
}
}

if (visibleCellSnapshots.count > 1) {
return YES;
}
return NO;
}];

Expand Down Expand Up @@ -247,35 +248,42 @@ - (CGRect)scrollingFrame
return self.visibleFrame;
}

- (void)fb_scrollUpByNormalizedDistance:(CGFloat)distance inApplication:(XCUIApplication *)application
- (void)fb_scrollUpByNormalizedDistance:(CGFloat)distance
inApplication:(XCUIApplication *)application
{
[self fb_scrollByNormalizedVector:CGVectorMake(0.0, distance) inApplication:application];
}

- (void)fb_scrollDownByNormalizedDistance:(CGFloat)distance inApplication:(XCUIApplication *)application
- (void)fb_scrollDownByNormalizedDistance:(CGFloat)distance
inApplication:(XCUIApplication *)application
{
[self fb_scrollByNormalizedVector:CGVectorMake(0.0, -distance) inApplication:application];
}

- (void)fb_scrollLeftByNormalizedDistance:(CGFloat)distance inApplication:(XCUIApplication *)application
- (void)fb_scrollLeftByNormalizedDistance:(CGFloat)distance
inApplication:(XCUIApplication *)application
{
[self fb_scrollByNormalizedVector:CGVectorMake(distance, 0.0) inApplication:application];
}

- (void)fb_scrollRightByNormalizedDistance:(CGFloat)distance inApplication:(XCUIApplication *)application
- (void)fb_scrollRightByNormalizedDistance:(CGFloat)distance
inApplication:(XCUIApplication *)application
{
[self fb_scrollByNormalizedVector:CGVectorMake(-distance, 0.0) inApplication:application];
}

- (BOOL)fb_scrollByNormalizedVector:(CGVector)normalizedScrollVector inApplication:(XCUIApplication *)application
- (BOOL)fb_scrollByNormalizedVector:(CGVector)normalizedScrollVector
inApplication:(XCUIApplication *)application
{
CGVector scrollVector = CGVectorMake(CGRectGetWidth(self.scrollingFrame) * normalizedScrollVector.dx,
CGRectGetHeight(self.scrollingFrame) * normalizedScrollVector.dy
);
return [self fb_scrollByVector:scrollVector inApplication:application error:nil];
}

- (BOOL)fb_scrollByVector:(CGVector)vector inApplication:(XCUIApplication *)application error:(NSError **)error
- (BOOL)fb_scrollByVector:(CGVector)vector
inApplication:(XCUIApplication *)application
error:(NSError **)error
{
CGVector scrollBoundingVector = CGVectorMake(
CGRectGetWidth(self.scrollingFrame) * FBScrollTouchProportion,
Expand Down Expand Up @@ -306,7 +314,9 @@ - (CGVector)fb_hitPointOffsetForScrollingVector:(CGVector)scrollingVector
return CGVectorMake((CGFloat)floor(x), (CGFloat)floor(y));
}

- (BOOL)fb_scrollAncestorScrollViewByVectorWithinScrollViewFrame:(CGVector)vector inApplication:(XCUIApplication *)application error:(NSError **)error
- (BOOL)fb_scrollAncestorScrollViewByVectorWithinScrollViewFrame:(CGVector)vector
inApplication:(XCUIApplication *)application
error:(NSError **)error
{
CGVector hitpointOffset = [self fb_hitPointOffsetForScrollingVector:vector];

Expand Down

0 comments on commit 5921b53

Please sign in to comment.