16
16
17
17
package com.duckduckgo.app.browser.omnibar
18
18
19
+ import android.annotation.SuppressLint
19
20
import android.content.Context
20
21
import android.util.AttributeSet
22
+ import android.view.Gravity
21
23
import android.view.View
22
24
import android.view.ViewGroup.MarginLayoutParams
23
25
import androidx.coordinatorlayout.widget.CoordinatorLayout
24
26
import com.duckduckgo.app.browser.R
25
27
import com.google.android.material.appbar.AppBarLayout
28
+ import com.google.android.material.snackbar.Snackbar
26
29
27
30
/*
28
31
* This custom behavior prevents the top omnibar from hiding everywhere except for the browser view (i.e. the autocomplete suggestions)
@@ -41,8 +44,11 @@ class TopAppBarBehavior(
41
44
)
42
45
}
43
46
47
+ @SuppressLint(" RestrictedApi" )
44
48
override fun layoutDependsOn (parent : CoordinatorLayout , child : AppBarLayout , dependency : View ): Boolean {
45
- if (! viewsExemptedFromOffset.contains(dependency.id)) {
49
+ if (dependency is Snackbar .SnackbarLayout ) {
50
+ updateSnackbar(child, dependency)
51
+ } else if (! viewsExemptedFromOffset.contains(dependency.id)) {
46
52
offsetBottomByToolbar(dependency)
47
53
}
48
54
@@ -65,6 +71,23 @@ class TopAppBarBehavior(
65
71
}
66
72
}
67
73
74
+ @SuppressLint(" RestrictedApi" )
75
+ private fun updateSnackbar (child : View , snackbarLayout : Snackbar .SnackbarLayout ) {
76
+ if (snackbarLayout.layoutParams is CoordinatorLayout .LayoutParams ) {
77
+ val params = snackbarLayout.layoutParams as CoordinatorLayout .LayoutParams
78
+
79
+ params.anchorId = R .id.navigationBar
80
+ params.anchorGravity = Gravity .TOP
81
+ params.gravity = Gravity .TOP
82
+ snackbarLayout.layoutParams = params
83
+
84
+ // add a padding to the snackbar to avoid it touching the anchor view
85
+ if (snackbarLayout.translationY == 0f ) {
86
+ snackbarLayout.translationY - = child.context.resources.getDimension(com.duckduckgo.mobile.android.R .dimen.keyline_2)
87
+ }
88
+ }
89
+ }
90
+
68
91
private fun offsetBottomByToolbar (view : View ? ) {
69
92
val omnibarHeight = omnibar.measuredHeight()
70
93
if (omnibarHeight > 0 && view is View && view.layoutParams is MarginLayoutParams ) {
0 commit comments