From d41b35b659f8abc00ca34e09bd45a112064c8f58 Mon Sep 17 00:00:00 2001 From: Melih Aksoy Date: Wed, 3 Jul 2019 11:48:08 +0200 Subject: [PATCH] Using SnackbarBehaviour for pushing list when there's an error Using SnackbarBehaviour for pushing list when there's an error --- .../kotlin/com/melih/core/utils/SnackbarBehaviour.kt | 10 ++++++---- .../list/src/main/res/layout/fragment_launches.xml | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/src/main/kotlin/com/melih/core/utils/SnackbarBehaviour.kt b/core/src/main/kotlin/com/melih/core/utils/SnackbarBehaviour.kt index 2528400..1bd4a28 100644 --- a/core/src/main/kotlin/com/melih/core/utils/SnackbarBehaviour.kt +++ b/core/src/main/kotlin/com/melih/core/utils/SnackbarBehaviour.kt @@ -4,18 +4,20 @@ import android.content.Context import android.util.AttributeSet import android.view.View import androidx.coordinatorlayout.widget.CoordinatorLayout -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import com.google.android.material.snackbar.Snackbar +/** + * Simple behaviour for pushing views when snackbar is animating so none of views will remain under snackbar + */ class SnackbarBehaviour constructor( context: Context, attributeSet: AttributeSet -) : CoordinatorLayout.Behavior() { +) : CoordinatorLayout.Behavior() { - override fun layoutDependsOn(parent: CoordinatorLayout, child: SwipeRefreshLayout, dependency: View): Boolean = + override fun layoutDependsOn(parent: CoordinatorLayout, child: View, dependency: View): Boolean = dependency is Snackbar.SnackbarLayout - override fun onDependentViewChanged(parent: CoordinatorLayout, child: SwipeRefreshLayout, dependency: View): Boolean { + override fun onDependentViewChanged(parent: CoordinatorLayout, child: View, dependency: View): Boolean { val translationY = Math.min(0.0f, (dependency.translationY - dependency.height)) child.translationY = translationY return true diff --git a/features/list/src/main/res/layout/fragment_launches.xml b/features/list/src/main/res/layout/fragment_launches.xml index 5835a11..c70a7c6 100644 --- a/features/list/src/main/res/layout/fragment_launches.xml +++ b/features/list/src/main/res/layout/fragment_launches.xml @@ -1,5 +1,6 @@ - @@ -17,7 +18,8 @@ + android:layout_height="match_parent" + app:layout_behavior="com.melih.core.utils.SnackbarBehaviour">