Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Last active March 4, 2026 07:45
Show Gist options
  • Select an option

  • Save benigumocom/af7eeb806d347c8d7f0d076cb7b918f0 to your computer and use it in GitHub Desktop.

Select an option

Save benigumocom/af7eeb806d347c8d7f0d076cb7b918f0 to your computer and use it in GitHub Desktop.
Jetpack Compose Navigation3 - Destiination Nested sealed interface
@Serializable
sealed interface AppDestination {
val label: String
@get:DrawableRes val iconRes: Int
@Serializable
data object Home : AppDestination {
override val label = "Home"
override val iconRes = R.drawable.ic_home
}
@Serializable
data object Settings : AppDestination {
override val label = "Settings"
override val iconRes = R.drawable.ic_settings
}
@Serializable
data class Detail(val id: String) : AppDestination {
override val label = "Detail"
override val iconRes = R.drawable.ic_detail
}
}
NavHost(navController = navController, startDestination = AppDestination.Home) {
composable<AppDestination.Home> { HomeScreen() }
composable<AppDestination.Settings> { SettingsScreen() }
composable<AppDestination.Detail> { entry ->
val dest = entry.toRoute<AppDestination.Detail>()
DetailScreen(dest.id)
}
}
@benigumocom
Copy link
Author

Navigation3 時代の Destination 設計:sealed interface による型安全な実装パターンと使い分け
https://android.benigumo.com/20260304/navigation3-sealed-interface/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment