Commit 2621fe78 authored by Mei Liang's avatar Mei Liang Committed by Commit Bot

Shrink tab to the correct position in GTS animation

http://crrev.com/c/2149626 converts the LayoutTab to a PropertyModel and
uses the constant start and end animation value when creating the
CompositorAnimator for the shrink tab animation. The use of the constant
values causes the shrinking tab animates to a wrong position, since the
targeted Rect can be changed after the CompositorAnimator is created.
This CL fixes the issue by using the Supplier to supply the start and
end value.

Change-Id: Ife607faa06aadd508816179ad856eadacc3e1e90
Bug: 1096718
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2254715Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Commit-Queue: Mei Liang <meiliang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782130}
parent f27cd421
......@@ -300,14 +300,23 @@ public class StartSurfaceLayout extends Layout implements StartSurface.OverviewM
Collection<Animator> animationList = new ArrayList<>(5);
// Step 1: zoom out the source tab
Supplier<Float> scaleStartValueSupplier = () -> 1.0f;
Supplier<Float> scaleEndValueSupplier = () -> target.get().width() / (getWidth() * mDpToPx);
Supplier<Float> xStartValueSupplier = () -> 0f;
Supplier<Float> xEndValueSupplier = () -> target.get().left / mDpToPx;
Supplier<Float> yStartValueSupplier = () -> 0f;
Supplier<Float> yEndValueSupplier = () -> target.get().top / mDpToPx;
animationList.add(CompositorAnimator.ofWritableFloatPropertyKey(handler, sourceLayoutTab,
LayoutTab.SCALE, 1.0f, target.get().width() / (getWidth() * mDpToPx),
ZOOMING_DURATION, Interpolators.FAST_OUT_SLOW_IN_INTERPOLATOR));
LayoutTab.SCALE, scaleStartValueSupplier, scaleEndValueSupplier, ZOOMING_DURATION,
Interpolators.FAST_OUT_SLOW_IN_INTERPOLATOR));
animationList.add(CompositorAnimator.ofWritableFloatPropertyKey(handler, sourceLayoutTab,
LayoutTab.X, 0f, target.get().left / mDpToPx, ZOOMING_DURATION,
LayoutTab.X, xStartValueSupplier, xEndValueSupplier, ZOOMING_DURATION,
Interpolators.FAST_OUT_SLOW_IN_INTERPOLATOR));
animationList.add(CompositorAnimator.ofWritableFloatPropertyKey(handler, sourceLayoutTab,
LayoutTab.Y, 0f, target.get().top / mDpToPx, ZOOMING_DURATION,
LayoutTab.Y, yStartValueSupplier, yEndValueSupplier, ZOOMING_DURATION,
Interpolators.FAST_OUT_SLOW_IN_INTERPOLATOR));
// TODO(crbug.com/964406): when shrinking to the bottom row, bottom of the tab goes up and
// down, making the "create group" visible for a while.
......
......@@ -210,15 +210,15 @@ public class CompositorAnimator extends Animator {
* @param handler The {@link CompositorAnimationHandler} responsible for running the animation.
* @param model The {@link PropertyModel} to modify.
* @param key The {@link WritableFloatPropertyKey} in the model to update.
* @param startValue The starting animation value.
* @param endValue The end animation value.
* @param startValue The {@link Supplier} of the starting animation value.
* @param endValue The {@link Supplier} of the end animation value.
* @param durationMs The duration of the animation in ms.
* @param interpolator The time interpolator for the animation.
* @return {@link CompositorAnimator} for animating the {@link WritableFloatPropertyKey}.
*/
public static CompositorAnimator ofWritableFloatPropertyKey(CompositorAnimationHandler handler,
final PropertyModel model, WritableFloatPropertyKey key, float startValue,
float endValue, long durationMs, TimeInterpolator interpolator) {
final PropertyModel model, WritableFloatPropertyKey key, Supplier<Float> startValue,
Supplier<Float> endValue, long durationMs, TimeInterpolator interpolator) {
CompositorAnimator animator = new CompositorAnimator(handler);
animator.setValues(startValue, endValue);
animator.setDuration(durationMs);
......@@ -227,6 +227,24 @@ public class CompositorAnimator extends Animator {
return animator;
}
/**
* Create a {@link CompositorAnimator} to animate the {@link WritableFloatPropertyKey}.
* @param handler The {@link CompositorAnimationHandler} responsible for running the animation.
* @param model The {@link PropertyModel} to modify.
* @param key The {@link WritableFloatPropertyKey} in the model to update.
* @param startValue The starting animation value.
* @param endValue The end animation value.
* @param durationMs The duration of the animation in ms.
* @param interpolator The time interpolator for the animation.
* @return {@link CompositorAnimator} for animating the {@link WritableFloatPropertyKey}.
*/
public static CompositorAnimator ofWritableFloatPropertyKey(CompositorAnimationHandler handler,
final PropertyModel model, WritableFloatPropertyKey key, float startValue,
float endValue, long durationMs, TimeInterpolator interpolator) {
return ofWritableFloatPropertyKey(
handler, model, key, () -> startValue, () -> endValue, durationMs, interpolator);
}
/**
* Create a {@link CompositorAnimator} to animate the {@link WritableFloatPropertyKey}.
* @param handler The {@link CompositorAnimationHandler} responsible for running the animation.
......
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