Commit d806f0b1 authored by gogerald's avatar gogerald Committed by Commit Bot

[StartSurface] Scroll single pane header together with the feed surface view

Layout resource is used to set filling the viewport.

Screenshots:
https://drive.google.com/file/d/1Cp37OzJNp_b6qf7PLJ9wlwzVkAeqFlbg/view?usp=sharing
https://drive.google.com/file/d/1TzXKP9YHv3tgx-_m5rJKVyc791mHt8aa/view?usp=sharing

Bug: 982018
Change-Id: Icb0e1366a1e95fad6f7ce1c48c9e23d035dc8f1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1776858
Commit-Queue: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Auto-Submit: Ganggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692118}
parent 3611fb77
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2019 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:background="@color/modern_primary_color"
android:visibility="gone" />
......@@ -6,6 +6,8 @@ package org.chromium.chrome.features.start_surface;
import android.app.Activity;
import android.support.annotation.Nullable;
import android.support.v4.widget.NestedScrollView;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.ViewGroup;
......@@ -17,6 +19,7 @@ import org.chromium.chrome.browser.feed.FeedSurfaceCoordinator;
import org.chromium.chrome.browser.feed.StreamLifecycleManager;
import org.chromium.chrome.browser.offlinepages.OfflinePageBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.start_surface.R;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
......@@ -45,7 +48,12 @@ class ExploreSurfaceCoordinator implements FeedSurfaceCoordinator.FeedSurfaceDel
mActivity = activity;
mPropertyModelChangeProcessor = PropertyModelChangeProcessor.create(containerPropertyModel,
new ExploreSurfaceViewBinder.ViewHolder(parentView, headerContainerView),
new ExploreSurfaceViewBinder.ViewHolder(parentView,
headerContainerView == null
? null
: (NestedScrollView) LayoutInflater.from(activity).inflate(
R.layout.ss_explore_scroll_container, parentView, false),
headerContainerView),
ExploreSurfaceViewBinder::bind);
mFeedSurfaceCreator = new FeedSurfaceCreator() {
@Override
......
......@@ -11,6 +11,7 @@ import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.
import static org.chromium.chrome.features.start_surface.StartSurfaceProperties.TOP_BAR_HEIGHT;
import android.support.annotation.Nullable;
import android.support.v4.widget.NestedScrollView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
......@@ -23,15 +24,21 @@ import org.chromium.ui.modelutil.PropertyModel;
/** Binder for the explore surface. */
class ExploreSurfaceViewBinder {
/**
* The view holder holds the parent view and the header container view.
* The view holder holds the parent view, the possible scroll container and header container
* view.
*/
public static class ViewHolder {
public final ViewGroup parentView;
@Nullable
public final NestedScrollView scrollContainer;
@Nullable
public final ViewGroup headerContainerView;
ViewHolder(ViewGroup parentView, @Nullable ViewGroup headerContainerView) {
ViewHolder(ViewGroup parentView, @Nullable NestedScrollView scrollContainer,
@Nullable ViewGroup headerContainerView) {
assert (scrollContainer == null) == (headerContainerView == null);
this.parentView = parentView;
this.scrollContainer = scrollContainer;
this.headerContainerView = headerContainerView;
}
}
......@@ -54,10 +61,12 @@ class ExploreSurfaceViewBinder {
/**
* Set the explore surface visibility.
* Note that if the {@link ViewHolder.headerContainerView} is not null, the feed surface view is
* added to the {@link ViewHolder.headerContainerView}, then the {@link
* ViewHolder.headerContainerView} is added to the {@link ViewHolder.parentView}. This is for
* the alignment between {@link ViewHolder.headerContainerView} and the feed surface view to
* avoid another level of view hiearachy. If the {@link ViewHolder.headerContainerView} is null,
* added to the {@link ViewHolder.headerContainerView}. This is for the alignment between the
* {@link ViewHolder.headerContainerView} and the feed surface view to avoid another level of
* view hiearachy. Then {@link ViewHolder.headerContainerView} is added to {@link
* ViewHolder.scrollContainer}. This allows the {@link ViewHolder.headerContainerView} scrolls
* together with the feed surface view. Finally, we add the {@link ViewHolder.scrollContainer}
* to the {@link ViewHolder.parentView}. If the {@link ViewHolder.headerContainerView} is null,
* then the feed surface view is added to the {@link ViewHolder.parentView} directly.
* @param viewHolder The view holder holds the parent and possible the header container view.
* @param model The property model.
......@@ -68,14 +77,15 @@ class ExploreSurfaceViewBinder {
if (model.get(FEED_SURFACE_COORDINATOR) == null) return;
if (viewHolder.headerContainerView != null) {
if (viewHolder.headerContainerView.getParent() == null) {
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
if (viewHolder.scrollContainer.getParent() == null) {
viewHolder.scrollContainer.addView(viewHolder.headerContainerView);
FrameLayout.LayoutParams layoutParams =
(FrameLayout.LayoutParams) viewHolder.scrollContainer.getLayoutParams();
layoutParams.bottomMargin = model.get(BOTTOM_BAR_HEIGHT);
layoutParams.topMargin = model.get(TOP_BAR_HEIGHT);
viewHolder.parentView.addView(viewHolder.headerContainerView, layoutParams);
viewHolder.parentView.addView(viewHolder.scrollContainer);
}
viewHolder.headerContainerView.setVisibility(isShowing ? View.VISIBLE : View.GONE);
viewHolder.scrollContainer.setVisibility(isShowing ? View.VISIBLE : View.GONE);
}
View feedSurfaceView = model.get(FEED_SURFACE_COORDINATOR).getView();
......
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