Skip to content

Commit d41b35b

Browse files
author
Melih Aksoy
committed
Using SnackbarBehaviour for pushing list when there's an error
Using SnackbarBehaviour for pushing list when there's an error
1 parent 4993c5e commit d41b35b

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

core/src/main/kotlin/com/melih/core/utils/SnackbarBehaviour.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@ import android.content.Context
44
import android.util.AttributeSet
55
import android.view.View
66
import androidx.coordinatorlayout.widget.CoordinatorLayout
7-
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
87
import com.google.android.material.snackbar.Snackbar
98

9+
/**
10+
* Simple behaviour for pushing views when snackbar is animating so none of views will remain under snackbar
11+
*/
1012
class SnackbarBehaviour constructor(
1113
context: Context,
1214
attributeSet: AttributeSet
13-
) : CoordinatorLayout.Behavior<SwipeRefreshLayout>() {
15+
) : CoordinatorLayout.Behavior<View>() {
1416

15-
override fun layoutDependsOn(parent: CoordinatorLayout, child: SwipeRefreshLayout, dependency: View): Boolean =
17+
override fun layoutDependsOn(parent: CoordinatorLayout, child: View, dependency: View): Boolean =
1618
dependency is Snackbar.SnackbarLayout
1719

18-
override fun onDependentViewChanged(parent: CoordinatorLayout, child: SwipeRefreshLayout, dependency: View): Boolean {
20+
override fun onDependentViewChanged(parent: CoordinatorLayout, child: View, dependency: View): Boolean {
1921
val translationY = Math.min(0.0f, (dependency.translationY - dependency.height))
2022
child.translationY = translationY
2123
return true

features/list/src/main/res/layout/fragment_launches.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<layout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<layout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
34
xmlns:app="http://schemas.android.com/apk/res-auto"
45
xmlns:tools="http://schemas.android.com/tools">
56

@@ -17,7 +18,8 @@
1718
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
1819
android:id="@+id/swipeRefreshLayout"
1920
android:layout_width="match_parent"
20-
android:layout_height="match_parent">
21+
android:layout_height="match_parent"
22+
app:layout_behavior="com.melih.core.utils.SnackbarBehaviour">
2123

2224
<androidx.recyclerview.widget.RecyclerView
2325
android:id="@+id/rocketList"

0 commit comments

Comments
 (0)