Skip to content

Commit

Permalink
workaround issue with dispatching window insets on Android API < 30 (f…
Browse files Browse the repository at this point in the history
…ixes #6030)
  • Loading branch information
westnordost committed Dec 1, 2024
1 parent 4b30199 commit 524c029
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.westnordost.streetcomplete.view

import android.content.Context
import android.os.Build
import android.os.Build.VERSION_CODES
import android.util.AttributeSet
import android.view.WindowInsets
import android.widget.RelativeLayout

class RelativeLayoutFix @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
) : RelativeLayout(context, attrs, defStyleAttr) {

// always dispatch window insets to children, see #6030
override fun dispatchApplyWindowInsets(insets: WindowInsets): WindowInsets {
if (Build.VERSION.SDK_INT >= VERSION_CODES.R) {
return super.dispatchApplyWindowInsets(insets)
} else {
for (i in 0 until childCount) {
getChildAt(i).dispatchApplyWindowInsets(insets)
}
return insets
}
}
}
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<de.westnordost.streetcomplete.view.RelativeLayoutFix xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
Expand Down Expand Up @@ -31,4 +31,4 @@
android:layout_height="match_parent"
android:clipChildren="false" />

</RelativeLayout >
</de.westnordost.streetcomplete.view.RelativeLayoutFix >

0 comments on commit 524c029

Please sign in to comment.