
Simplifies navigation in Jetpack Compose with type-safe routes, advanced backstack control, and conditional navigation. Automatically generates code, ensuring compile-time safety.
Com
ComPilot simplifies navigation in Jetpack Compose by providing type-safe routes and advanced navigation control. Leveraging Kotlin Symbol Processing (KSP), ComPilot automatically generates navigation code, ensuring compile-time safety and reducing errors in backstack management and argument handling.
Add ComPilot dependencies to your Gradle configuration:
commonMain.dependencies {
implementation "io.github.mahmoudafarideh.compilot.kmp:common:$version"
implementation "io.github.mahmoudafarideh.compilot.kmp:runtime:$version"
implementation "io.github.mahmoudafarideh.compilot.kmp:navigation:$version"
}
dependencies {
add("kspCommonMainMetadata", "io.github.mahmoudafarideh.compilot.kmp:compiler:$version")
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().all {
if (name != "kspCommonMainKotlinMetadata") {
dependsOn("kspCommonMainKotlinMetadata")
}
}
To define a type-safe route, annotate a data class with @RouteNavigation. Each class must include a companion object to enable code generation.
@RouteNavigation(RouteType.Screen)
data class SomeScreenRoute(val title: String) {
companion object
}ComPilot supports complex structures like nested data classes and enums:
@RouteNavigation(RouteType.Screen)
data class SomeScreenWithNestedArgRoute(
val nested: NestedData,
val child: Child?
) {
data class NestedData(val id: Int, val name: String)
enum class Child { Child1, Child2 }
companion object
}ComPilot supports multiple route types by setting the type parameter in the @RouteNavigation annotation:
@RouteNavigation(type = RouteType.Dialog)
@RouteNavigation(type = RouteType.Dialog)
data class SomeDialogRoute(val id: Int) {
companion object
}Access ComPilotNavController via LocalNavController to enable type-safe, controlled navigation.
val comPilotNavController = LocalNavController.comPilotNavController
// Navigate to a route
comPilotNavController.navigate(SomeScreenRoute(title = "Welcome").navigator())
// Safe backstack pop
comPilotNavController.safePopBackStack()Use functions like safeNavigate() and checkNotInRoutes() to prevent duplicate navigations and manage the backstack safely.
To make ComPilotNavController accessible throughout your screens, provide the NavController at the root of your composable hierarchy:
CompositionLocalProvider(LocalNavController provides navigation) {
// Your screen content
}This CompositionLocalProvider setup allows all child composables to access LocalNavController and use comPilotNavController for navigation.
@RouteNavigation annotated data class must include a companion object to allow the compiler to extend it with generated functions.ComPilotNavController to confirm behavior, especially with nested arguments and different route types.Com
ComPilot simplifies navigation in Jetpack Compose by providing type-safe routes and advanced navigation control. Leveraging Kotlin Symbol Processing (KSP), ComPilot automatically generates navigation code, ensuring compile-time safety and reducing errors in backstack management and argument handling.
Add ComPilot dependencies to your Gradle configuration:
commonMain.dependencies {
implementation "io.github.mahmoudafarideh.compilot.kmp:common:$version"
implementation "io.github.mahmoudafarideh.compilot.kmp:runtime:$version"
implementation "io.github.mahmoudafarideh.compilot.kmp:navigation:$version"
}
dependencies {
add("kspCommonMainMetadata", "io.github.mahmoudafarideh.compilot.kmp:compiler:$version")
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().all {
if (name != "kspCommonMainKotlinMetadata") {
dependsOn("kspCommonMainKotlinMetadata")
}
}
To define a type-safe route, annotate a data class with @RouteNavigation. Each class must include a companion object to enable code generation.
@RouteNavigation(RouteType.Screen)
data class SomeScreenRoute(val title: String) {
companion object
}ComPilot supports complex structures like nested data classes and enums:
@RouteNavigation(RouteType.Screen)
data class SomeScreenWithNestedArgRoute(
val nested: NestedData,
val child: Child?
) {
data class NestedData(val id: Int, val name: String)
enum class Child { Child1, Child2 }
companion object
}ComPilot supports multiple route types by setting the type parameter in the @RouteNavigation annotation:
@RouteNavigation(type = RouteType.Dialog)
@RouteNavigation(type = RouteType.Dialog)
data class SomeDialogRoute(val id: Int) {
companion object
}Access ComPilotNavController via LocalNavController to enable type-safe, controlled navigation.
val comPilotNavController = LocalNavController.comPilotNavController
// Navigate to a route
comPilotNavController.navigate(SomeScreenRoute(title = "Welcome").navigator())
// Safe backstack pop
comPilotNavController.safePopBackStack()Use functions like safeNavigate() and checkNotInRoutes() to prevent duplicate navigations and manage the backstack safely.
To make ComPilotNavController accessible throughout your screens, provide the NavController at the root of your composable hierarchy:
CompositionLocalProvider(LocalNavController provides navigation) {
// Your screen content
}This CompositionLocalProvider setup allows all child composables to access LocalNavController and use comPilotNavController for navigation.
@RouteNavigation annotated data class must include a companion object to allow the compiler to extend it with generated functions.ComPilotNavController to confirm behavior, especially with nested arguments and different route types.