### Configure Destination Properties Source: https://github.com/raamcosta/compose-destinations/wiki/Defining-Destinations Configure route, start destination status, navigation graph, argument delegation, deep links, and transition styles for a destination. This example demonstrates advanced configuration options. ```kotlin import androidx.compose.runtime.Composable import com.ramcosta.compose.destinations.DeepLink import com.ramcosta.compose.destinations.Destination import com.ramcosta.compose.destinations.FullRoute const val PROFILE_SCREEN_ROUTE = "profile/main" const val PROFILE_NAV_GRAPH = "profile" // Placeholder for the actual transition style class object ProfileScreenTransitions @Destination( route = PROFILE_SCREEN_ROUTE, start = true, navGraph = PROFILE_NAV_GRAPH, navArgsDelegate = ProfileScreenNavArgs::class, deepLinks = [DeepLink(uriPattern = "https://destinationssample.com/$FULL_ROUTE_PLACEHOLDER")], style = ProfileScreenTransitions::class ) @Composable fun ProfileScreen( navArgs: ProfileScreenNavArgs ) { //... Content of the profile screen } data class ProfileScreenNavArgs( val arg1: Long, val arg2: String ) ``` -------------------------------- ### Setup Animated NavHostEngine with Default Animations Source: https://github.com/raamcosta/compose-destinations/wiki/Styles-and-Animations Configure the `NavHostEngine` to handle animations, including default root animations and specific animations for nested graphs. Use `rememberAnimatedNavHostEngine` and pass `RootNavGraphDefaultAnimations` and `NestedNavGraphDefaultAnimations`. ```kotlin val navHostEngine = rememberAnimatedNavHostEngine( navHostContentAlignment = Alignment.TopCenter, rootDefaultAnimations = RootNavGraphDefaultAnimations.ACCOMPANIST_FADING, //default `rootDefaultAnimations` means no animations defaultAnimationsForNestedNavGraph = mapOf( NavGraphs.settings to NestedNavGraphDefaultAnimations( enterTransition = { fadeIn(animationSpec = tween(2000)) }, exitTransition = { fadeOut(animationSpec = tween(2000)) } ), NavGraphs.otherNestedGraph to NestedNavGraphDefaultAnimations.ACCOMPANIST_FADING ) // all other nav graphs not specified in this map, will get their animations from the `rootDefaultAnimations` above. ) ``` -------------------------------- ### Setup BottomSheetNavigator and DestinationsNavHost Source: https://github.com/raamcosta/compose-destinations/wiki/Styles-and-Animations Integrate `BottomSheetNavigator` with `rememberAnimatedNavController` and `DestinationsNavHost`. Wrap the `DestinationsNavHost` in a `ModalBottomSheetLayout` for proper rendering. ```kotlin val navController = rememberAnimatedNavController() val bottomSheetNavigator = rememberBottomSheetNavigator() navController.navigatorProvider += bottomSheetNavigator ModalBottomSheetLayout( bottomSheetNavigator = bottomSheetNavigator, //other configuration for you bottom sheet screens, like: sheetShape = RoundedCornerShape(16.dp), ) { //... DestinationsNavHost( navController = navController, //... ) } ``` -------------------------------- ### Basic DestinationsNavHost Setup Source: https://github.com/raamcosta/compose-destinations/wiki/NavHosts Use this as a base for all your screens. It internally calls Compose Navigation's NavHost but automatically adds all `@Destination` annotated Composables of a given NavGraph instance. If not specified, it defaults to NavGraphs.root. ```kotlin DestinationsNavHost(navGraph = NavGraphs.root) ``` -------------------------------- ### DestinationsNavHost with Customizations Source: https://github.com/raamcosta/compose-destinations/wiki/NavHosts Allows overriding default parameters like the navigation graph, modifier, start route, navigation engine, and navController. Useful for multiple top-level graphs, custom start destinations, or integrating animations. ```kotlin DestinationsNavHost( navGraph = NavGraphs.root, startRoute = "some_other_route", engine = rememberAnimatedNavHostEngine(), navController = rememberAnimatedNavController() ) ``` -------------------------------- ### Generated Destination Object Example Source: https://github.com/raamcosta/compose-destinations/wiki/Defining-Destinations An example of a generated `Destination` object for a `ProfileScreen`. It implements the `TypedDestination` interface and defines route, arguments, deep links, and content. ```kotlin object ProfileScreenDestination : TypedDestination { operator fun invoke( arg1: Long, arg2: String, ): Direction { //... } override val routeId = // override val route: String = "$routeId//..." override val arguments get() = listOf( navArgument("arg1") { //... }, navArgument("arg2") { //... } ) override val deepLinks get() = listOf( navDeepLink { //... } ) override val style = //... @Composable override fun DestinationScope.Content( dependenciesContainerBuilder: DependenciesContainerBuilder.() -> Unit ) { //... } override fun argsFrom(navBackStackEntry: NavBackStackEntry): ProfileScreenNavArgs { //... } override fun argsFrom(savedStateHandle: SavedStateHandle): ProfileScreenNavArgs { //... } } ``` -------------------------------- ### Configure DestinationsNavHost with Start Route Override Source: https://context7.com/raamcosta/compose-destinations/llms.txt The DestinationsNavHost composable hosts all destinations of a given NavHostGraphSpec. It wraps Compose Navigation's NavHost and automatically registers destinations. An optional 'start' override can be used for runtime-conditional start screens. ```kotlin @Composable fun App() { val navController = rememberNavController() val vm = activityViewModel() // Override start destination at runtime based on login state val startRoute = if (!vm.isLoggedIn) LoginScreenDestination else NavGraphs.root.defaultStartDirection DestinationsNavHost( navGraph = NavGraphs.root, navController = navController, start = startRoute, modifier = Modifier.fillMaxSize() ) } ``` -------------------------------- ### Configure a Navigation Destination with Custom Options Source: https://context7.com/raamcosta/compose-destinations/llms.txt Configure a destination with a custom route, mark it as the start destination, specify navigation arguments, deep links, and animation styles. Navigation arguments can be defined using a delegate class. ```kotlin const val PROFILE_ROUTE = "profile" @Destination( route = PROFILE_ROUTE, start = true, navArgs = ProfileScreenNavArgs::class, deepLinks = [DeepLink(uriPattern = "https://myapp.com/$FULL_ROUTE_PLACEHOLDER")], style = ProfileTransitions::class ) @Composable fun ProfileScreen( navArgs: ProfileScreenNavArgs, // receive the nav args delegate directly navigator: DestinationsNavigator ) { Text("User id: ${navArgs.userId}") } data class ProfileScreenNavArgs( val userId: Int, val groupName: String? = null // optional (nullable) argument ) ``` -------------------------------- ### Annotate Destination for Nested NavGraph Source: https://github.com/raamcosta/compose-destinations/wiki/Defining-your-navigation-graphs Assigns a destination to a specific navigation graph named 'settings'. The 'start = true' argument designates it as the starting point for that graph. ```kotlin @Destination( navGraph = "settings", start = true ) @Composable fun SettingsScreen() { /*...*/ } ``` -------------------------------- ### Multi-module KSP Configuration for Compose Destinations Source: https://context7.com/raamcosta/compose-destinations/llms.txt Configure KSP generation mode per module in multi-module projects. Use 'destinations' to expose destinations, 'navgraphs' to expose complete graphs, and 'singlemodule' (default) for single-module apps. This example shows how to configure a feature module to expose destinations and how a navigation module assembles graphs. ```kotlin // Feature module's build.gradle.kts — exposes destinations only ksp { arg("compose-destinations.mode", "destinations") arg("compose-destinations.moduleName", "feature_profile") } // Navigation/app module — assembles graphs from feature modules // Include external destinations into a graph via @ExternalDestination: @NavGraph annotation class ProfileGraph { @ExternalDestination(start = true) @ExternalDestination companion object Includes } // Configure generated files package name (any module): ksp { arg("compose-destinations.codeGenPackageName", "com.myapp.navigation.generated") } // Disable NavGraphs auto-generation for manual graph construction: ksp { arg("compose-destinations.generateNavGraphs", "false") } ``` -------------------------------- ### Destination Title Extension Property Source: https://github.com/raamcosta/compose-destinations/wiki/Defining-Destinations An example of an extension property `title` added to the `Destination` interface. This allows for a common way to retrieve string resource IDs for screen titles based on the specific destination. ```kotlin @get:StringRes val Destination.title get(): Int { return when (this) { GreetingScreenDestination -> R.string.greeting_screen ProfileScreenDestination -> R.string.profile_screen SettingsDestination -> R.string.settings_screen FeedDestination -> R.string.feed_screen ThemeSettingsDestination -> R.string.theme_settings_screen } } ``` -------------------------------- ### Define a Simple NavGraph Data Class Source: https://github.com/raamcosta/compose-destinations/wiki/Defining-your-navigation-graphs Represents a navigation graph with a route, start route, destinations, and nested graphs. Used for structuring navigation within your app. ```kotlin data class NavGraph( override val route: String, override val startRoute: Route, // Route is implemented by NavGraph and Destination val destinations: List, override val nestedNavGraphs: List = emptyList() ): NavGraphSpec { override val destinationsByRoute: Map = destinations.associateBy { it.route } } ``` -------------------------------- ### Define Nested Navigation Graph with @NavGraph Source: https://context7.com/raamcosta/compose-destinations/llms.txt Use the @NavGraph annotation on a custom annotation class to define a nested navigation graph. Destinations annotated with this custom annotation will be grouped into the resulting graph. Compile-time checks ensure exactly one start destination per graph. ```kotlin // Define a "settings" nested nav graph inside RootGraph @NavGraph annotation class SettingsGraph // Mark destinations as belonging to this nested graph @Destination(start = true) @Composable fun SettingsScreen(navigator: DestinationsNavigator) { /* ... */ } @Destination @Composable fun ThemeSettingsScreen() { /* ... */ } // Navigate to the nested graph itself (goes to its start destination): navigator.navigate(NavGraphs.settings) ``` -------------------------------- ### Basic Navigation with DestinationsNavigator Source: https://github.com/raamcosta/compose-destinations/wiki/Navigating Use `DestinationsNavigator.navigate` to navigate to a destination. Ensure you have a `DestinationsNavigator` instance available. ```kotlin navigator.navigate(GreetingScreenDestination) ``` -------------------------------- ### Vanilla `NavHost` Integration with Compose Destinations Source: https://context7.com/raamcosta/compose-destinations/llms.txt Integrate Compose Destinations with the standard Compose `NavHost` using provided extension functions. This allows for type-safe registration of generated `Destination` objects without needing `DestinationsNavHost`. ```kotlin val navController = rememberNavController() NavHost( navController = navController, startDestination = GreetingScreenDestination.route ) { composable(GreetingScreenDestination) { args, _ -> GreetingScreen(name = args.name) } composable(TaskScreenDestination) { args, navBackStackEntry -> TaskScreen(taskId = args.taskId, filter = args.filter) } // Dialog destination dialogComposable(DeleteConfirmationDialogDestination) { _, _ -> DeleteConfirmationDialog(/* ... */) } } ``` -------------------------------- ### Basic Navigation with NavController Source: https://github.com/raamcosta/compose-destinations/wiki/Navigating Use the `navigateTo` extension function on `NavController` for navigation. This is an alternative to `DestinationsNavigator`. ```kotlin navController.navigateTo(GreetingScreenDestination) ``` -------------------------------- ### Navigate with Arguments using NavController Source: https://github.com/raamcosta/compose-destinations/wiki/Navigating Use the `navigateTo` extension function with arguments on `NavController`. This mirrors the `DestinationsNavigator` approach for argument passing. ```kotlin navController.navigateTo(ProfileScreenDestination(id = 1)) ``` -------------------------------- ### Registering Destinations with Vanilla NavHost Source: https://github.com/raamcosta/compose-destinations/wiki/NavHosts Use this snippet to register destinations with a standard `NavHost` Composable. Replace `NavHost` with `AnimatedNavHost` and `composable` with `animatedComposable` if you are using the `animations-core` module. Ensure `NavGraph` generation is disabled if you manually define your graphs. ```kotlin NavHost( // Replace with AnimatedNavHost if you're using `animations-core` navController = navController, startDestination = GreetingScreenDestination.route, ) { // Replace with `animatedComposable` if you're using `animations-core` composable(GreetingScreenDestination) { args, navBackStackEntry -> GreetingScreen( arg1 = args.arg1, arg2 = args.arg2, //... ) } composable(SomeScreenWithoutNavigationArgsDestination) { navBackStackEntry -> //no args param if the destination doesn't have them SomeScreenWithoutNavigationArgs() } // Use `dialogComposable` if the destination has a `style = DestinationStyle.Dialog::class` or subclass // Use `bottomSheetComposable` if the destination has a `style = DestinationStyle.BottomSheet::class` } ``` -------------------------------- ### Disable NavGraphs Generation Source: https://github.com/raamcosta/compose-destinations/wiki/Code-generating-Configurations Disable the generation of the `NavGraphs` object by setting `compose-destinations.generateNavGraphs` to `false`. This config is intended for the default `"singlemodule"` mode and will cause `start` and `navGraph` parameters of the `@Destination` annotation to be ignored. ```kotlin ksp { arg("compose-destinations.generateNavGraphs", "false") } ``` -------------------------------- ### Configure DestinationsNavHost with Dependency Injection Source: https://context7.com/raamcosta/compose-destinations/llms.txt DestinationsNavHost accepts a dependenciesContainerBuilder to facilitate DI-style parameter injection for screens. This allows non-navigation parameters to be injected into destinations. ```kotlin // With dependenciesContainerBuilder — inject non-navigation parameters to all screens: DestinationsNavHost( navGraph = NavGraphs.root, dependenciesContainerBuilder = { dependency(myAnalyticsTracker) dependency(userRepositoryImpl) } ) ``` -------------------------------- ### Custom Animated Transitions for Destinations Source: https://context7.com/raamcosta/compose-destinations/llms.txt Create custom animated transitions by extending `DestinationStyle.Animated` and defining enter/exit/pop enter/pop exit transitions. Apply this style to a destination using the `style` parameter. ```kotlin object SlideInTransitions : DestinationStyle.Animated() { override val enterTransition: AnimatedContentTransitionScope.() -> EnterTransition? = { slideInHorizontally(initialOffsetX = { it }, animationSpec = tween(350)) } override val exitTransition: AnimatedContentTransitionScope.() -> ExitTransition? = { slideOutHorizontally(targetOffsetX = { -it }, animationSpec = tween(350)) } override val popEnterTransition: AnimatedContentTransitionScope.() -> EnterTransition? = { slideInHorizontally(initialOffsetX = { -it }, animationSpec = tween(350)) } override val popExitTransition: AnimatedContentTransitionScope.() -> ExitTransition? = { slideOutHorizontally(targetOffsetX = { it }, animationSpec = tween(350)) } } @Destination(style = SlideInTransitions::class) @Composable fun DetailScreen(navigator: DestinationsNavigator) { /* ... */ } ``` -------------------------------- ### Add KSP Plugin (Kotlin DSL) Source: https://github.com/raamcosta/compose-destinations/blob/main/README.md Apply the KSP plugin using Kotlin DSL syntax in your module-level build.gradle.kts file. The version should match your Kotlin version. ```gradle plugins { //... id("com.google.devtools.ksp") version "1.9.22-1.0.17" // Depends on your kotlin version } ``` -------------------------------- ### Add Core Dependencies (Groovy) Source: https://github.com/raamcosta/compose-destinations/blob/main/README.md Use this snippet to add the core Compose Destinations library and KSP processor in a Groovy build script. Include the bottom-sheet dependency for bottom sheet destination support. ```gradle implementation 'io.github.raamcosta.compose-destinations:core:' ksp 'io.github.raamcosta.compose-destinations:ksp:' // V2 only: for bottom sheet destination support, also add implementation 'io.github.raamcosta.compose-destinations:bottom-sheet:' ``` -------------------------------- ### Navigate with Arguments using DestinationsNavigator Source: https://github.com/raamcosta/compose-destinations/wiki/Navigating Pass arguments directly to the destination's invoke function when navigating. Default values are automatically included. ```kotlin navigator.navigate(ProfileScreenDestination(id = 1)) ``` -------------------------------- ### Add KSP Plugin (Groovy) Source: https://github.com/raamcosta/compose-destinations/blob/main/README.md Apply the KSP plugin using Groovy syntax in your module-level build.gradle file. The version should match your Kotlin version. ```gradle plugins { //... id 'com.google.devtools.ksp' version '1.9.22-1.0.17' // Depends on your kotlin version } ``` -------------------------------- ### Add KSP Plugin and Compose Destinations Dependencies Source: https://context7.com/raamcosta/compose-destinations/llms.txt Add the KSP plugin and core Compose Destinations library dependencies to your module's build.gradle.kts file. Ensure the KSP plugin version matches your Kotlin version. The bottom-sheet dependency is optional. ```kotlin plugins { id("com.google.devtools.ksp") version "1.9.22-1.0.17" // match your Kotlin version } dependencies { implementation("io.github.raamcosta.compose-destinations:core:") ksp("io.github.raamcosta.compose-destinations:ksp:") // Optional: bottom sheet destination support implementation("io.github.raamcosta.compose-destinations:bottom-sheet:") } ``` -------------------------------- ### Send Results with ResultBackNavigator Source: https://context7.com/raamcosta/compose-destinations/llms.txt Use ResultBackNavigator to send a result back to the previous destination. The sending screen declares ResultBackNavigator and calls navigateBack(result). Ensure type consistency between sender and recipient for compile-time safety. ```kotlin import androidx.compose.material3.AlertDialog import androidx.compose.material3.Button import androidx.compose.material3.Text import androidx.compose.runtime.Composable import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.DestinationStyle import com.ramcosta.composedestinations.resultБыack.NavResult import com.ramcosta.composedestinations.resultБыack.ResultBackNavigator import com.ramcosta.composedestinations.navigation.DestinationsNavigator import com.ramcosta.composedestinations.resultБыack.ResultRecipient // Sending screen: a dialog that returns a Boolean confirmation @Destination(style = DestinationStyle.Dialog::class) @Composable fun DeleteConfirmationDialog( resultNavigator: ResultBackNavigator // R = Boolean ) { AlertDialog( onDismissRequest = { resultNavigator.navigateBack(result = false) }, title = { Text("Delete item?") }, confirmButton = { Button(onClick = { resultNavigator.navigateBack(result = true) }) { Text("Delete") } }, dismissButton = { Button(onClick = { resultNavigator.navigateBack(result = false) }) { Text("Cancel") } } ) } // Receiving screen: listens for the result @Destination(start = true) @Composable fun ItemListScreen( navigator: DestinationsNavigator, resultRecipient: ResultRecipient ) { // Install listener — safe across recompositions resultRecipient.onNavResult { result -> when (result) { is NavResult.Canceled -> { /* dialog dismissed */ } is NavResult.Value -> if (result.value) deleteSelectedItem() } } Button(onClick = { navigator.navigate(DeleteConfirmationDialogDestination) }) { Text("Delete") } } ``` -------------------------------- ### Navigate to Destination with Typed Arguments Source: https://github.com/raamcosta/compose-destinations/blob/main/README.md Use the generated `[ComposableName]Destination` invoke method to navigate to a screen. This method accepts the correct typed arguments, ensuring type safety. ```kotlin @Destination(start = true) // sets this as the start destination of the "root" nav graph @Composable fun HomeScreen( navigator: DestinationsNavigator ) { /*...*/ navigator.navigate(ProfileScreenDestination(id = 7, groupName = "Kotlin programmers")) } ``` -------------------------------- ### Set Generated Files Package Name Source: https://github.com/raamcosta/compose-destinations/wiki/Code-generating-Configurations Configure the package name for generated files by providing the `compose-destinations.codeGenPackageName` argument to KSP. ```kotlin ksp { arg("compose-destinations.codeGenPackageName", "your.preferred.packagename") } ``` -------------------------------- ### Add Core Dependencies (Kotlin DSL) Source: https://github.com/raamcosta/compose-destinations/blob/main/README.md Use this snippet to add the core Compose Destinations library and KSP processor in a Kotlin DSL build script. Include the bottom-sheet dependency for bottom sheet destination support. ```kotlin implementation("io.github.raamcosta.compose-destinations:core:") ksp("io.github.raamcosta.compose-destinations:ksp:") // V2 only: for bottom sheet destination support, also add implementation("io.github.raamcosta.compose-destinations:bottom-sheet:") ``` -------------------------------- ### Send Result Back Source: https://github.com/raamcosta/compose-destinations/wiki/Navigating Call `navigateBack` on the `ResultBackNavigator` instance, passing the result. This also finishes the current screen. ```kotlin resultNavigator.navigateBack(result = true) ``` -------------------------------- ### DestinationsNavHost with Manual Composable Calls Source: https://github.com/raamcosta/compose-destinations/wiki/NavHosts Provides a scope to manually call specific Destination Composables within the provided navGraph. This is useful for passing non-navigation arguments that the library cannot automatically provide. ```kotlin DestinationsNavHost( navGraph = NavGraphs.root ) { manualComposableCallsBuilder -> manualComposableCallsBuilder.invoke( route = "some_route", arguments = listOf(navArg1, navArg2) ) } ``` -------------------------------- ### Deep Linking with FULL_ROUTE_PLACEHOLDER Source: https://context7.com/raamcosta/compose-destinations/llms.txt Use `FULL_ROUTE_PLACEHOLDER` in a deep link `uriPattern` to automatically expand to the destination's full route, including all navigation arguments. ```kotlin @Destination( route = "product", deepLinks = [DeepLink(uriPattern = "https://myapp.com/$FULL_ROUTE_PLACEHOLDER")] ) @Composable fun ProductScreen(productId: Int, category: String?) { /* ... */ } // uriPattern becomes: "https://myapp.com/product/{productId}?category={category}" ``` -------------------------------- ### Add Wear OS Core Dependency (Groovy) Source: https://github.com/raamcosta/compose-destinations/blob/main/README.md For Wear OS applications, replace the standard core dependency with this one to utilize Wear Compose Navigation internally. Refer to the provided link for further configuration steps. ```gradle implementation 'io.github.raamcosta.compose-destinations:wear-core:' ``` -------------------------------- ### Declare ResultBackNavigator for Sending Results Source: https://github.com/raamcosta/compose-destinations/wiki/Navigating Add a `ResultBackNavigator` parameter to a Composable to enable sending results back. The type argument specifies the result type. ```kotlin @Destination(style = AppDialog::class) @Composable fun GoToProfileConfirmation( resultNavigator: ResultBackNavigator ) {//...} ``` -------------------------------- ### Add Wear OS Core Dependency (Kotlin DSL) Source: https://github.com/raamcosta/compose-destinations/blob/main/README.md For Wear OS applications, replace the standard core dependency with this one to utilize Wear Compose Navigation internally. Refer to the provided link for further configuration steps. ```kotlin implementation("io.github.raamcosta.compose-destinations:wear-core:") ``` -------------------------------- ### Define Custom Profile Transitions Source: https://github.com/raamcosta/compose-destinations/wiki/Styles-and-Animations Subclass `DestinationStyle.Animated` to define custom enter, exit, pop enter, and pop exit transitions for specific destinations. Requires `io.github.raamcosta.compose-destinations:animations-core` dependency. ```kotlin @OptIn(ExperimentalAnimationApi::class) object ProfileTransitions : DestinationStyle.Animated { override fun AnimatedContentScope.enterTransition(): EnterTransition? { //... //... return when (initialState.navDestination) { GreetingScreenDestination -> slideInHorizontally( initialOffsetX = { 1000 }, animationSpec = tween(700) ) else -> null } } override fun AnimatedContentScope.exitTransition(): ExitTransition? { return when (targetState.navDestination) { GreetingScreenDestination -> slideOutHorizontally( targetOffsetX = { -1000 }, animationSpec = tween(700) ) else -> null } } override fun AnimatedContentScope.popEnterTransition(): EnterTransition? { return when (initialState.navDestination) { GreetingScreenDestination -> slideInHorizontally( initialOffsetX = { -1000 }, animationSpec = tween(700) ) else -> null } } override fun AnimatedContentScope.popExitTransition(): ExitTransition? { return when (targetState.navDestination) { GreetingScreenDestination -> slideOutHorizontally( targetOffsetX = { 1000 }, animationSpec = tween(700) ) else -> null } } } ``` -------------------------------- ### Configure Multi-Module Generation Modes Source: https://github.com/raamcosta/compose-destinations/wiki/Code-generating-Configurations For multi-module applications, configure the generation mode and module name using KSP arguments. `GENERATION_MODE_FOR_MODULE` can be set to `"destinations"`, `"navgraphs"`, or `"singlemodule"` (default). ```gradle ksp { arg("compose-destinations.mode", "[GENERATION_MODE_FOR_MODULE]") arg("compose-destinations.moduleName", "[YOUR_MODULE_NAME") } ``` -------------------------------- ### Annotate Screen with @Destination Source: https://github.com/raamcosta/compose-destinations/blob/main/README.md Annotate your screen composables with `@Destination` to mark them as navigation destinations. Specify the navigation graph they belong to. ```kotlin @Destination // sets this as a destination of the "root" nav graph @Composable fun ProfileScreen() { /*...*/ } ``` -------------------------------- ### Apply NavArgs Delegate to @Destination Source: https://github.com/raamcosta/compose-destinations/wiki/Destination-arguments Annotate your @Destination with `navArgsDelegate` pointing to your custom arguments data class. The generated `argsFrom` methods will then return this class. ```kotlin import com.ramcosta.composedestinations.annotation.Destination import androidx.navigation.NavBackStackEntry import androidx.navigation.NavArgs import android.os.Bundle import androidx.lifecycle.SavedStateHandle @Destination( navArgsDelegate = ProfileScreenNavArgs::class ) fun ProfileScreen() { /*...*/ } // Example of generated methods (implementation not shown) // override fun argsFrom(navBackStackEntry: NavBackStackEntry): ProfileScreenNavArgs { // //... // } // // override fun argsFrom(savedStateHandle: SavedStateHandle): ProfileScreenNavArgs { // //... // } ``` -------------------------------- ### Define Navigation Arguments with a Data Class Delegate Source: https://github.com/raamcosta/compose-destinations/wiki/Destination-arguments Use a data class to define navigation arguments when they are primarily used by a ViewModel. This avoids cluttering the Composable function signature. ```kotlin data class ProfileScreenNavArgs( val id: Long, val groupName: String? ) ``` -------------------------------- ### Apply Dialog Style to a Destination Source: https://github.com/raamcosta/compose-destinations/wiki/Styles-and-Animations Use the `style` argument in the `@Destination` annotation to apply the `DestinationStyle.Dialog`. ```kotlin @Destination(style = DestinationStyle.Dialog::class) @Composable fun SomeScreen() { /*...*/ } ``` -------------------------------- ### Navigate with DestinationsNavigator Source: https://context7.com/raamcosta/compose-destinations/llms.txt Use DestinationsNavigator to navigate between composable destinations. It supports various navigation actions like navigating to a new screen, navigating up, and popping the back stack. The navigator is automatically provided by the Compose Destinations library. ```kotlin import androidx.compose.foundation.layout.Column import androidx.compose.material3.Button import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.tooling.preview.Preview import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.navigation.DestinationsNavigator import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator @Destination(start = true) @Composable fun HomeScreen( navigator: DestinationsNavigator // injected by Compose Destinations ) { Column { // Navigate to a no-arg destination Button(onClick = { navigator.navigate(SettingsScreenDestination) }) { Text("Settings") } // Navigate with arguments Button(onClick = { navigator.navigate(ProfileScreenDestination(userId = 42, groupName = "Admins")) }) { Text("My Profile") } // Navigate with NavOptions builder — avoid duplicate navigation on rapid taps Button(onClick = { navigator.navigate(DetailScreenDestination(id = 1)) { launchSingleTop = true } }) { Text("Details") } // Pop back to a specific destination inclusively Button(onClick = { navigator.popBackStack(HomeScreenDestination, inclusive = false) }) { Text("Back to Home") } } } // For previews / unit tests — use the empty no-op navigator: @Preview @Composable fun HomeScreenPreview() { HomeScreen(navigator = EmptyDestinationsNavigator) } ``` -------------------------------- ### Define Deep Link with FULL_ROUTE_PLACEHOLDER Source: https://github.com/raamcosta/compose-destinations/wiki/Deep-Links Utilize `FULL_ROUTE_PLACEHOLDER` within the `uriPattern` to automatically include all destination arguments. This simplifies deep link configuration when arguments are part of the route. ```kotlin import androidx.compose.runtime.Composable import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.DeepLink import com.ramcosta.composedestinations.navigation.DestinationsNavigator @Destination( route = "user", deepLinks = [ DeepLink( uriPattern = "https://myapp.com/$FULL_ROUTE_PLACEHOLDER" ) ] ) @Composable fun UserScreen( navigator: DestinationsNavigator, id: Int ) ``` -------------------------------- ### Define Top-Level Navigation Graph with @NavHostGraph Source: https://context7.com/raamcosta/compose-destinations/llms.txt Use @NavHostGraph to define a top-level navigation graph suitable for DestinationsNavHost. Custom graphs can specify default transition animations. RootGraph is a pre-defined @NavHostGraph annotation provided by the library. ```kotlin // Custom top-level graph with default fade transitions @NavHostGraph(defaultTransitions = AppDefaultTransitions::class) annotation class AppGraph object AppDefaultTransitions : NavHostAnimatedDestinationStyle() { override val enterTransition = { fadeIn(tween(300)) } override val exitTransition = { fadeOut(tween(300)) } } // Use custom graph annotation on destinations @Destination(start = true) @Composable fun HomeScreen() { /* ... */ } // Pass the generated NavGraphs object to DestinationsNavHost DestinationsNavHost(navGraph = NavGraphs.app) ``` -------------------------------- ### BottomSheet Style Integration Source: https://context7.com/raamcosta/compose-destinations/llms.txt Utilize the built-in `DestinationStyle.BottomSheet` for bottom sheet destinations. Requires the bottom-sheet dependency and a wrapper around the app content. ```kotlin // ——— BottomSheet style (requires bottom-sheet dependency) ——— @Destination(style = DestinationStyle.BottomSheet::class) @Composable fun ColumnScope.FilterSheet(navigator: DestinationsNavigator) { /* ... */ } // Required wrapper around app content when using BottomSheet destinations: val bottomSheetNavigator = rememberBottomSheetNavigator() navController.navigatorProvider += bottomSheetNavigator ModalBottomSheetLayout(bottomSheetNavigator = bottomSheetNavigator) { DestinationsNavHost(navGraph = NavGraphs.root, navController = navController) } ``` -------------------------------- ### Consume Navigation Arguments in ViewModel with navArgs Source: https://context7.com/raamcosta/compose-destinations/llms.txt Declare navigation arguments in a data class and reference it via navArgs for consumption in a ViewModel. The generated destination provides argsFrom(SavedStateHandle) for this purpose. Navigate using type-safe invocations. ```kotlin data class StepScreenNavArgs( val stepId: Long, val taskId: Int ) @Destination(navArgs = StepScreenNavArgs::class) @Composable fun StepScreen( navigator: DestinationsNavigator, viewModel: StepDetailsViewModel = viewModel() // composable does not need to know about args ) { /* composable does not need to know about args */ } // In ViewModel — args retrieved from SavedStateHandle: class StepDetailsViewModel(savedStateHandle: SavedStateHandle) : ViewModel() { private val args = StepScreenDestination.argsFrom(savedStateHandle) val stepId = args.stepId val taskId = args.taskId } // Navigate with type-safe invocation: navigator.navigate(StepScreenDestination(stepId = 7L, taskId = 3)) ``` -------------------------------- ### Manually Calling Composable Destinations Source: https://github.com/raamcosta/compose-destinations/wiki/Destination-arguments Use `manualComposableCallsBuilder` within `DestinationsNavHost` to manually call specific `Destination` Composables. This allows passing custom parameters like `scaffoldState` that are not part of standard navigation arguments. The `DestinationsNavHost` will still manage navigation for other destinations. ```kotlin val scaffoldState = rememberScaffoldState() DestinationsNavHost( navGraph = NavGraphs.root ) { composable(SomeScreenDestination) { //this: DestinationScope SomeScreen( arg1 = navArgs.arg1, // navArgs is a lazily evaluated `SomeScreenDestination.NavArgs` instance, field of `DestinationScope` navigator = destinationsNavigator, // destinationsNavigator is a `DestinationsNavigator` (also lazily evaluated) backStackEntry = navBackStackEntry, // navBackStackEntry is a `DestinationScope` field scaffoldState = scaffoldState, resultBackNavigator = resultBackNavigator(), // needed if "SomeScreen" needs to send argument back to previous screen resultRecipient = resultRecipient(), // needed if "SomeScreen" needs to receive results from a forward screen ) } } ``` -------------------------------- ### Declare Optional Navigation Arguments Source: https://github.com/raamcosta/compose-destinations/wiki/Destination-arguments Mark arguments as nullable or provide default values to make them optional. Note that only String arguments can be nullable directly, while others use String internally for nullability. ```kotlin import androidx.compose.runtime.Composable import com.ramcosta.composedestinations.annotation.Destination @Destination @Composable fun ProfileScreen( id: Int = -1, // <- optional navigation argument. If it is not sent by previous screen, -1 will be received here name: String? // <- optional navigation argument. It will be null if not sent by previous screen ) ``` -------------------------------- ### Manual Composable Calls with `manualComposableCallsBuilder` Source: https://context7.com/raamcosta/compose-destinations/llms.txt Override how specific destination composables are called within `DestinationsNavHost`. This is useful for passing arbitrary non-navigation objects like `ScaffoldState` or callbacks that are not suitable for `dependenciesContainerBuilder`. ```kotlin val scaffoldState = rememberScaffoldState() DestinationsNavHost(navGraph = NavGraphs.root) { composable(SomeScreenDestination) { // `this` is DestinationScope SomeScreen( id = navArgs.id, // typed nav args navigator = destinationsNavigator, // DestinationsNavigator backStackEntry = navBackStackEntry, // NavBackStackEntry scaffoldState = scaffoldState, // custom non-nav param resultRecipient = resultRecipient() // result from sub-screen ) } // All other destinations in NavGraphs.root are still auto-wired } ``` -------------------------------- ### Custom Serializer for Parcelable/Serializable Arguments Source: https://github.com/raamcosta/compose-destinations/wiki/Deep-Links Implement `@NavTypeSerializer` to define how custom `Parcelable` or `Serializable` navigation arguments are converted to and from route strings for deep links. ```kotlin import androidx.compose.runtime.Composable import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.DeepLink import com.ramcosta.composedestinations.navargs.NavTypeSerializer import com.ramcosta.composedestinations.navargs.ParcelableNavTypeSerializer data class Things( val thingOne: String, val thingTwo: String ) // _________________________ @NavTypeSerializer class ThingsNavTypeSerializer : ParcelableNavTypeSerializer { override fun toRouteString(value: Things): String { return "${value.thingOne};${value.thingTwo}" } override fun fromRouteString(routeStr: String, jClass: Class): Things { return routeStr.split(";").run { Things(get(0), get(1)) } } } ``` ```kotlin import androidx.compose.runtime.Composable import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.DeepLink @Destination( deepLinks = [ DeepLink(uriPattern = "https://myapp.com/things_screen/{things}") ] ) @Composable fun ThingsScreen( things: Things ) { //... } ``` -------------------------------- ### Excluding Parameters with @NavHostParam Source: https://context7.com/raamcosta/compose-destinations/llms.txt Use the `@NavHostParam` annotation to mark composable parameters that should not be treated as navigation arguments. These parameters must be provided at the `DestinationsNavHost` level. ```kotlin @Destination @Composable fun DashboardScreen( userId: Int, // navigation argument (Int type) @NavHostParam analytics: AnalyticsTracker // NOT a nav arg — provided from NavHost level ) { LaunchedEffect(Unit) { analytics.track("dashboard_opened") } } // Wire it up at NavHost level: DestinationsNavHost( navGraph = NavGraphs.root, dependenciesContainerBuilder = { dependency(analyticsTrackerInstance) // provided to any screen that requests it } ) ``` -------------------------------- ### Create Custom Non-Dismissable Dialog Style Source: https://github.com/raamcosta/compose-destinations/wiki/Styles-and-Animations Define a custom dialog style by subclassing `DestinationStyle.Dialog` and overriding `properties` with custom `DialogProperties`. ```kotlin object NonDismissableDialog : DestinationStyle.Dialog { override val properties = DialogProperties( dismissOnClickOutside = false, dismissOnBackPress = false, ) } ``` -------------------------------- ### Deep Linking with Explicit Argument Placeholder Source: https://context7.com/raamcosta/compose-destinations/llms.txt Define deep links for a destination using the `deepLinks` parameter of `@Destination`. Use explicit argument placeholders like `{userId}` for specific arguments. ```kotlin @Destination( route = "user", deepLinks = [DeepLink(uriPattern = "https://myapp.com/user/{userId}")] ) @Composable fun UserScreen(navigator: DestinationsNavigator, userId: Int) { /* ... */ } // Opens via: adb shell am start -W -a android.intent.action.VIEW -d "https://myapp.com/user/42" ``` -------------------------------- ### Apply BottomSheet Style to a Destination Source: https://github.com/raamcosta/compose-destinations/wiki/Styles-and-Animations Use the `style` argument in the `@Destination` annotation to apply the `DestinationStyle.BottomSheet`. Requires `animations-core` dependency. ```kotlin @Destination(style = DestinationStyle.BottomSheet::class) @Composable fun ColumnScope.SomeBottomSheetScreen() { /*...*/ } ``` -------------------------------- ### Define Deep Link with URI Pattern Source: https://github.com/raamcosta/compose-destinations/wiki/Deep-Links Use the `deepLinks` parameter in the `@Destination` annotation to specify a `uriPattern` for a deep link. This allows users to navigate to a specific screen by opening a URL. ```kotlin import androidx.compose.runtime.Composable import androidx.navigation.navArgument import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.DeepLink import com.ramcosta.composedestinations.navigation.DestinationsNavigator @Destination( route = "user", deepLinks = [ DeepLink( uriPattern = "https://myapp.com/user/{id}" ) ] ) @Composable fun UserScreen( navigator: DestinationsNavigator, id: Int ) ``` -------------------------------- ### Receive Result with ResultRecipient Source: https://github.com/raamcosta/compose-destinations/wiki/Navigating Use `ResultRecipient` in a Composable to listen for results from another destination. Specify the source destination and result type. ```kotlin @Composable fun GreetingScreen( navigator: DestinationsNavigator, resultRecipient: ResultRecipient ) { resultRecipient.onResult { confirmed -> // Do whatever with the result received! // Think of it like a button click, usually you want to call // a view model method here or navigate somewhere } // Navigate normally to the other screen, example: Button( onClick = { navigator.navigate(GoToProfileConfirmationDestination) } ) {//...} ``` -------------------------------- ### Apply Custom Transitions to a Destination Source: https://github.com/raamcosta/compose-destinations/wiki/Styles-and-Animations Annotate a Composable destination with `@Destination(style = ProfileTransitions::class)` to apply the custom transitions defined in `ProfileTransitions`. Note the `AnimatedVisibilityScope` receiver. ```kotlin @Destination(style = ProfileTransitions::class) @Composable fun AnimatedVisibilityScope.ProfileScreen() { /*...*/ } ``` -------------------------------- ### Custom Dialog Style for Non-Dismissable Dialogs Source: https://context7.com/raamcosta/compose-destinations/llms.txt Define a custom `DestinationStyle.Dialog` to control dialog properties like dismissability. Use this style with the `style` parameter of `@Destination`. ```kotlin object NonDismissableDialog : DestinationStyle.Dialog() { override val properties = DialogProperties( dismissOnClickOutside = false, dismissOnBackPress = false ) } @Destination(style = NonDismissableDialog::class) @Composable fun PinEntryDialog(resultNavigator: ResultBackNavigator) { /* ... */ } ``` -------------------------------- ### Declare Navigation Arguments Inline in Composable Parameters Source: https://context7.com/raamcosta/compose-destinations/llms.txt Declare navigation arguments directly as parameters in the @Composable function. Supported types include String, Boolean, Int, Float, Long, Parcelable, Serializable, and Enum. Optional arguments can be made by providing default values or using nullable types. ```kotlin @Destination @Composable fun TaskScreen( taskId: Int, // mandatory navigation argument filter: String? = null, // optional — null if not sent page: Int = 0 // optional — default 0 if not sent ) { // Arguments are available directly in the composable val vm: TaskViewModel = viewModel() // ... } // Caller navigates with full type safety: navigator.navigate(TaskScreenDestination(taskId = 42, filter = "active")) // Compiler error if taskId is omitted or wrong type ``` -------------------------------- ### Add Navigation Arguments to Composable Source: https://github.com/raamcosta/compose-destinations/blob/main/README.md Define navigation arguments directly in the composable function declaration. Supported types include Parcelable, Serializable, Enum, and kotlinx.serialization.Serializable classes, as well as their arrays. ```kotlin @Destination @Composable fun ProfileScreen( id: Int, // <-- required navigation argument groupName: String?, // <-- optional navigation argument isOwnUser: Boolean = false // <-- optional navigation argument ) { /*...*/ } ``` -------------------------------- ### Declare Mandatory Navigation Argument Source: https://github.com/raamcosta/compose-destinations/wiki/Destination-arguments Add a parameter directly to the Composable function to make it a mandatory navigation argument. Only specific types are supported. ```kotlin import androidx.compose.runtime.Composable import com.ramcosta.composedestinations.annotation.Destination @Destination @Composable fun ProfileScreen( id: Int // <- this will be a mandatory navigation argument! ) ``` -------------------------------- ### Define a Minimal Navigation Destination Source: https://context7.com/raamcosta/compose-destinations/llms.txt Mark a @Composable function as a navigation destination using the @Destination annotation. The type parameter specifies the navigation graph it belongs to. The route defaults to the snake-case composable name. ```kotlin // Minimal destination — auto-route "greeting_screen", belongs to RootGraph @Destination @Composable fun GreetingScreen() { /* ... */ } ```