Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3891)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java

Issue 2579643003: NTP: the spacer may be larger than 0 for initial scroll below fold. (Closed)
Patch Set: Address review comments from bauerb. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java
index 1db039439303053043116bb0c0557a051b9ac763..e4673668ef55125a9d7bb568bd3dd8e858ad010d 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java
@@ -82,6 +82,9 @@ public class NewTabPageRecyclerView extends RecyclerView implements TouchDisable
/** Whether the above-the-fold left space for a peeking card to be displayed. */
private boolean mHasSpaceForPeekingCard;
+ /** Whether the above-the-fold view has ever been rendered. */
+ private boolean mHasRenderedAboveTheFoldView;
+
/**
* Constructor needed to inflate from XML.
*/
@@ -108,6 +111,19 @@ public class NewTabPageRecyclerView extends RecyclerView implements TouchDisable
res.getDimensionPixelSize(R.dimen.snippets_peeking_card_bounce_distance);
setHasFixedSize(true);
+
+ addOnChildAttachStateChangeListener(new OnChildAttachStateChangeListener() {
+ @Override
+ public void onChildViewAttachedToWindow(View view) {
+ if (view == mAboveTheFoldView) {
+ mHasRenderedAboveTheFoldView = true;
+ removeOnChildAttachStateChangeListener(this);
+ }
+ }
+
+ @Override
+ public void onChildViewDetachedFromWindow(View view) {}
+ });
}
public boolean isFirstItemVisible() {
@@ -207,8 +223,11 @@ public class NewTabPageRecyclerView extends RecyclerView implements TouchDisable
return 0;
}
- // We have enough items to fill the view, since the above-the-fold item is not even visible.
- if (firstVisiblePos > aboveTheFoldPosition) {
+ if (firstVisiblePos > aboveTheFoldPosition && mHasRenderedAboveTheFoldView) {
+ // We have enough items to fill the viewport, since we have scrolled past the
+ // above-the-fold item. We must check whether the above-the-fold view has been rendered
+ // at least once, because it's possible to skip right over it if the initial scroll
+ // position is not 0, in which case we may need the spacer to be taller than 0.
return 0;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698