'Insets in Android 11(API 30)

I'm getting insets using WindowManager, and in some contexts inset.top returns 0. Here's the way i'm getting WindowManager:

val Context.windowManager: WindowManager
    get() =  asActivity()?.windowManager ?: getSystemService(Context.WINDOW_SERVICE) as WindowManager


fun Context.asActivity(): Activity? {
    return when (this) {
        is Activity -> this
        is ContextWrapper -> baseContext.asActivity()
        else -> null
    }
}

While context comes from activity(fragment, dialog, etc.) all works fine(even in API30)? tested this in Android 12(API 31), and all works great, but on android 11 and when context comes from behaiviour(i've created custom one), it inset.top is 0, but bottom is correct. Really no ideas why it's going? already think that's bug in API 30



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source