Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save benigumocom/22d6bfd3d3498537e6c96459fe393bd1 to your computer and use it in GitHub Desktop.
Jetpack Compose Navigation3 - Destiination sealed interface
@Serializable
sealed interface AppDestination {
val label: String
@get:DrawableRes val iconRes: Int
}
@Serializable
data object HomeDestination : AppDestination {
override val label = "Home"; override val iconRes = R.drawable.ic_home
}
@Serializable
data class DetailDestination(val id: String) : AppDestination {
override val label = "Detail"; override val iconRes = R.drawable.ic_detail
}
NavHost(navController = navController, startDestination = HomeDestination) {
composable<HomeDestination> { HomeScreen() }
composable<DetailDestination> { entry ->
val dest = entry.toRoute<DetailDestination>()
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