https://kotlinlang.org logo
#compose
Title
# compose
m

Michal Klimczak

08/24/2022, 12:31 PM
I have a weird issue with manual scroll invoking.
LazyListState.animateScrollToItem(0)
suspends indefinitely whenever I intercept the scroll animation by touching the list. Thus blocking the collection for any consecutive animations. Tried working around with
withTimeout
, but it seems like the
animateScrollToItem
animation loop has no way of supporting cancellation (no
yield
in the
while
loop).
👍 1
2
`launch`ing each
animateScrollToItem(0)
in a separate coroutine is a working hack, but it still leaves the broken coroutine hanging forever (memory leak)
compose 1.1.x, and 1.2.x
f

Filip Wiesner

08/24/2022, 1:29 PM
Just a wild guess, are you by any chance catching generic exceptions? In other words, is there a chance you accidentally catch
CancellationException
and don't rethrow it? 🤔
m

Michal Klimczak

08/24/2022, 2:06 PM
It's not that, there's a SharedFlow with collect and inside this collection there's just animateSceollToItem, no exception handling at all
f

Filip Wiesner

08/24/2022, 2:28 PM
And isn't the problem that you are calling it inside
SharedFlow
collector? If you intercept the scroll animation, the
animateScrollToItem
throws
CancellationException
and the
SharedFlow
collector will be cancelled, meaning that no other emit will be collected. So maybe it's not that it suspends forever but that there is no collector and you will not receive any value. I am not 100% sure. Just throwing ideas.
m

Michal Klimczak

08/24/2022, 3:02 PM
Hmm, this might be the case. I don't think I've seen any cancellation there but I light have missed it. So wrapping it in supervisorscope there would work. Or catching cancellation exception. Nice idea
That was exactly the problem, thank you Filip!
5 Views