Fix FAB positioning
FAB placement was wrong for the traditional three-button navigation after the Material You migration. The bottom inset was applied twice.
This commit is contained in:
+1
-1
@@ -50,7 +50,7 @@ class AutomatedActionsActivity : AbstractBaseActivity() {
|
||||
editAction(null)
|
||||
}
|
||||
|
||||
findViewById<View>(R.id.inset_layout).setPaddingFromWindowInsets()
|
||||
findViewById<View>(R.id.inset_layout).setPaddingFromWindowInsets(bottom = false)
|
||||
listView.setPaddingFromWindowInsets()
|
||||
}
|
||||
|
||||
|
||||
@@ -120,8 +120,8 @@ class BarcodeActivity : AbstractBaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
findViewById<View>(R.id.inset_layout).setPaddingFromWindowInsets()
|
||||
imageView.doOnApplyWindowInsets { _, insets ->
|
||||
findViewById<View>(R.id.inset_layout).setPaddingFromWindowInsets(bottom = false)
|
||||
imageView.doOnApplyWindowInsets { _, insets, _ ->
|
||||
imageView.insets.set(insets)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ class DecodeActivity : AbstractBaseActivity() {
|
||||
labelView.visibility = View.GONE
|
||||
}
|
||||
|
||||
findViewById<View>(R.id.inset_layout).setPaddingFromWindowInsets()
|
||||
findViewById<View>(R.id.inset_layout).setPaddingFromWindowInsets(bottom = false)
|
||||
findViewById<View>(R.id.scroll_view).setPaddingFromWindowInsets()
|
||||
|
||||
initContentAndFab(justScanned)
|
||||
|
||||
@@ -187,7 +187,7 @@ class EncodeActivity : AbstractBaseActivity() {
|
||||
it.context.encode()
|
||||
}
|
||||
|
||||
findViewById<View>(R.id.inset_layout).setPaddingFromWindowInsets()
|
||||
findViewById<View>(R.id.inset_layout).setPaddingFromWindowInsets(bottom = false)
|
||||
findViewById<View>(R.id.scroll_view).setPaddingFromWindowInsets()
|
||||
}
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ class HistoryActivity : AbstractBaseActivity() {
|
||||
|
||||
progressView = findViewById(R.id.progress_view)
|
||||
|
||||
findViewById<View>(R.id.inset_layout).setPaddingFromWindowInsets()
|
||||
findViewById<View>(R.id.inset_layout).setPaddingFromWindowInsets(bottom = false)
|
||||
listView.setPaddingFromWindowInsets()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ class IgnoreCodesActivity : AbstractBaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
findViewById<View>(R.id.inset_layout).setPaddingFromWindowInsets()
|
||||
findViewById<View>(R.id.inset_layout).setPaddingFromWindowInsets(bottom = false)
|
||||
listView.setPaddingFromWindowInsets()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ class NetworkSuggestionsActivity : AbstractBaseActivity() {
|
||||
listView.emptyView = findViewById(R.id.no_suggestions)
|
||||
listView.adapter = suggestionArrayAdapter
|
||||
listView.setOnScrollListener(systemBarListViewScrollListener)
|
||||
findViewById<View>(R.id.inset_layout).setPaddingFromWindowInsets()
|
||||
findViewById<View>(R.id.inset_layout).setPaddingFromWindowInsets(bottom = false)
|
||||
listView.setPaddingFromWindowInsets()
|
||||
|
||||
findViewById<View>(R.id.remove).setOnClickListener {
|
||||
|
||||
@@ -45,7 +45,7 @@ class ProfilesActivity : AbstractBaseActivity() {
|
||||
addProfile()
|
||||
}
|
||||
|
||||
findViewById<View>(R.id.inset_layout).setPaddingFromWindowInsets()
|
||||
findViewById<View>(R.id.inset_layout).setPaddingFromWindowInsets(bottom = false)
|
||||
listView.setPaddingFromWindowInsets()
|
||||
}
|
||||
|
||||
|
||||
@@ -43,17 +43,22 @@ fun setPaddingFromWindowInsets(
|
||||
}
|
||||
}
|
||||
|
||||
fun View.setPaddingFromWindowInsets() {
|
||||
doOnApplyWindowInsets { v, insets -> v.setPadding(insets) }
|
||||
fun View.setPaddingFromWindowInsets(bottom: Boolean = true) {
|
||||
doOnApplyWindowInsets { v, insets, windowInsets ->
|
||||
if (!bottom) {
|
||||
insets.bottom = getImeBottomInsetWithoutSystemBars(windowInsets)
|
||||
}
|
||||
v.setPadding(insets)
|
||||
}
|
||||
}
|
||||
|
||||
// A slight variation of the idea from Google's Chris Banes to avoid
|
||||
// adding the toolbar height for every view that needs to be inset.
|
||||
// For the original post see here:
|
||||
// https://medium.com/androiddevelopers/windowinsets-listeners-to-layouts-8f9ccc8fa4d1
|
||||
fun View.doOnApplyWindowInsets(f: (View, Rect) -> Unit) {
|
||||
fun View.doOnApplyWindowInsets(f: (View, Rect, WindowInsetsCompat) -> Unit) {
|
||||
ViewCompat.setOnApplyWindowInsetsListener(this) { v, insets ->
|
||||
f(v, insetsWithToolbar(insets))
|
||||
f(v, insetsWithToolbar(insets), insets)
|
||||
insets
|
||||
}
|
||||
// It's important to explicitly request the insets (again) in
|
||||
@@ -70,6 +75,11 @@ private fun insetsWithToolbar(insets: WindowInsetsCompat? = null) = Rect(
|
||||
insets?.systemWindowInsetBottom ?: 0
|
||||
)
|
||||
|
||||
private fun getImeBottomInsetWithoutSystemBars(insets: WindowInsetsCompat) =
|
||||
(insets.getInsets(WindowInsetsCompat.Type.ime()).bottom -
|
||||
insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom)
|
||||
.coerceAtLeast(0)
|
||||
|
||||
private fun View.requestApplyInsetsWhenAttached() {
|
||||
if (isAttachedToWindow) {
|
||||
ViewCompat.requestApplyInsets(this)
|
||||
|
||||
Reference in New Issue
Block a user