Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions packages/core/ui/scroll-view/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,27 @@ export class ScrollView extends ScrollViewBase {
this.updateContentInsetAdjustmentBehavior(value);
}

// The offset is set directly rather than through scrollRectToVisible with a
// viewport-sized rect: that rect cannot fit inside a content inset, so UIKit
// would land contentInset.bottom (or .right) past the requested offset. The
// value is clamped to the range a user scroll can reach.
public scrollToVerticalOffset(value: number, animated: boolean) {
if (this.nativeViewProtected && this.orientation === 'vertical' && this.isScrollEnabled) {
const bounds = this.nativeViewProtected.bounds.size;
this.nativeViewProtected.scrollRectToVisibleAnimated(CGRectMake(0, value, bounds.width, bounds.height), animated);
const nativeView = this.nativeViewProtected;
if (nativeView && this.orientation === 'vertical' && this.isScrollEnabled) {
const inset = nativeView.adjustedContentInset;
const min = -inset.top;
const max = Math.max(min, nativeView.contentSize.height + inset.bottom - nativeView.bounds.size.height);
nativeView.setContentOffsetAnimated(CGPointMake(nativeView.contentOffset.x, Math.min(Math.max(value, min), max)), animated);
}
}

public scrollToHorizontalOffset(value: number, animated: boolean) {
if (this.nativeViewProtected && this.orientation === 'horizontal' && this.isScrollEnabled) {
const bounds = this.nativeViewProtected.bounds.size;
this.nativeViewProtected.scrollRectToVisibleAnimated(CGRectMake(value, 0, bounds.width, bounds.height), animated);
const nativeView = this.nativeViewProtected;
if (nativeView && this.orientation === 'horizontal' && this.isScrollEnabled) {
const inset = nativeView.adjustedContentInset;
const min = -inset.left;
const max = Math.max(min, nativeView.contentSize.width + inset.right - nativeView.bounds.size.width);
nativeView.setContentOffsetAnimated(CGPointMake(Math.min(Math.max(value, min), max), nativeView.contentOffset.y), animated);
}
}

Expand Down
Loading