amrelmasry
03/30/2023, 11:31 AMLaunchedEffect
seems to work, but is it guaranteed that it will be always called after the Drawing phase?
The doc on LaunchedEffect
says it will launch a job when it enters the Composition (so it should work in the first phase, right?), this gave me the impression that it doesn’t wait until the Drawing phase, but in reality it actually does for some reason, but not sure if this is guaranteed in all cases.
@Composable fun Example() {
val startTimestamp = System.currentTimeMillis()
Text("Hi)
LaunchedEffect(Unit) {
val endTimestamp = System.currentTimeMillis()
reportTime(endTimestamp - startTimestamp)
}
}
mohamed rejeb
03/30/2023, 12:02 PMdrawBehind
modifier to the text, The drawBehind
lambda should be executed on the Drawing phaseamrelmasry
03/30/2023, 12:37 PMdrawBehind
will always be called each time the Text
Composable is drawn (could be too much specially in animation for example), and I need to report the time only once, so I am trying to see if LaunchedEffect
will provide similar behaviour without the overhead.mohamed rejeb
03/30/2023, 2:09 PMdrawWithCache
it's going to be called again only if there is changes on the measured layoutamrelmasry
03/31/2023, 8:23 AM.drawWithCache {
// cached
onDrawWithContent {
// called every time it's getting drawn
}
}
amrelmasry
03/31/2023, 8:24 AMLaunchedEffect(state)
will wait until this state
is indeed drawn?