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

Lilly

08/01/2022, 5:35 AM
I face a strange behavior when navigating to another screen (not using any navigation libraries). When I navigate from screen A -> B, it takes 2-4 seconds until B is displayed. In this time screen A is still displayed although the screen has already been disposed according to my logs:
Copy code
DisposableEffect(Unit) {
        onDispose { Log.e("ScreenA", "Leaving...") } // is logged immediately after call to navigate to screen B but screen A still visible
    }
I would at least expect an empty screen B immediately after this log. Any ideas? EDIT: logs in thread.
z

Zoltan Demant

08/01/2022, 5:48 AM
Are you using any animations?
l

Lilly

08/01/2022, 5:48 AM
No animations
On entering screen B I connect to a bluetooth device but this does not run on the main thread. But even without that call I get the delay ~4 seconds.
The first log indicates the call to navigate from A to B. The last call inidcates the point where screen B is actually displayed.
z

Zoltan Demant

08/01/2022, 6:54 AM
Can you share the code that holds Screen A and B (where the decision is made to now start rendering B)?
l

Lilly

08/01/2022, 7:39 AM
It's not known to you what is going on in my
Router
class but the logs tell us this isn't the bottleneck
z

Zoltan Demant

08/03/2022, 6:42 AM
Could you also please share how the content block of router looks like? I know you said that logs look alright, but I think thats where the issue sits. You could also create a separate sample, just using router and seeing if onDipose is called as expected when navigating around; that way you can filter out all the other composables quite easily 🙂
@Lilly Can you try replacing
override val current: T? get() = backStack.lastOrNull()
with
override val current: T? by derivedStateOf { backStack.lastOrNull() }
?
l

Lilly

08/04/2022, 9:12 AM
@Zoltan Demant I have replaced it and the transition to the other screen still takes 4 seconds. I can see how the viewModel operation of Screen B is already called while Screen A is still displayed. Meanwhile I also have tested another routing library: compose-router (zoltek) => same behavior.
z

Zoltan Demant

08/04/2022, 9:37 AM
@Lilly Gotcha. The same behavior happening w/ compose-router as well makes me think the issue is elsewhere, but from what youve shared I cant find anything that seems off. If youre able to share even more of the surrounding code, perhaps that can help. Otherwise perhaps someone with more compose knowledge than me can find the culprit!
l

Lilly

08/04/2022, 9:38 AM
Yeah I have to decompose it step by step. I will do this when I get some time and let u know. Thanks so far 🙂
3 Views