Skip to content
This repository has been archived by the owner on Dec 26, 2019. It is now read-only.

Commit

Permalink
Use visibleFrame to calculate scrolling vector
Browse files Browse the repository at this point in the history
Summary:
Using views frame for calculating scroling vector might be buggy when application is doing tricky stuff with scolling views eg. nesting scrollview within scrollview.
In that case frame of the second scrollview will be huge and make scrolling imposible as we will try to use points of the screen. Instead we should visible frame.

Reviewed By: antiarchit

Differential Revision: D6819626

fbshipit-source-id: 27062f593485b4ec55ae8bd1a9c9a32a89630b92
  • Loading branch information
Marek Cirkos authored and facebook-github-bot committed Feb 5, 2018
1 parent 183f679 commit 1199aa4
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions WebDriverAgentLib/Categories/XCUIElement+FBScrolling.m
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ - (BOOL)fb_isEquivalentElementSnapshotVisible:(XCElementSnapshot *)snapshot

@implementation XCElementSnapshot (FBScrolling)

- (CGRect)scrollingFrame
{
return self.visibleFrame;
}

- (void)fb_scrollUpByNormalizedDistance:(CGFloat)distance inApplication:(XCUIApplication *)application
{
[self fb_scrollByNormalizedVector:CGVectorMake(0.0, distance) inApplication:application];
Expand All @@ -226,16 +231,16 @@ - (void)fb_scrollRightByNormalizedDistance:(CGFloat)distance inApplication:(XCUI

- (BOOL)fb_scrollByNormalizedVector:(CGVector)normalizedScrollVector inApplication:(XCUIApplication *)application
{
CGVector scrollVector = CGVectorMake(CGRectGetWidth(self.frame) * normalizedScrollVector.dx,
CGRectGetHeight(self.frame) * normalizedScrollVector.dy
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
{
CGVector scrollBoundingVector = CGVectorMake(CGRectGetWidth(self.frame) * FBScrollTouchProportion - FBScrollBoundingVelocityPadding,
CGRectGetHeight(self.frame)* FBScrollTouchProportion - FBScrollBoundingVelocityPadding
CGVector scrollBoundingVector = CGVectorMake(CGRectGetWidth(self.scrollingFrame) * FBScrollTouchProportion - FBScrollBoundingVelocityPadding,
CGRectGetHeight(self.scrollingFrame)* FBScrollTouchProportion - FBScrollBoundingVelocityPadding
);
scrollBoundingVector.dx = (CGFloat)floor(copysign(scrollBoundingVector.dx, vector.dx));
scrollBoundingVector.dy = (CGFloat)floor(copysign(scrollBoundingVector.dy, vector.dy));
Expand All @@ -257,8 +262,8 @@ - (BOOL)fb_scrollByVector:(CGVector)vector inApplication:(XCUIApplication *)appl

- (CGVector)fb_hitPointOffsetForScrollingVector:(CGVector)scrollingVector
{
CGFloat x = CGRectGetMinX(self.frame) + CGRectGetWidth(self.frame) * (scrollingVector.dx < 0.0f ? FBScrollTouchProportion : (1 - FBScrollTouchProportion));
CGFloat y = CGRectGetMinY(self.frame) + CGRectGetHeight(self.frame) * (scrollingVector.dy < 0.0f ? FBScrollTouchProportion : (1 - FBScrollTouchProportion));
CGFloat x = CGRectGetMinX(self.scrollingFrame) + CGRectGetWidth(self.scrollingFrame) * (scrollingVector.dx < 0.0f ? FBScrollTouchProportion : (1 - FBScrollTouchProportion));
CGFloat y = CGRectGetMinY(self.scrollingFrame) + CGRectGetHeight(self.scrollingFrame) * (scrollingVector.dy < 0.0f ? FBScrollTouchProportion : (1 - FBScrollTouchProportion));
return CGVectorMake((CGFloat)floor(x), (CGFloat)floor(y));
}

Expand Down

1 comment on commit 1199aa4

@vksd07
Copy link

@vksd07 vksd07 commented on 1199aa4 Feb 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi
send keys works fine to select picker wheel elements but I want to know how to scroll elements ?

Please sign in to comment.