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

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

Issue 2106753002: Refine snap scrolling on the Cards New Tab Page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tidy code. Created 4 years, 6 months 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
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 e6f2003ecf5fc2304d299fb03663901130c0dc6e..f7ff60b8772160843bd67b7216fa4c17e19452c4 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
@@ -192,6 +192,18 @@ public class NewTabPageRecyclerView extends RecyclerView {
}
}
+ public boolean isPeekingCardVisible() {
+ return findFirstCard() != null;
+ }
+
+ public int getPeekingCardTop() {
+ return findFirstCard().itemView.getTop();
+ }
+
+ public int getPeekingCardHeight() {
+ return findFirstCard().itemView.getHeight();
+ }
+
/**
* Finds the first card in this RecyclerView.
* @return The viewholder for the first card or null if no card is available.
@@ -244,4 +256,31 @@ public class NewTabPageRecyclerView extends RecyclerView {
mCompensationHeight -= itemView.getHeight();
assert mCompensationHeight >= 0;
}
+
+ /**
+ * If the RecyclerView is currently scrolled to between regionStart and regionEnd, smooth scroll
+ * out of the region. flipPoint is the threshold used to decide which bound of the region to
+ * scroll to. It returns whether the view was scrolled.
+ */
+ public boolean scrollOutOfRegion(int regionStart, int flipPoint, int regionEnd) {
+ // This function is only called when we are using the RecyclerView.
+ final int currentScroll = computeVerticalScrollOffset();
+
+ if (currentScroll < regionStart || currentScroll > regionEnd) return false;
+
+ if (currentScroll < flipPoint) {
+ smoothScrollBy(0, regionStart - currentScroll);
+ } else {
+ smoothScrollBy(0, regionEnd - currentScroll);
+ }
+ return true;
+ }
+
+ /**
+ * If the RecyclerView is currently scrolled to between regionStart and regionEnd, smooth scroll
+ * out of the region to the nearest edge.
+ */
+ public boolean scrollOutOfRegion(int regionStart, int regionEnd) {
+ return scrollOutOfRegion(regionStart, (regionStart + regionEnd) / 2, regionEnd);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698