Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

You should not use collectAsState for navigation #38

Open
bigfarid opened this issue Nov 5, 2021 · 0 comments
Open

You should not use collectAsState for navigation #38

bigfarid opened this issue Nov 5, 2021 · 0 comments

Comments

@bigfarid
Copy link

bigfarid commented Nov 5, 2021

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)
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant