I have a weird issue with manual scroll invoking. ...
# compose
m
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
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
It's not that, there's a SharedFlow with collect and inside this collection there's just animateSceollToItem, no exception handling at all
f
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
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!