This is bad, right? I'm trying to come up with wh...
# compose-android
c
This is bad, right? I'm trying to come up with why it's bad... and my brain is just melting as to why someone would try to call setContent in a scope.launch{}. Sort of similar as the one before this... is there any docs on when to call setContent{}?
h
Yeap, it's bad, you don't know the scope's context (but in this case you do know since it's probably main) but unnecessary launching something that's not blocking and doesn't need scope
c
so "unnecessary launching something that's not blocking and doesn't need scope on main"? or is the fact that its the main scope why it's working?
w
setContent literally just assigns a lambda, it's not tied to a thread or any work. It basically registers a State/snapshot write.
c
So I sorta lied (just for the sake of seeing if theres an issue with calling setContent in a launch block... but this is the actual offending code...
s
I think the issue here is that you're completing some work before setting the content, so as you add complexity and compute time to
getInstance
and
init
, your app will have longer and longer blank screens before it renders your actual content
c
yeah. in this case. i just joined this project. so im trying to clean a few things up here (like in my above question). its definitely "working" but written by someone that doesn't typically write compose code so it feels off. my main thing my bringing it up here is to see if theres any actual documented "guideliens" that are being broken.
s
Benchmarking the startup performance might be your best bet here. It's difficult to tell whether this actually impacts performance, or if it's nitpicking over coding standards
j
Is the App.getInstance returning something that can dynamically change “Content” being shown?
c
its not returning anything no. its just that Content() composable function live in the App class. and the Content() function reads a bunch of state in the App class (that should instead be passed in)
s
it is not necessarily wrong, you'll just get at least a frame without content view set
❤️ 1