@@ -9,6 +9,8 @@ import android.view.MotionEvent
9
9
import android.view.View
10
10
import android.view.View.OnAttachStateChangeListener
11
11
import android.view.ViewTreeObserver.OnGlobalLayoutListener
12
+ import androidx.core.view.ViewCompat
13
+ import androidx.core.view.WindowInsetsCompat.Type
12
14
import androidx.core.view.doOnAttach
13
15
import androidx.lifecycle.DefaultLifecycleObserver
14
16
import androidx.lifecycle.LifecycleOwner
@@ -380,7 +382,16 @@ public class LayeredDialogSessions private constructor(
380
382
val attachStateChangeListener = object : OnAttachStateChangeListener {
381
383
val boundsListener = OnGlobalLayoutListener {
382
384
view.getScreenRect(boundsRect)
383
- if (boundsRect != boundsStateFlow.value) boundsStateFlow.value = Rect (boundsRect)
385
+ val type = Type .systemBars()
386
+ val insets = ViewCompat .getRootWindowInsets(view)?.getInsets(type)?.top
387
+ // If we managed to get insets, we only accept the bounds if it is below the insets.
388
+ // There are times that the reported bounds are above the insets or is negative ie) when
389
+ // the view is animating, and we don't want to accept those bounds.
390
+ if (boundsRect != boundsStateFlow.value &&
391
+ (insets == null || boundsRect.top >= insets)
392
+ ) {
393
+ boundsStateFlow.value = Rect (boundsRect)
394
+ }
384
395
}
385
396
386
397
override fun onViewAttachedToWindow (v : View ) {
0 commit comments