Commit da86fb19 authored by Becky Zhou's avatar Becky Zhou Committed by Commit Bot

[Feed] Fix toolbar is gone on toggled article section header

Update search box on content changed because OnScrolled might not be
called or the vertical offset might be be reliable.

Bug: 887628
Change-Id: I429b817abd44f1a8e66b616dfad5f190f6fd8822
Reviewed-on: https://chromium-review.googlesource.com/1238619
Commit-Queue: Becky Zhou <huayinz@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593387}
parent ba455a15
......@@ -127,7 +127,10 @@ class FeedNewTabPageMediator
};
stream.addScrollListener(mStreamScrollListener);
mStreamContentChangedListener = () -> mStreamContentChanged = true;
mStreamContentChangedListener = () -> {
mStreamContentChanged = true;
mSnapScrollHelper.resetSearchBoxOnScroll(true);
};
stream.addOnContentChangedListener(mStreamContentChangedListener);
boolean suggestionsVisible =
......
......@@ -39,8 +39,6 @@ import org.chromium.chrome.browser.widget.displaystyle.UiConfig;
public class NewTabPageView extends FrameLayout {
private static final String TAG = "NewTabPageView";
private final int mScrollToSuggestionsOffset;
private NewTabPageRecyclerView mRecyclerView;
private NewTabPageLayout mNewTabPageLayout;
......@@ -49,7 +47,6 @@ public class NewTabPageView extends FrameLayout {
private Tab mTab;
private SnapScrollHelper mSnapScrollHelper;
private UiConfig mUiConfig;
private Runnable mUpdateSearchBoxOnScrollRunnable;
private boolean mNewTabPageRecyclerViewChanged;
private int mSnapshotWidth;
......@@ -93,9 +90,6 @@ public class NewTabPageView extends FrameLayout {
public NewTabPageView(Context context, AttributeSet attrs) {
super(context, attrs);
mScrollToSuggestionsOffset =
getResources().getDimensionPixelSize(R.dimen.toolbar_height_no_shadow);
mRecyclerView = new NewTabPageRecyclerView(getContext());
// Don't attach now, the recyclerView itself will determine when to do it.
......@@ -150,7 +144,7 @@ public class NewTabPageView extends FrameLayout {
// Cancel any pending scroll update handling, a new one will be scheduled in
// onAnimationFinished().
mRecyclerView.removeCallbacks(mUpdateSearchBoxOnScrollRunnable);
mSnapScrollHelper.resetSearchBoxOnScroll(false);
return super.animateMove(holder, fromX, fromY, toX, toY);
}
......@@ -169,8 +163,7 @@ public class NewTabPageView extends FrameLayout {
if (viewHolder.itemView == mNewTabPageLayout) {
mNewTabPageLayout.setIsViewMoving(false);
}
mRecyclerView.removeCallbacks(mUpdateSearchBoxOnScrollRunnable);
mRecyclerView.post(mUpdateSearchBoxOnScrollRunnable);
mSnapScrollHelper.resetSearchBoxOnScroll(true);
}
});
......@@ -178,8 +171,6 @@ public class NewTabPageView extends FrameLayout {
OfflinePageBridge offlinePageBridge =
SuggestionsDependencyFactory.getInstance().getOfflinePageBridge(profile);
mUpdateSearchBoxOnScrollRunnable = mNewTabPageLayout::updateSearchBoxOnScroll;
initializeLayoutChangeListener();
mNewTabPageLayout.setSearchProviderInfo(searchProviderHasLogo, searchProviderIsGoogle);
......
......@@ -23,6 +23,7 @@ public class SnapScrollHelper {
private final NewTabPageManager mManager;
private final NewTabPageLayout mNewTabPageLayout;
private final Runnable mSnapScrollRunnable;
private final Runnable mUpdateSearchBoxOnScrollRunnable;
private final int mToolbarHeight;
private final int mSearchBoxTransitionLength;
......@@ -40,6 +41,7 @@ public class SnapScrollHelper {
mManager = manager;
mNewTabPageLayout = newTabPageLayout;
mSnapScrollRunnable = new SnapScrollRunnable();
mUpdateSearchBoxOnScrollRunnable = mNewTabPageLayout::updateSearchBoxOnScroll;
Resources res = newTabPageLayout.getResources();
mToolbarHeight = res.getDimensionPixelSize(R.dimen.toolbar_height_no_shadow)
......@@ -88,6 +90,18 @@ public class SnapScrollHelper {
mNewTabPageLayout.updateSearchBoxOnScroll();
}
/**
* Resets any pending callbacks to update the search box position, and add new callback to
* update the search box position if necessary. This is used whenever {@link #handleScroll()} is
* not reliable (e.g. when an item is dismissed, the items at the top of the viewport might not
* move, and onScrolled() might not be called).
* @param update Whether a new callback to update search box should be posted to {@link #mView}.
*/
public void resetSearchBoxOnScroll(boolean update) {
mView.removeCallbacks(mUpdateSearchBoxOnScrollRunnable);
if (update) mView.post(mUpdateSearchBoxOnScrollRunnable);
}
/**
* @param scrollPosition The scroll position that the snap scroll calculation is based on.
* @return The modified scroll position that accounts for snap scroll.
......
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