Skip to content
Merged
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions apps/automated/src/ui/scroll-view/scroll-view-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,37 @@ class ScrollLayoutTest extends UITest<ScrollView> {
TKUnit.assertAreClose(layoutHelper.dip(this.testView.scrollableWidth), 300, 0.4, 'this.testView.scrollableWidth');
}

public test_scrollableHeight_includes_bottom_content_inset() {
if (!__APPLE__) {
return;
}
this.waitUntilTestElementLayoutIsValid();
const native = this.testView.ios as UIScrollView;
const before = this.testView.scrollableHeight;
native.contentInset = new UIEdgeInsets({ top: 0, left: 0, bottom: 50, right: 0 });

TKUnit.assertAreClose(this.testView.scrollableHeight, before + 50, 0.1, 'scrollableHeight with a bottom inset');
this.testView.scrollToVerticalOffset(this.testView.scrollableHeight, false);
const end = native.contentSize.height + native.adjustedContentInset.bottom - native.bounds.size.height;
TKUnit.assertAreClose(native.contentOffset.y, end, 0.1, 'scrollToVerticalOffset(scrollableHeight) reaches the end above the inset');
}

public test_scrollableWidth_includes_right_content_inset() {
if (!__APPLE__) {
return;
}
this.testView.orientation = 'horizontal';
this.waitUntilTestElementLayoutIsValid();
const native = this.testView.ios as UIScrollView;
const before = this.testView.scrollableWidth;
native.contentInset = new UIEdgeInsets({ top: 0, left: 0, bottom: 0, right: 40 });

TKUnit.assertAreClose(this.testView.scrollableWidth, before + 40, 0.1, 'scrollableWidth with a right inset');
this.testView.scrollToHorizontalOffset(this.testView.scrollableWidth, false);
const end = native.contentSize.width + native.adjustedContentInset.right - native.bounds.size.width;
TKUnit.assertAreClose(native.contentOffset.x, end, 0.1, 'scrollToHorizontalOffset(scrollableWidth) reaches the end beside the inset');
}

public test_scrollToVerticalOffset_no_animation() {
TKUnit.assertEqual(this.testView.verticalOffset, 0, 'this.testView.verticalOffset');
this.waitUntilTestElementLayoutIsValid();
Expand Down
8 changes: 6 additions & 2 deletions packages/core/ui/scroll-view/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,24 @@ export class ScrollView extends ScrollViewBase {
return this.nativeViewProtected ? this.nativeViewProtected.contentOffset.y : 0;
}

// Each is the largest offset a scroll reaches, end inset included, so scrolling to it shows the end of the
// content above a keyboard or docked bar that sets contentInset.bottom.
get scrollableWidth(): number {
if (!this.nativeViewProtected || this.orientation !== 'horizontal') {
return 0;
}

return Math.max(0, this.nativeViewProtected.contentSize.width - this.nativeViewProtected.bounds.size.width);
const nativeView = this.nativeViewProtected;
return Math.max(0, nativeView.contentSize.width + nativeView.adjustedContentInset.right - nativeView.bounds.size.width);
}

get scrollableHeight(): number {
if (!this.nativeViewProtected || this.orientation !== 'vertical') {
return 0;
}

return Math.max(0, this.nativeViewProtected.contentSize.height - this.nativeViewProtected.bounds.size.height);
const nativeView = this.nativeViewProtected;
return Math.max(0, nativeView.contentSize.height + nativeView.adjustedContentInset.bottom - nativeView.bounds.size.height);
}

[isScrollEnabledProperty.getDefault](): boolean {
Expand Down
Loading