Can I request if a Composable like my ImageView is...
# compose
s
Can I request if a Composable like my ImageView is visible or has disappeared? I have a image gallery grid with 1000+ photos and if my ImageView is visible I launch a coroutine so set and fetch a thumbnail to display. But if the user scrolls quickly trough the gallery I want to cancel the request for loading the thumbnail as it's not needed. I use
Copy code
rememberCoroutineScope()
but it looks like that "isActive" in the loading job still returns "true" even if it's not more on screen. To test that I have put into a delay of 1000ms. Is there something like "onDisappeared" that I can use to cancel my job? Or can I have that coroutineScope cancel the job automatic if it's no longer visible?
1
d
As far as i understood it the disposable effect onDispose is called only when the composable permanently leave the UI I'm not sure if scrolling out of view qualify for that. I didn't tested it tho'
s
Thank you both. You are correct. LaunchEffect.onDispose() will be called if a child view scrolls out of a grid and gets reused. It's not the same as being not visible, but it works for me. LaunchedEffect hat a coroutine inside that gets automaticly cancelled on dispose. Works also. There seems to be no real "disappeared", but it's good enough.