https://kotlinlang.org logo
s

Scott Kruse

08/13/2021, 11:29 PM
What is the best way to find out if a composable is visible on screen? Im familiar with getting window rect / running intersection logic for a view, checking View.visible, etc. Is there a different way in compose?
3
d

dambakk

10/09/2021, 12:48 PM
I think I found a kind of a solution to this. I noticed that a composable does not have a height until it is visible on the screen, like this:
Copy code
.onGloballyPositioned {
    isVisibleOnScreen = it.boundsInRoot().height > 0f
}
where
isVisibleOnScreen
is a remembered mutable state. Hope it helps!