Skip to content

Commit 821a72b

Browse files
committed
Overscroll to make lazy scrollviews work
1 parent 37a6050 commit 821a72b

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

Sources/SBTUITestTunnelServer/SBTUITestTunnelServer.m

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@ - (CGRect)visibleUnobscuredFrameInWindowForScrollView:(UIScrollView *)scrollView
914914
}
915915

916916
CGRect visibleFrame = [scrollView convertRect:scrollView.bounds toView:window];
917+
visibleFrame = UIEdgeInsetsInsetRect(visibleFrame, scrollView.adjustedContentInset);
917918
visibleFrame = CGRectIntersection(window.bounds, visibleFrame);
918919

919920
if (CGRectIsNull(visibleFrame) || CGRectIsEmpty(visibleFrame)) {
@@ -1087,10 +1088,10 @@ - (BOOL)scrollToTargetView:(UIView *)target
10871088
CGPoint newOffset = scrollView.contentOffset;
10881089
CGFloat desired;
10891090
if (isVertical) {
1090-
desired = scrollView.contentOffset.y + (CGRectGetMinY(targetFrameInWindow) - CGRectGetMinY(visibleFrameInWindow) - insets.top);
1091+
desired = scrollView.contentOffset.y + (CGRectGetMinY(targetFrameInWindow) - CGRectGetMinY(visibleFrameInWindow));
10911092
newOffset.y = MIN(maxOffset, MAX(-insets.top, desired));
10921093
} else {
1093-
desired = scrollView.contentOffset.x + (CGRectGetMinX(targetFrameInWindow) - CGRectGetMinX(visibleFrameInWindow) - insets.left);
1094+
desired = scrollView.contentOffset.x + (CGRectGetMinX(targetFrameInWindow) - CGRectGetMinX(visibleFrameInWindow));
10941095
newOffset.x = MIN(maxOffset, MAX(-insets.left, desired));
10951096
}
10961097

@@ -1108,8 +1109,10 @@ - (BOOL)scrollToTargetView:(UIView *)target
11081109
}
11091110

11101111
// Advances the scroll view by one page to reveal more content while searching
1111-
// for a target. If already at the end, waits briefly for lazy loading to extend
1112-
// contentSize. Returns NO when truly at the end (no more pages, no growth).
1112+
// for a target. If already at the end, overscrolls past maxOffset to trigger
1113+
// "load more" handlers that fire on pull-past-edge, then waits briefly for
1114+
// lazy loading to extend contentSize. Returns NO when truly at the end (no
1115+
// more pages, no growth).
11131116
- (BOOL)advanceScrollView:(UIScrollView *)scrollView
11141117
direction:(SBTUITestTunnelScrollDirection)direction
11151118
animated:(BOOL)animated
@@ -1129,7 +1132,27 @@ - (BOOL)advanceScrollView:(UIScrollView *)scrollView
11291132
return YES;
11301133
}
11311134

1135+
// At the end: bump contentInset to open an overscroll region, pull into it
1136+
// so scroll delegates fire (common "load more" trigger), then restore the
1137+
// inset. UIKit would otherwise clamp setContentOffset: at maxOffset.
1138+
UIEdgeInsets originalInset = scrollView.contentInset;
1139+
UIEdgeInsets bumpedInset = originalInset;
1140+
CGFloat overscroll = pageSize * 0.5;
1141+
if (isVertical) {
1142+
bumpedInset.bottom += overscroll;
1143+
} else {
1144+
bumpedInset.right += overscroll;
1145+
}
1146+
scrollView.contentInset = bumpedInset;
1147+
1148+
CGPoint overscrollOffset = isVertical
1149+
? CGPointMake(scrollView.contentOffset.x, maxOffset + overscroll)
1150+
: CGPointMake(maxOffset + overscroll, scrollView.contentOffset.y);
1151+
[scrollView setContentOffset:overscrollOffset animated:animated];
11321152
[self spinMainRunLoopForInterval:0.5];
1153+
1154+
scrollView.contentInset = originalInset;
1155+
11331156
return [self maxContentOffsetForScrollView:scrollView direction:direction] > maxOffset;
11341157
}
11351158

0 commit comments

Comments
 (0)