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

Zoltan Demant

12/13/2021, 5:50 PM
Are there any known issues with compose on Android 12? Ive received a few super-strange reports where ui actions have ~1 second delay; e.g. typing text in an input field has a 1 second delay between letters, etc. In all other cases, all of this happens instantaneously.
c

Casey Brooks

12/13/2021, 5:52 PM
Are you launching any coroutines in your composable's
rememberCoroutineScope()
? That scope by default runs on
Dispatchers.Main.immediate
, so any long-running work on it would block UI rendering and event dispatching, and it should be moved to another dispatcher
z

Zoltan Demant

12/13/2021, 6:21 PM
I do use it as the overall scope so that operations stop whenever the compose-scope is cancelled, but I make sure that all background work runs on
Dispatchers.Default/IO
(and I just verified thats the case).
r

Rick Regan

12/14/2021, 1:59 AM
I have performance issues with
Crossfade
on Android 12, though that doesn't sound like it's related to your problem: https://issuetracker.google.com/u/1/issues/207107680
z

Zoltan Demant

12/14/2021, 5:35 AM
@Rick Regan Thank you, its hard to tell if its the same underlying issue - but your screen recordings look exactly like what Im seeing, and I do use
Crossfade
a lot. Is this local to
Crossfade
only, or does a similar thing happen with
AnimatedContent
for you as well?
r

Rick Regan

12/14/2021, 12:04 PM
I don't use `AnimatedContent`; in fact,
Crossfade
is the only animation I (explicitly) use.
z

Zoltan Demant

12/14/2021, 12:15 PM
@Rick Regan Got it. I just got a response about the delay being fixed after having switched to
AnimatedContent
, so thats a good sign! Thank you so much for bringing this to my attention. Im still seeing some lag on Android 12, but I think thats internal components using the broken animations, likely the same thing that
Crossfade
uses.
r

Rick Regan

12/14/2021, 12:31 PM
Can you share more detail on the "delay being fixed after having switched to 
AnimatedContent
?
z

Zoltan Demant

12/14/2021, 12:34 PM
Delay/Lag 🙂 Same thing that you showed in your screen-recordings.
r

Rick Regan

12/14/2021, 12:35 PM
Oh...I thought you meant you had a side channel with someone else 🙂
(@Doris Liu I wanted to make you aware of the issue cited above. Thank you.)
z

Zoltan Demant

12/14/2021, 12:43 PM
Oh snap, the response I was referring to is from a user of my app - I cant recreate these issues locally, so thankfully there are people out there who are happy to help :)
r

Rick Regan

12/14/2021, 1:12 PM
I never really looked into`AnimatedContent` so it's interesting to learn that it's a "drop-in replacement" for
Crossfade
. (Although the doc page I am looking at calls it "experimental".) I will try it out.
z

Zoltan Demant

12/14/2021, 1:23 PM
Ridiculously simplified probably, but I think of
Crossfade
like an
AnimatedContent
that just uses
fadeIn
and
fadeOut
.
r

Rick Regan

12/14/2021, 1:49 PM
Funny,
AnimatedContent
made the example in my issue much slower (both API 31 and 30). Although, I'm not 100% sure I'm comparing them correctly (for
Crossfade
I used 
animationSpec = tween(10)
and for 
AnimatedContent
 I used
Copy code
transitionSpec = {
  fadeIn(animationSpec = tween(5)) with
      fadeOut(animationSpec = tween(5))
},
(the low
tween
times was just to factor that out of the issue.)
z

Zoltan Demant

12/14/2021, 2:25 PM
Do you see the same behavior if you use something like a
Text
? Ive noticed that buttons do something when animating their enabled/disabled state, Im curious if something in there is related to this as well.
r

Rick Regan

12/14/2021, 2:44 PM
Still slow with `Text`s instead of `Button`s (both
Crossfade
and
AnimatedContent
, with
AnimatedContent
still slower).
z

Zoltan Demant

12/14/2021, 3:18 PM
Hopefully well find the answers soon enough! Have you tried running this on a real device too?
r

Rick Regan

12/14/2021, 3:54 PM
The
Crossfade
version I had, yes, and I saw it there too.
👍🏽 1
d

Doris Liu

12/14/2021, 10:12 PM
@Rick Regan Do you see any difference in performance between 30 & 31 when using
AnimatedContent
with
Copy code
slideIntoContainer(AnimatedContentScope.SlideDirection.Left) with slideOutOfContainer(AnimatedContentScope.SlideDirection.Left)
instead of fade? That might help narrow down the issue here.
r

Rick Regan

12/14/2021, 11:44 PM
I posted an update (with videos) to the issue (31 is much slower).
👍🏽 1