Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix what bounds gets reported in layered dialog sessions #1155

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import android.view.MotionEvent
import android.view.View
import android.view.View.OnAttachStateChangeListener
import android.view.ViewTreeObserver.OnGlobalLayoutListener
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat.Type
import androidx.core.view.doOnAttach
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
Expand Down Expand Up @@ -380,7 +382,16 @@ public class LayeredDialogSessions private constructor(
val attachStateChangeListener = object : OnAttachStateChangeListener {
val boundsListener = OnGlobalLayoutListener {
view.getScreenRect(boundsRect)
if (boundsRect != boundsStateFlow.value) boundsStateFlow.value = Rect(boundsRect)
val type = Type.systemBars()
val insets = ViewCompat.getRootWindowInsets(view)?.getInsets(type)?.top
// If we managed to get insets, we only accept the bounds if it is below the insets.
// There are times that the reported bounds are above the insets or is negative ie) when
// the view is animating, and we don't want to accept those bounds.
if (boundsRect != boundsStateFlow.value &&
(insets == null || boundsRect.top >= insets)
) {
boundsStateFlow.value = Rect(boundsRect)
}
}

override fun onViewAttachedToWindow(v: View) {
Expand Down
Loading