Commit e76c6253 authored by adamta's avatar adamta Committed by Commit Bot

[iOS] Increase offset for infinite feed triggering

Increase offset to fit ~2 cards before triggering infinite feed. Compute
initial NTP scroll height in layout to only trigger infinite feed if the
feed has loaded.

Bug: 1085419
Change-Id: I9fccd5f135382d5574ccb6a7ce562339455c7564
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2355294
Commit-Queue: Adam Trudeau-Arcaro <adamta@google.com>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798296}
parent a7b6cd33
......@@ -16,6 +16,9 @@
// The cached scroll position of the NTP.
@property(nonatomic, assign) CGFloat offset;
// The total scroll height of the NTP.
@property(nonatomic, assign) CGFloat ntpHeight;
// Creates layout with |offset| as additional height. Allows the view's height
// to be increased enough to maintain the scroll position. Only needed if
// Discover feed is enabled.
......
......@@ -30,9 +30,11 @@
// The minimum height for the collection view content should be the height of
// the header plus the height of the collection view minus the height of the
// NTP bottom bar. This allows the Most Visited cells to be scrolled up to the
// top of the screen.
CGFloat minimumHeight = collectionViewHeight + headerHeight -
ntp_header::kScrolledToTopOmniboxBottomMargin;
// top of the screen. Also computes the total NTP scrolling height for
// Discover infinite feed.
self.ntpHeight = collectionViewHeight + headerHeight;
CGFloat minimumHeight =
self.ntpHeight - ntp_header::kScrolledToTopOmniboxBottomMargin;
CGFloat topSafeArea = self.collectionView.safeAreaInsets.top;
if (!IsRegularXRegularSizeClass(self.collectionView)) {
CGFloat toolbarHeight =
......@@ -40,8 +42,10 @@
? ToolbarExpandedHeight([UIApplication sharedApplication]
.preferredContentSizeCategory)
: 0;
minimumHeight -=
CGFloat additionalHeight =
toolbarHeight + topSafeArea + self.collectionView.contentInset.bottom;
minimumHeight -= additionalHeight;
self.ntpHeight += additionalHeight;
}
CGSize contentSize = [super collectionViewContentSize];
......
......@@ -52,7 +52,7 @@ const CGFloat kMostVisitedBottomMargin = 13;
const CGFloat kCardBorderRadius = 11;
const CGFloat kDiscoverFeedContentWith = 430;
// Value representing offset from bottom of the page to trigger pagination.
const CGFloat kPaginationOffset = 100;
const CGFloat kPaginationOffset = 400;
// Height for the Discover Feed section header.
const CGFloat kDiscoverFeedFeaderHeight = 30;
}
......@@ -697,7 +697,15 @@ NSString* const kContentSuggestionsMostVisitedAccessibilityIdentifierPrefix =
if (IsDiscoverFeedEnabled() && self.contentSuggestionsEnabled) {
float scrollPosition =
scrollView.contentOffset.y + scrollView.frame.size.height;
if (scrollPosition >= scrollView.contentSize.height - kPaginationOffset) {
// Check if view is bouncing to ignore overscoll positions for infinite feed
// triggering.
BOOL isBouncing =
(scrollView.contentOffset.y >=
(scrollView.contentSize.height - scrollView.bounds.size.height));
ContentSuggestionsLayout* layout = static_cast<ContentSuggestionsLayout*>(
self.collectionView.collectionViewLayout);
if (scrollPosition > scrollView.contentSize.height - kPaginationOffset &&
scrollPosition > layout.ntpHeight && !isBouncing) {
[self.handler loadMoreFeedArticles];
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment