Skip to content

Commit b6403fb

Browse files
authored
Merge pull request #1155 from square/kabdulla/fix-reported-bounds-layered-dialog-sessions
Fix what bounds gets reported in layered dialog sessions
2 parents c67e204 + da3bd47 commit b6403fb

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/container/LayeredDialogSessions.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import android.view.MotionEvent
99
import android.view.View
1010
import android.view.View.OnAttachStateChangeListener
1111
import android.view.ViewTreeObserver.OnGlobalLayoutListener
12+
import androidx.core.view.ViewCompat
13+
import androidx.core.view.WindowInsetsCompat.Type
1214
import androidx.core.view.doOnAttach
1315
import androidx.lifecycle.DefaultLifecycleObserver
1416
import androidx.lifecycle.LifecycleOwner
@@ -380,7 +382,16 @@ public class LayeredDialogSessions private constructor(
380382
val attachStateChangeListener = object : OnAttachStateChangeListener {
381383
val boundsListener = OnGlobalLayoutListener {
382384
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+
}
384395
}
385396

386397
override fun onViewAttachedToWindow(v: View) {

0 commit comments

Comments
 (0)