From 481e6d9e2a687cc88ff93f0fe329b1db1b5eebd0 Mon Sep 17 00:00:00 2001 From: Floens Date: Thu, 25 Jan 2018 15:40:07 +0100 Subject: [PATCH] improve pin clicking animation jumping. --- .../chan/ui/controller/DrawerController.java | 5 ++++- .../java/org/floens/chan/ui/view/LoadView.java | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/DrawerController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/DrawerController.java index ffde7060..ebbb16a6 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/DrawerController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/DrawerController.java @@ -138,7 +138,10 @@ public class DrawerController extends Controller implements DrawerAdapter.Callba @Override public void onPinClicked(Pin pin) { - drawerLayout.closeDrawer(Gravity.LEFT); + // Post it to avoid animation jumping because the first frame is heavy. + // TODO: probably twice because of some force redraw, fix that. + drawerLayout.post(() -> drawerLayout.post(() -> drawerLayout.closeDrawer(drawer))); + ThreadController threadController = getTopThreadController(); threadController.openPin(pin); } diff --git a/Clover/app/src/main/java/org/floens/chan/ui/view/LoadView.java b/Clover/app/src/main/java/org/floens/chan/ui/view/LoadView.java index 176688dd..d505a125 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/view/LoadView.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/view/LoadView.java @@ -146,7 +146,20 @@ public class LoadView extends FrameLayout { animatorSet.setDuration(fadeDuration); animatorSet.playTogether(animators); - animatorSet.start(); + + final AnimatorSet currentAnimatorSet = animatorSet; + + // Postponing the animation to the next frame delays the animation until the heavy + // view setup is done. If you start the animation immediately, it will jump because + // the first frame is nowhere near 16ms. We rather have a bit of a delay instead of + // a broken jumping animation. + post(() -> { + // The AnimatorSet is replaced with a new one, if it was changed between the + // previous frame and now. + if (animatorSet == currentAnimatorSet) { + animatorSet.start(); + } + }); } else { // Fast forward possible pending animations (end, so also remove them). animatorSet.end();