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

vide

03/17/2023, 4:40 PM
I'm having a weird problem with nested AndroidViews: content inside AndroidViews doesn't render initially when the activity comes back from the background. A recomposition will trigger rendering again. EDIT: The problem is actually this:
View.onDraw
is never called for `AndroidView`s in my composition after
onResume
when activity comes back from background. Any ideas what could be causing this?
y

yschimke

03/17/2023, 6:07 PM
I don't have an answer, but is it all views inside the AndroidView or just some. Google Maps MapView has a bunch of lifecycle events that you used to have to wire up yourself when embedding in compose.
v

vide

03/17/2023, 6:08 PM
I'm seeing this on at least
SurfaceView
and
RecyclerView
. What makes it even more confusing is that it happens only on specific hardware, can't reproduce on emulator Actually I can, I was trying with a wrong API level...
(So everything inside AndroidView)
I also think there might be some kind of race condition involved as it only happens ~90% of the time. It might also be that there's some extra recomposition happening randomly that makes it work
Actually, no, recomposition doesn't seem to help. I added logging to the AndroidView's
update
block to confirm it is recomposing, but still no pixels on screen
Making some progress in investigating. It seems like
View.draw
is normally called soon after onResume:
Copy code
00:03:18.858  D  Main Activity onResume
00:03:18.887  W  Drawing to canvas.
However on my hardware the draw call never happens. No wonder nothing is rendered 😅
Okay, investigation complete! This is actually a filed bug: https://issuetracker.google.com/issues/244274006
I am using an older compose version so don't benefit of the fix, but I will implement something similar manually
l

louiscad

03/18/2023, 9:38 AM
Why don't you just update Compose UI?
6 Views