I have a bunch of dialog composables each of which...
# compose
m
I have a bunch of dialog composables each of which needs to perform a certain amount of work (currently executed in `LaunchedEffect`s within each composable) before the dialog can be fully drawn. This can result in jerkiness as the UI expands with new content. Obviously the composable could just delay (until work is done) when it draws anything but then you have an awkward delay. So I need to communicate back to the calling composable that some work is in progress. What is the best way to do this? 1️⃣ Add a callback argument (e.g.
onReady()
) to the dialog composable. The dialog composable will not emit any UI until this is called. The caller can show what it likes (e.g. indeterminate progress spinner) in the meantime 2️⃣ Change the API such that instead of a composable, the dialog is represented by a suspending function that returns a composable (e.g.
suspend fun showDialog(…): @Composable () -> Unit)
). An advantage here is that there is no danger of forgetting to call
onReady()
3️⃣ Too much logic in UI code, so shift the work to a view model which would be responsible for creating dialog UiState Something else?
1️⃣ 1
2️⃣ 1
3️⃣ 2
z
It sounds both like you’re trying to put too much into the view layer and fight against the natural data flow. I’d move this stuff a layer up, both more testable that way and you can defer the navigation until ready.
👆 1
m
Thanks @Zach Klippenstein (he/him) [MOD] So that sounds like option 3️⃣
z
Yea probably
m
Implemented 3️⃣ and it’s looking good. I also tried the other two ideas, and those worked out pretty terrible!