From 09f0ac866f0c387c18b35136c970cee50cc929cd Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Fri, 1 Oct 2021 20:13:00 +0700 Subject: [PATCH] Fix incorrect appbar lift state when opening MangaController in hidden state (#5990) --- .../appbar/HideToolbarOnScrollBehavior.kt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/google/android/material/appbar/HideToolbarOnScrollBehavior.kt b/app/src/main/java/com/google/android/material/appbar/HideToolbarOnScrollBehavior.kt index a6c9318812..1d5f01c002 100644 --- a/app/src/main/java/com/google/android/material/appbar/HideToolbarOnScrollBehavior.kt +++ b/app/src/main/java/com/google/android/material/appbar/HideToolbarOnScrollBehavior.kt @@ -77,6 +77,10 @@ class HideToolbarOnScrollBehavior : AppBarLayout.Behavior() { child: AppBarLayout, isVisible: Boolean ) { + val current = getTopBottomOffsetForScrollingSibling(child) + val target = if (isVisible) 0 else -toolbarHeight + if (current == target) return + offsetAnimator?.cancel() offsetAnimator = ValueAnimator().apply { interpolator = DecelerateInterpolator() @@ -85,18 +89,12 @@ class HideToolbarOnScrollBehavior : AppBarLayout.Behavior() { setHeaderTopBottomOffset(coordinatorLayout, child, it.animatedValue as Int) } doOnEnd { - if (!isVisible && - !child.isLifted && - (child as? ElevationAppBarLayout)?.isTransparentWhenNotLifted == true - ) { - child.isLifted = true + if ((child as? ElevationAppBarLayout)?.isTransparentWhenNotLifted == true) { + child.isLifted = !isVisible } } + setIntValues(current, target) + start() } - offsetAnimator?.setIntValues( - getTopBottomOffsetForScrollingSibling(child), - if (isVisible) 0 else -toolbarHeight - ) - offsetAnimator?.start() } }