I'm trying to figure out when the user visit a pag...
# compose
a
I'm trying to figure out when the user visit a page inside
HorizontalPager
and do some actions on visiting and leaving the page. So I put a
DisposableEffect
inside my page compose function and trying to achieve my requirement. But it seems that the
HorizontalPager
which is using
LazyRow
internally is loading offscreen pages. Do you know how to fix this issue? I know I can use pager state to figure out current page and move my logic to there, but I prefer to hold my logics inside the page content as it is also used somewhere else out of pager too. I also tried to use
itemSpacing
to force pages be fully offscreen but it didn't solve the problem.
y
It's by design, and generally anything using LaunchedEffect and DisposableEffect to understand being onscreen is broken. Not just pager, but navigation hosts also. They might render screen below.
I'd recommend passing in a flag for whether you are on screen, or similar.
a
Thank you Yuri