From b59e05c63eaab471cdd369dc3ec28f255e9bd849 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Tue, 22 Sep 2020 16:14:34 +0200 Subject: [PATCH] Added a check against view being initialized in its behavior The view will be simply hidden if not --- .../utils/HideBottomViewOnScrollBehavior.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/HideBottomViewOnScrollBehavior.kt b/app/src/main/java/com/topjohnwu/magisk/utils/HideBottomViewOnScrollBehavior.kt index d3009f56a..68aa24273 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/HideBottomViewOnScrollBehavior.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/HideBottomViewOnScrollBehavior.kt @@ -3,6 +3,7 @@ package com.topjohnwu.magisk.utils import android.view.View import android.view.ViewGroup import androidx.coordinatorlayout.widget.CoordinatorLayout +import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.core.view.updateLayoutParams import androidx.interpolator.view.animation.FastOutSlowInInterpolator @@ -15,10 +16,16 @@ class HideBottomViewOnScrollBehavior : HideBottomViewOnScrollBehavior< HideableBehavior { private var lockState: Boolean = false + private var isLaidOut = false override fun layoutDependsOn(parent: CoordinatorLayout, child: V, dependency: View) = super.layoutDependsOn(parent, child, dependency) or (dependency is Snackbar.SnackbarLayout) + override fun onLayoutChild(parent: CoordinatorLayout, child: V, layoutDirection: Int): Boolean { + isLaidOut = true + return super.onLayoutChild(parent, child, layoutDirection) + } + override fun onDependentViewChanged( parent: CoordinatorLayout, child: V, @@ -92,8 +99,15 @@ class HideBottomViewOnScrollBehavior : HideBottomViewOnScrollBehavior< } if (hide) { - slideDown(view) + // view is not laid out and drawn yet properly, so animation will not be attached + // hence we just simply hide the view + if (!isLaidOut) { + view.isGone = true + } else { + slideDown(view) + } } else { + view.isVisible = true slideUp(view) }