Skip to content

Commit

Permalink
fix(UIScrollView): assert on scrolling when view is not visible.
Browse files Browse the repository at this point in the history
This fixes the bug reported on this issue: wix#2834.
  • Loading branch information
asafkorem committed Nov 29, 2021
1 parent 30a1ef0 commit 6a5fc38
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions detox/ios/Detox/Actions/UIScrollView+DetoxActions.m
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ - (void)dtx_scrollWithOffset:(CGPoint)offset normalizedStartingPoint:(CGPoint)no

- (void)_dtx_scrollWithOffset:(CGPoint)offset normalizedStartingPoint:(CGPoint)normalizedStartingPoint strict:(BOOL)strict
{
[self dtx_assertVisibleWithPercent:@1];

if(offset.x == 0.0 && offset.y == 0.0)
{
return;
Expand Down
1 change: 1 addition & 0 deletions detox/ios/Detox/Utilities/NSObject+DetoxUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static double LNLinearInterpolate(CGFloat from, CGFloat to, CGFloat p)
@property (nonatomic, readonly) CGRect dtx_visibleBounds;

- (BOOL)dtx_isVisible;
- (void)dtx_assertVisibleWithPercent:(nullable NSNumber *)percent;
- (BOOL)dtx_isVisibleAtRect:(CGRect)rect percent:(nullable NSNumber *)percent
error:(NSError* __strong * __nullable)error;
- (void)dtx_assertVisible;
Expand Down
8 changes: 6 additions & 2 deletions detox/ios/Detox/Utilities/NSObject+DetoxUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,14 @@ - (BOOL)dtx_isVisibleAtRect:(CGRect)rect percent:(nullable NSNumber *)percent
}

- (void)dtx_assertVisible {
[self dtx_assertVisibleAtRect:self.dtx_bounds percent:nil];
[self dtx_assertVisibleWithPercent:nil];
}

- (void)dtx_assertVisibleAtRect:(CGRect)rect percent:(NSNumber *)percent {
- (void)dtx_assertVisibleWithPercent:(nullable NSNumber *)percent {
[self dtx_assertVisibleAtRect:self.dtx_bounds percent:percent];
}

- (void)dtx_assertVisibleAtRect:(CGRect)rect percent:(nullable NSNumber *)percent {
[self.dtx_view dtx_assertVisibleAtRect:rect percent:percent];
}

Expand Down
6 changes: 2 additions & 4 deletions detox/ios/Detox/Utilities/UIView+DetoxUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,8 @@ - (BOOL)_dtx_testVisibilityInRect:(CGRect)rect percent:(NSUInteger)percent
CGRect testedRegionInWindowCoords = [windowToUse convertRect:rect fromView:self];

CGRect visibleBounds = self.dtx_visibleBounds;

if (CGRectIsNull(visibleBounds) || [self _dtx_isRegionObscured:visibleBounds
fromTestedRegion:self.dtx_visibleBounds
percent:percent]) {
if (CGRectIsNull(visibleBounds) || CGRectIsEmpty(visibleBounds) ||
[self _dtx_isRegionObscured:visibleBounds fromTestedRegion:visibleBounds percent:percent]) {
auto errorDescription = [NSString stringWithFormat:@"View is clipped by one or more of its "
"superviews' bounds and does not pass visibility percent "
"threshold (%lu)", (unsigned long)percent];
Expand Down

0 comments on commit 6a5fc38

Please sign in to comment.