Skip to content

Commit 3c73250

Browse files
committed
fix: use windowInsets for input method detection
1 parent 5249d8d commit 3c73250

File tree

1 file changed

+11
-3
lines changed
  • OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common

1 file changed

+11
-3
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common/DeviceUtils.kt

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ import android.app.Activity
44
import android.content.Context
55
import android.graphics.Rect
66
import android.net.ConnectivityManager
7+
import android.os.Build
78
import android.telephony.TelephonyManager
89
import android.util.DisplayMetrics
910
import android.view.View
11+
import androidx.core.view.WindowInsetsCompat
1012
import java.lang.ref.WeakReference
1113

1214
object DeviceUtils {
1315
private val MARGIN_ERROR_PX_SIZE = ViewUtils.dpToPx(24)
1416

1517
/**
1618
* Check if the keyboard is currently being shown.
17-
* Does not work for cases when keyboard is full screen.
1819
*/
1920
fun isKeyboardUp(activityWeakReference: WeakReference<Activity?>): Boolean {
2021
val metrics = DisplayMetrics()
@@ -28,8 +29,15 @@ object DeviceUtils {
2829
window.windowManager.defaultDisplay.getMetrics(metrics)
2930
}
3031
if (view != null) {
31-
val heightDiff = metrics.heightPixels - visibleBounds.bottom
32-
isOpen = heightDiff > MARGIN_ERROR_PX_SIZE
32+
isOpen =
33+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
34+
val imeInsets = view.rootWindowInsets
35+
imeInsets.isVisible(WindowInsetsCompat.Type.ime())
36+
} else {
37+
// Does not work for cases when keyboard is full screen for Android 9 and below
38+
val heightDiff = metrics.heightPixels - visibleBounds.bottom
39+
heightDiff > MARGIN_ERROR_PX_SIZE
40+
}
3341
}
3442
return isOpen
3543
}

0 commit comments

Comments
 (0)