Skip to content

Commit

Permalink
[#352] Apply some code reviews changes: navigation & LaunchedEffect u…
Browse files Browse the repository at this point in the history
…sage
  • Loading branch information
luongvo committed Dec 15, 2022
1 parent 1928900 commit d709212
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ sealed class AppDestination(val route: String = "") {

object Home : AppDestination("home")

/**
* We can define route as "coin/details" without "coinId" parameter because we're passing it as argument already.
* So either passing "coinId" via arguments or passing it via route.
*
* We keep passing "coinId" in both route and arguments for this destination to give example of navigation concept
* about how to build a destination with parameters.
*/
object Second : AppDestination("second/{$KEY_ID}") {

override val arguments = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private fun NavGraphBuilder.composable(

private fun NavHostController.navigate(destination: AppDestination) {
when (destination) {
is AppDestination.Up -> popBackStack()
is AppDestination.Up -> navigateUp()
else -> navigate(route = destination.destination)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ fun HomeComposeScreen(
navigator: (destination: AppDestination) -> Unit
) {
val context = LocalContext.current
LaunchedEffect(Unit) {
LaunchedEffect(viewModel.error) {
viewModel.error.collect { error ->
val message = error.userReadableMessage(context)
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
}
}
LaunchedEffect(viewModel) {
LaunchedEffect(viewModel.navigator) {
viewModel.navigator.collect { destination -> navigator(destination) }
}

Expand Down

0 comments on commit d709212

Please sign in to comment.