From c0b56b927fe30e7a702da5cd6224972967da568f Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Mon, 6 Jan 2020 16:24:27 +0100 Subject: [PATCH] Updated the material library back to alpha03 version The aforementioned fragment has fixed issue with layouts being oversized on API21 (maybe a bit lower and higher as well, did not test) which was notable on homepage. Unfortunately it deprecated most of the logic behind hiding of the top action view. Since it inherited and overridden the functionality from HideBottomViewOnScrollBehavior it no longer called the old methods and so the whole class was rendered _useless_. Fortunately we didn't need the whole backing implementation so the parent class was changed to the bare minimum. Hopefully this incident will not repeat. Thanks goes to material team for introducing breaking changes in feature update. --- app/build.gradle | 4 +-- .../utils/HideTopViewOnScrollBehavior.kt | 36 +++++++------------ 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 377e2c62d..f9d01ef3c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -121,7 +121,7 @@ dependencies { implementation "androidx.navigation:navigation-ui-ktx:${vNav}" implementation 'androidx.biometric:biometric:1.0.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha03' implementation 'androidx.browser:browser:1.0.0' implementation 'androidx.preference:preference:1.1.0' @@ -132,5 +132,5 @@ dependencies { implementation 'androidx.multidex:multidex:2.0.1' implementation 'androidx.core:core-ktx:1.2.0-rc01' // DO NOT UPDATE, 1.2.x has bunch of things broken in functionality against 1.1.x - implementation 'com.google.android.material:material:1.1.0-beta02' + implementation 'com.google.android.material:material:1.2.0-alpha03' } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/HideTopViewOnScrollBehavior.kt b/app/src/main/java/com/topjohnwu/magisk/utils/HideTopViewOnScrollBehavior.kt index 66e6701ff..6ce5f5af8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/HideTopViewOnScrollBehavior.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/HideTopViewOnScrollBehavior.kt @@ -4,23 +4,24 @@ import android.animation.TimeInterpolator import android.view.View import android.view.ViewGroup import android.view.ViewPropertyAnimator -import androidx.annotation.Dimension import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.view.ViewCompat import com.google.android.material.animation.AnimationUtils -import com.google.android.material.behavior.HideBottomViewOnScrollBehavior -class HideTopViewOnScrollBehavior : HideBottomViewOnScrollBehavior(), +class HideTopViewOnScrollBehavior : + CoordinatorLayout.Behavior(), HideableBehavior { companion object { private const val STATE_SCROLLED_DOWN = 1 private const val STATE_SCROLLED_UP = 2 + + private const val ENTER_ANIMATION_DURATION = 225 + private const val EXIT_ANIMATION_DURATION = 175 } private var height = 0 private var currentState = STATE_SCROLLED_UP - private var additionalHiddenOffsetY = 0 private var currentAnimator: ViewPropertyAnimator? = null private var lockState: Boolean = false @@ -34,26 +35,13 @@ class HideTopViewOnScrollBehavior : HideBottomViewOnScrollBehavior( return super.onLayoutChild(parent, child, layoutDirection) } - /** - * Sets an additional offset for the y position used to hide the view. - * - * @param child the child view that is hidden by this behavior - * @param offset the additional offset in pixels that should be added when the view slides away - */ - override fun setAdditionalHiddenOffsetY(child: V, @Dimension offset: Int) { - additionalHiddenOffsetY = offset - - if (currentState == STATE_SCROLLED_DOWN) { - child.translationY = (height + additionalHiddenOffsetY).toFloat() - } - } - override fun onStartNestedScroll( coordinatorLayout: CoordinatorLayout, child: V, directTargetChild: View, target: View, - nestedScrollAxes: Int + nestedScrollAxes: Int, + type: Int ) = nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL override fun onNestedScroll( @@ -63,7 +51,9 @@ class HideTopViewOnScrollBehavior : HideBottomViewOnScrollBehavior( dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, - dyUnconsumed: Int + dyUnconsumed: Int, + type: Int, + consumed: IntArray ) { // when initiating scroll while the view is at the bottom or at the top and pushing it // further, the parent will report consumption of 0 @@ -95,7 +85,7 @@ class HideTopViewOnScrollBehavior : HideBottomViewOnScrollBehavior( * Perform an animation that will slide the child from it's current position to be totally on the * screen. */ - override fun slideDown(child: V) { + private fun slideDown(child: V) { if (currentState == STATE_SCROLLED_UP || lockState) { return } @@ -118,7 +108,7 @@ class HideTopViewOnScrollBehavior : HideBottomViewOnScrollBehavior( * Perform an animation that will slide the child from it's current position to be totally off the * screen. */ - override fun slideUp(child: V) { + private fun slideUp(child: V) { if (currentState == STATE_SCROLLED_DOWN || lockState) { return } @@ -131,7 +121,7 @@ class HideTopViewOnScrollBehavior : HideBottomViewOnScrollBehavior( currentState = STATE_SCROLLED_DOWN animateChildTo( child, - -(height + additionalHiddenOffsetY), + -height, EXIT_ANIMATION_DURATION.toLong(), AnimationUtils.FAST_OUT_LINEAR_IN_INTERPOLATOR )