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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SectionHeaderViewHolder.java

Issue 2273713002: 📰Use the scroll offset to stop the card from peeking (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test Created 4 years, 4 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
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java ('k') | 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/snippets/SectionHeaderViewHolder.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SectionHeaderViewHolder.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SectionHeaderViewHolder.java
index 73e5fed4efaa4cddce005fd4e349fcc6bc8fcc8f..410ca3ab83d764264cf122fe84467d72dbce7adb 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SectionHeaderViewHolder.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SectionHeaderViewHolder.java
@@ -28,9 +28,6 @@
private SectionHeader mHeaderListItem;
- /** Can the header transition. */
- private boolean mCanTransition = false;
-
public SectionHeaderViewHolder(final NewTabPageRecyclerView recyclerView, UiConfig config) {
super(LayoutInflater.from(recyclerView.getContext())
.inflate(R.layout.new_tab_page_snippets_header, recyclerView, false));
@@ -48,43 +45,43 @@ public SectionHeaderViewHolder(final NewTabPageRecyclerView recyclerView, UiConf
@Override
public void onBindViewHolder(NewTabPageItem header) {
mHeaderListItem = (SectionHeader) header;
- updateDisplay();
- }
-
- /**
- * Set whether the header is in a state where the height can vary from show to hidden.
- */
- public void setCanTransition(boolean canTransition) {
- mCanTransition = canTransition;
+ mHeaderTextView.setText(mHeaderListItem.getHeaderText());
+ updateDisplay(0, false);
}
/**
* @return The header height we want to set.
*/
- private int getHeaderHeight() {
+ private int getHeaderHeight(int amountScrolled, boolean canTransition) {
if (!mHeaderListItem.isVisible()) return 0;
// If the header cannot transition but is visible - set the height to the maximum so
// it always displays
- if (!mCanTransition) return mMaxSnippetHeaderHeight;
+ if (!canTransition) return mMaxSnippetHeaderHeight;
// Check if snippet header top is within range to start showing. Set the header height,
// this is a percentage of how much is scrolled. The balance of the scroll will be used
// to display the peeking card.
- int amountScrolled = (mRecyclerView.getHeight() - mMaxPeekPadding) - itemView.getTop();
return MathUtils.clamp((int) (amountScrolled * SCROLL_HEADER_HEIGHT_PERCENTAGE),
0, mMaxSnippetHeaderHeight);
}
/**
* Update the view for the fade in/out and heading height.
+ * @param amountScrolled the number of pixels scrolled, or how far away from the bottom of the
+ * screen we got.
+ * @param canTransition whether we should animate the header sliding in. When {@code false},
+ * the header will always be fully visible.
*/
- public void updateDisplay() {
- mHeaderTextView.setText(mHeaderListItem.getHeaderText());
- int headerHeight = getHeaderHeight();
+ public void updateDisplay(int amountScrolled, boolean canTransition) {
+ int headerHeight = getHeaderHeight(amountScrolled, canTransition);
itemView.setAlpha((float) headerHeight / mMaxSnippetHeaderHeight);
getParams().height = headerHeight;
+
+ // This request layout is needed to let the rest of the elements know about the modified
+ // dimensions of this one. Otherwise scrolling fast can make the peeking card go completely
+ // below the fold for example.
itemView.requestLayout();
}
}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698