Commit af0808e4 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere Committed by Commit Bot

[Autofill Assistant] Fix Autofill Assistant animations

Change-Id: Id135016a32da62d3b573a0b10b7b238e63646b46
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1631285
Auto-Submit: Jordan Demeulenaere <jdemeulenaere@chromium.org>
Reviewed-by: default avatarClemens Arbesser <arbesser@google.com>
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Cr-Commit-Position: refs/heads/master@{#664296}
parent eeba5f27
......@@ -58,7 +58,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:animateLayoutChanges="true"
android:clipChildren="false"
android:clipToPadding="false" />
</org.chromium.chrome.browser.widget.FadingEdgeScrollView>
......
......@@ -7,6 +7,10 @@ package org.chromium.chrome.browser.autofill_assistant;
import android.app.Activity;
import android.content.Context;
import android.support.annotation.Nullable;
import android.transition.ChangeBounds;
import android.transition.Fade;
import android.transition.TransitionManager;
import android.transition.TransitionSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -29,6 +33,7 @@ import org.chromium.chrome.browser.autofill_assistant.infobox.AssistantInfoBoxCo
import org.chromium.chrome.browser.autofill_assistant.overlay.AssistantOverlayModel;
import org.chromium.chrome.browser.autofill_assistant.overlay.AssistantOverlayState;
import org.chromium.chrome.browser.autofill_assistant.payment.AssistantPaymentRequestCoordinator;
import org.chromium.chrome.browser.autofill_assistant.payment.AssistantPaymentRequestModel;
import org.chromium.chrome.browser.compositor.CompositorViewResizer;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
......@@ -40,6 +45,10 @@ import org.chromium.ui.modelutil.ListModel;
*/
class AssistantBottomBarCoordinator
implements CompositorViewResizer, AssistantPeekHeightCoordinator.Delegate {
private static final int FADE_OUT_TRANSITION_TIME_MS = 150;
private static final int FADE_IN_TRANSITION_TIME_MS = 150;
private static final int CHANGE_BOUNDS_TRANSITION_TIME_MS = 250;
private final AssistantModel mModel;
private final BottomSheetController mBottomSheetController;
private final AssistantBottomSheetContent mContent;
......@@ -54,6 +63,14 @@ class AssistantBottomBarCoordinator
private AssistantInfoBoxCoordinator mInfoBoxCoordinator;
private AssistantPaymentRequestCoordinator mPaymentRequestCoordinator;
// The transition triggered whenever the layout of the BottomSheet content changes.
private final TransitionSet mLayoutTransition =
new TransitionSet()
.setOrdering(TransitionSet.ORDERING_SEQUENTIAL)
.addTransition(new Fade(Fade.OUT).setDuration(FADE_OUT_TRANSITION_TIME_MS))
.addTransition(new ChangeBounds().setDuration(CHANGE_BOUNDS_TRANSITION_TIME_MS))
.addTransition(new Fade(Fade.IN).setDuration(FADE_IN_TRANSITION_TIME_MS));
private final ObserverList<CompositorViewResizer.Observer> mSizeObservers =
new ObserverList<>();
private boolean mResizeViewport;
......@@ -64,6 +81,14 @@ class AssistantBottomBarCoordinator
mBottomSheetController = controller;
mContent = new AssistantBottomSheetContent(activity);
// Set up animations. We need to setup them before initializing the child coordinators as we
// want our observers to be triggered before the coordinators/view binders observers.
// TODO(crbug.com/806868): We should only animate our BottomSheetContent instead of the root
// view. However, it looks like doing that is not well supported by the BottomSheet, so the
// BottomSheet offset is wrong during the animation.
ViewGroup rootView = (ViewGroup) controller.getBottomSheet().getRootView();
setupAnimations(model, rootView);
// Instantiate child components.
mHeaderCoordinator = new AssistantHeaderCoordinator(
activity, mContent.mBottomBarView, model.getHeaderModel());
......@@ -81,6 +106,11 @@ class AssistantBottomBarCoordinator
mContent.mToolbarView, mContent.mBottomBarView, mSuggestionsCoordinator.getView(),
mActionsCoordinator.getView(), AssistantPeekHeightCoordinator.PeekMode.HANDLE);
// We don't want to animate the carousels children views as they are already animated by the
// recyclers ItemAnimator, so we exclude them to avoid a clash between the animations.
mLayoutTransition.excludeChildren(mSuggestionsCoordinator.getView(), /* exclude= */ true);
mLayoutTransition.excludeChildren(mActionsCoordinator.getView(), /* exclude= */ true);
// Add child views to bottom bar container. We put all child views in the scrollable
// container, except the actions and suggestions.
mContent.mScrollableContentContainer.addView(mInfoBoxCoordinator.getView());
......@@ -171,6 +201,41 @@ class AssistantBottomBarCoordinator
});
}
private void setupAnimations(AssistantModel model, ViewGroup rootView) {
// Animate when the chip in the header changes.
model.getHeaderModel().addObserver((source, propertyKey) -> {
if (propertyKey == AssistantHeaderModel.CHIP
|| propertyKey == AssistantHeaderModel.CHIP_VISIBLE) {
animateChildren(rootView);
}
});
// Animate when info box changes.
model.getInfoBoxModel().addObserver((source, propertyKey) -> animateChildren(rootView));
// Animate when details change.
model.getDetailsModel().addObserver((source, propertyKey) -> animateChildren(rootView));
// Animate when a PR section is expanded.
model.getPaymentRequestModel().addObserver((source, propertyKey) -> {
if (propertyKey == AssistantPaymentRequestModel.EXPANDED_SECTION) {
animateChildren(rootView);
}
});
// Animate when form inputs change.
model.getFormModel().getInputsModel().addObserver(new AbstractListObserver<Void>() {
@Override
public void onDataSetChanged() {
animateChildren(rootView);
}
});
}
private void animateChildren(ViewGroup rootView) {
TransitionManager.beginDelayedTransition(rootView, mLayoutTransition);
}
private void maybeShowHeaderChip() {
boolean showChip = mBottomSheetController.getBottomSheet().getSheetState()
== BottomSheet.SheetState.PEEK
......
......@@ -17,7 +17,7 @@ import java.util.List;
public class AssistantFormModel {
private final ListModel<AssistantFormInput> mInputsModel = new ListModel<>();
ListModel<AssistantFormInput> getInputsModel() {
public ListModel<AssistantFormInput> getInputsModel() {
return mInputsModel;
}
......
......@@ -6,10 +6,6 @@ package org.chromium.chrome.browser.autofill_assistant.header;
import android.content.Context;
import android.support.annotation.Nullable;
import android.transition.ChangeBounds;
import android.transition.Fade;
import android.transition.TransitionManager;
import android.transition.TransitionSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupMenu;
......@@ -31,11 +27,6 @@ import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
class AssistantHeaderViewBinder
implements PropertyModelChangeProcessor.ViewBinder<AssistantHeaderModel,
AssistantHeaderViewBinder.ViewHolder, PropertyKey> {
private final TransitionSet mTransition = new TransitionSet()
.addTransition(new Fade(Fade.OUT))
.addTransition(new ChangeBounds())
.addTransition(new Fade(Fade.IN));
/**
* A wrapper class that holds the different views of the header.
*/
......@@ -90,7 +81,6 @@ class AssistantHeaderViewBinder
}
private void maybeShowChip(AssistantHeaderModel model, ViewHolder view) {
TransitionManager.beginDelayedTransition(view.mHeader, mTransition);
if (model.get(AssistantHeaderModel.CHIP_VISIBLE)
&& model.get(AssistantHeaderModel.CHIP) != null) {
view.mChip.getView().setVisibility(View.VISIBLE);
......@@ -109,8 +99,6 @@ class AssistantHeaderViewBinder
return;
}
TransitionManager.beginDelayedTransition(view.mHeader, mTransition);
int viewType = AssistantChipViewHolder.getViewType(chip);
// If there is already a chip in the header but with incompatible type, remove it.
......
......@@ -5,10 +5,6 @@
package org.chromium.chrome.browser.autofill_assistant.payment;
import android.content.Context;
import android.transition.ChangeBounds;
import android.transition.Fade;
import android.transition.TransitionManager;
import android.transition.TransitionSet;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
......@@ -29,14 +25,10 @@ import org.chromium.chrome.browser.widget.TintedDrawable;
* parameters for disambiguation, otherwise the child won't be added at all!
*/
public class AssistantVerticalExpander extends LinearLayout {
private static final int FADE_OUT_TRANSITION_TIME_MS = 150;
private static final int FADE_IN_TRANSITION_TIME_MS = 150;
private static final int CHANGE_BOUNDS_TRANSITION_TIME_MS = 250;
private final ViewGroup mTitleContainer;
private final ViewGroup mCollapsedContainer;
private final ViewGroup mExpandedContainer;
private final View mChevronButton;
private final TransitionSet mLayoutTransition;
private Callback<Boolean> mOnExpansionStateChangedListener;
private View mTitleView;
......@@ -49,14 +41,6 @@ public class AssistantVerticalExpander extends LinearLayout {
super(context, attrs);
setOrientation(VERTICAL);
mLayoutTransition = new TransitionSet();
mLayoutTransition.setOrdering(TransitionSet.ORDERING_SEQUENTIAL);
mLayoutTransition.addTransition(
new Fade(Fade.OUT).setDuration(FADE_OUT_TRANSITION_TIME_MS));
mLayoutTransition.addTransition(
new ChangeBounds().setDuration(CHANGE_BOUNDS_TRANSITION_TIME_MS));
mLayoutTransition.addTransition(new Fade(Fade.IN).setDuration(FADE_IN_TRANSITION_TIME_MS));
mTitleContainer = createChildContainer();
mChevronButton = createChevron();
mCollapsedContainer = createChildContainer();
......@@ -123,7 +107,6 @@ public class AssistantVerticalExpander extends LinearLayout {
return;
}
TransitionManager.beginDelayedTransition((ViewGroup) getRootView(), mLayoutTransition);
mExpanded = expanded;
mChevronButton.setScaleY(mExpanded ? -1 : 1);
update();
......
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