浏览代码

ui: Set window inset listener only once

On API 29 and lower seems like Android has a bug where it does not
dispatch window insets properly to sibling views:

https://github.com/streetcomplete/StreetComplete/issues/6030

The fix here is to... not set window inset handler on multiple views
simultaneously. Hopefully this fixes it.
Peter Cai 1 月之前
父节点
当前提交
b7fc164a3f
共有 1 个文件被更改,包括 7 次插入14 次删除
  1. 7 14
      app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardActivity.kt

+ 7 - 14
app-common/src/main/java/im/angry/openeuicc/ui/wizard/DownloadWizardActivity.kt

@@ -95,27 +95,20 @@ class DownloadWizardActivity : BaseEuiccAccessActivity() {
 
         val navigation = requireViewById<View>(R.id.download_wizard_navigation)
         val origHeight = navigation.layoutParams.height
+        val fragmentRoot = requireViewById<View>(R.id.step_fragment_container)
 
-        ViewCompat.setOnApplyWindowInsetsListener(navigation) { v, insets ->
+        ViewCompat.setOnApplyWindowInsetsListener(window.decorView.rootView) { _, insets ->
             val bars = insets.getInsets(
                 WindowInsetsCompat.Type.systemBars()
                     or WindowInsetsCompat.Type.displayCutout()
                     or WindowInsetsCompat.Type.ime()
             )
-            v.updatePadding(bars.left, 0, bars.right, bars.bottom)
-            val newParams = navigation.layoutParams
-            newParams.height = origHeight + bars.bottom
-            navigation.layoutParams = newParams
-            WindowInsetsCompat.CONSUMED
-        }
 
-        val fragmentRoot = requireViewById<View>(R.id.step_fragment_container)
-        ViewCompat.setOnApplyWindowInsetsListener(fragmentRoot) { v, insets ->
-            val bars = insets.getInsets(
-                WindowInsetsCompat.Type.systemBars()
-                    or WindowInsetsCompat.Type.displayCutout()
-            )
-            v.updatePadding(bars.left, bars.top, bars.right, 0)
+            fragmentRoot.updatePadding(bars.left, bars.top, bars.right, 0)
+            navigation.updatePadding(bars.left, 0, bars.right, bars.bottom)
+            val newNavParams = navigation.layoutParams
+            newNavParams.height = origHeight + bars.bottom
+            navigation.layoutParams = newNavParams
             WindowInsetsCompat.CONSUMED
         }
     }