[Bouncer] Reset y translation and alpha

When doing the appear animation, sometimes, the animation will not
complete. I am unable to repro reliably, but I have experienced the
behavior more than 3 times, and QA has seen it too.

I'm thinking that this code change will fix the issue, but it's not
guaranteed.

Bug: 228886154
Test: Manual
Change-Id: Ie6b138468e3f8ef3e27bc2e3249c0de13709ed57
This commit is contained in:
Aaron Liu
2022-04-19 15:21:15 +00:00
parent f08f61e9f9
commit 7d42430dc2

View File

@@ -181,10 +181,12 @@ public class AppearAnimationUtils implements AppearAnimationCreator<View> {
public void createAnimation(final View view, long delay, long duration, float translationY,
boolean appearing, Interpolator interpolator, final Runnable endRunnable) {
if (view != null) {
view.setAlpha(appearing ? 0f : 1.0f);
view.setTranslationY(appearing ? translationY : 0);
float targetAlpha = appearing ? 1f : 0f;
float targetTranslationY = appearing ? 0 : translationY;
view.setAlpha(1.0f - targetAlpha);
view.setTranslationY(translationY - targetTranslationY);
Animator alphaAnim;
float targetAlpha = appearing ? 1f : 0f;
if (view.isHardwareAccelerated()) {
RenderNodeAnimator alphaAnimRt = new RenderNodeAnimator(RenderNodeAnimator.ALPHA,
targetAlpha);
@@ -205,14 +207,21 @@ public class AppearAnimationUtils implements AppearAnimationCreator<View> {
}
});
}
if (endRunnable != null) {
alphaAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
alphaAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
// If Animation is canceled, we want to ensure UI is reset.
view.setAlpha(targetAlpha);
view.setTranslationY(targetTranslationY);
}
@Override
public void onAnimationEnd(Animator animation) {
if (endRunnable != null) {
endRunnable.run();
}
});
}
}
});
alphaAnim.start();
startTranslationYAnimation(view, delay, duration, appearing ? 0 : translationY,
interpolator);