Fix issue with insets on API < 30.
This commit is contained in:
parent
e1c3583702
commit
dfcc14963d
2 changed files with 11 additions and 4 deletions
|
@ -1,6 +1,8 @@
|
|||
package org.thoughtcrime.securesms.util
|
||||
|
||||
import android.os.Build
|
||||
import android.view.View
|
||||
import androidx.core.graphics.Insets
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
|
@ -13,9 +15,9 @@ object SystemWindowInsetsSetter {
|
|||
*/
|
||||
fun attach(view: View, lifecycleOwner: LifecycleOwner, @WindowInsetsCompat.Type.InsetsType insetType: Int = WindowInsetsCompat.Type.systemBars()) {
|
||||
val listener = view.doOnEachLayout {
|
||||
val insets = ViewCompat.getRootWindowInsets(view)?.getInsets(insetType)
|
||||
val insets: Insets? = ViewCompat.getRootWindowInsets(view)?.getInsets(insetType)
|
||||
|
||||
if (insets != null) {
|
||||
if (Build.VERSION.SDK_INT > 29 && insets != null && !insets.isEmpty()) {
|
||||
view.setPadding(
|
||||
insets.left,
|
||||
insets.top,
|
||||
|
@ -40,4 +42,8 @@ object SystemWindowInsetsSetter {
|
|||
|
||||
lifecycleOwner.lifecycle.addObserver(lifecycleObserver)
|
||||
}
|
||||
|
||||
private fun Insets.isEmpty(): Boolean {
|
||||
return (top + bottom + right + left) == 0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.annotation.SuppressLint;
|
|||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -329,7 +330,7 @@ public final class ViewUtil {
|
|||
|
||||
public static int getStatusBarHeight(@NonNull View view) {
|
||||
final WindowInsetsCompat rootWindowInsets = ViewCompat.getRootWindowInsets(view);
|
||||
if (rootWindowInsets != null) {
|
||||
if (Build.VERSION.SDK_INT > 29 && rootWindowInsets != null) {
|
||||
return rootWindowInsets.getInsets(WindowInsetsCompat.Type.statusBars()).top;
|
||||
} else {
|
||||
int result = 0;
|
||||
|
@ -343,7 +344,7 @@ public final class ViewUtil {
|
|||
|
||||
public static int getNavigationBarHeight(@NonNull View view) {
|
||||
final WindowInsetsCompat rootWindowInsets = ViewCompat.getRootWindowInsets(view);
|
||||
if (rootWindowInsets != null) {
|
||||
if (Build.VERSION.SDK_INT > 29 && rootWindowInsets != null) {
|
||||
return rootWindowInsets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom;
|
||||
} else {
|
||||
int result = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue