Skip to content

You should not use collectAsState for navigation #38

@bigfarid

Description

@bigfarid

navigationManager.commands.collectAsState().value.also { command ->
if (command.destination.isNotEmpty()) {
navController.navigate(command.destination)
}
}

Can cause nullpointer exceptions on recomposition because the navgraph is not initialized yet. It shoudl be something like:
LaunchedEffect(navigationManager.commands){
navigationManager.commands.collect{ command ->
if (command.destination.isNotEmpty()) {
navController.navigate(command.destination)
}
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions