piyushverma0/android-agent-skills/compose-navigation

Claude Code and agent skill by piyushverma0/android-agent-skills

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Jetpack Compose Navigation for Android AI agents. Use this skill whenever implementing navigation, NavHost, NavController, back stack, deep links, navigation arguments, routes, type-safe navigation, @Serializable routes, navController.navigate, popBackStack, navigateUp, bottom navigation, tab navigation, nested navigation graphs, shared ViewModels across destinations, navigation with Hilt, passing arguments between screens, transition animations between screens, or any navigation pattern. Always apply before writing any NavHost or navigation logic. Triggers on: navigate, NavController, NavHost, route, backstack, deep link, navigation argument, destination, composable(), navigation graph.

Install

npx vskill@latest install piyushverma0/android-agent-skills/compose-navigation

SKILL.md

The same SKILL.md was published earlier as piyushverma0/android-agent-skills/compose-navigation.

Compose Navigation

Type-safe navigation prevents the most common navigation bugs in AI-built apps. These rules cover the complete navigation pattern from setup to --- name: compose-navigation description: | Jetpack Compose Navigation for Android AI agents — complete patterns. Use this skill for any navigation: NavHost, NavController, type-safe @Serializable routes, back stack, deep links, navigation arguments, composable(), nested graphs, shared ViewModels, navigateUp, navigateTopLevel, launchSingleTop, popUpTo, shared element transitions, predictive back gesture, transition animations between screens, bottom navigation, navigation with Hilt, passing arguments, result passing via SavedStateHandle, or any navigation pattern in Compose. Always apply before writing any NavHost or route.


Compose Navigation — Complete Guide

Type-safe navigation with shared element transitions and predictive back. These rules cover every pattern from simple routes to complex multi-graph apps.

Setup

toml
[versions]
navigationCompose = "2.8.5"
[libraries]
navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose" }

Rule 1: All routes are @Serializable — zero string routes

kotlin
// navigation/Routes.kt — ALL routes defined here, nowhere else
@Serializable object HomeRoute
@Serializable object SearchRoute
@Serializable object InboxRoute
@Serializable object ProfileRoute
@Serializable object SettingsRoute
// Routes with required arguments
@Serializable data class ItemDetailRoute(val itemId: String)
@Serializable data class EditItemRoute(val itemId: String, val isNew: Boolean = false)
@Serializable data class UserProfileRoute(val userId: String, val fromNotification: Boolean = false)
// Graph containers
@Serializable object AuthGraph
@Serializable object LoginRoute
@Serializable object SignUpRoute
@Serializable object ForgotPasswordRoute
@Serializable object OnboardingGraph
@Serializable object OnboardingStep1Route
@Serializable object OnboardingStep2Route
@Serializable object OnboardingStep3Route
// ❌ NEVER use string routes
navController.navigate("detail/$itemId") // typo-prone, no type safety
composable("detail/{itemId}") { backStackEntry ->
backStackEntry.arguments?.getString("itemId") // nullable, untyped
}

Rule 2: Complete NavHost — every destination registered

kotlin
// navigation/AppNavHost.kt
@Composable
fun AppNavHost(
navController: NavHostController = rememberNavController(),
startDestination: Any = if (isLoggedIn) HomeRoute else AuthGraph
) {
NavHost(
navController = navController,
startDestination = startDestination,
// M3 Expressive enter/exit transitions (applied to ALL screens by default)
enterTransition = { slideInHorizontally(
initialOffsetX = { it },
animationSpec = tween(Duration.medium4, easing = AppEasing.EmphasizedDecel)
) + fadeIn(tween(Duration.medium4)) },
exitTransition = { slideOutHorizontally(
targetOffsetX = { -it / 4 },
animationSpec = tween(Duration.short4, easing = AppEasing.EmphasizedAccel)
) + fadeOut(tween(Duration.short4)) },
popEnterTransition = { slideInHorizontally(
initialOffsetX = { -it / 4 },
animationSpec = tween(Duration.medium4, easing = AppEasing.EmphasizedDecel)
) + fadeIn(tween(Duration.medium4)) },
popExitTransition = { slideOutHorizontally(
targetOffsetX = { it },
animationSpec = tween(Duration.short4, easing = AppEasing.EmphasizedAccel)
) + fadeOut(tween(Duration.short4)) }
) {
// Top-level destinations
composable<HomeRoute> { HomeScreen(navController = navController) }
composable<SearchRoute> { SearchScreen(navController = navController) }
composable<InboxRoute> { InboxScreen(navController = navController) }
composable<ProfileRoute>{ ProfileScreen(navController = navController) }
composable<SettingsRoute>{ SettingsScreen(onBack = { navController.navigateUp() }) }
// Detail screens
composable<ItemDetailRoute> { entry ->
val route: ItemDetailRoute = entry.toRoute()
ItemDetailScreen(
itemId = route.itemId,
onEdit = { navController.navigate(EditItemRoute(route.itemId)) },
onBack = { navController.navigateUp() }
)
}
composable<EditItemRoute> { entry ->
val route: EditItemRoute = entry.toRoute()
EditItemScreen(
itemId = route.itemId,
isNew = route.isNew,
onDone = { navController.navigateUp() }
)
}
// Auth flow — nested graph
navigation<AuthGraph>(startDestination = LoginRoute) {
composable<LoginRoute> {
LoginScreen(
onLoginSuccess = {
navController.navigate(HomeRoute) {
popUpTo(AuthGraph) { inclusive = true } // clear auth stack entirely
}
},
onSignUp = { navController.navigate(SignUpRoute) },
onForgotPass = { navController.navigate(ForgotPasswordRoute) }
)
}
composable<SignUpRoute> {
SignUpScreen(
onSuccess = { navController.navigate(HomeRoute) { popUpTo(AuthGraph) { inclusive = true } } },
onBack = { navController.navigateUp() }
)
}
composable<ForgotPasswordRoute> {
ForgotPasswordScreen(onBack = { navController.navigateUp() })
}
}
}
}

Rule 3: Top-level navigation — launchSingleTop prevents duplicate entries

kotlin
// ✅ Navigation helper for tab/nav items — prevents backstack pollution
fun NavController.navigateTopLevel(route: Any) {
navigate(route) {
// Pop to start destination, saving state for restoration
popUpTo(graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true // don't create duplicate on re-tap
restoreState = true // restore state when re-navigating to tab
}
}
// Usage in NavigationSuiteScaffold
item(
selected = currentDestination?.hasRoute<HomeRoute>() == true,
onClick = { navController.navigateTopLevel(HomeRoute) }
)

Rule 4: Shared Element Transitions — M3 Expressive

kotlin
// ✅ Shared element transition between list item and detail screen
// Navigation 2.8+ with material3 1.4+ supports SharedTransitionLayout
@Composable
fun HomeScreen(navController: NavController) {
SharedTransitionLayout {
AnimatedContent(targetState = selectedItem, label = "shared-transition") { item ->
if (item == null) {
LazyColumn {
items(items, key = { it.id }) { item ->
ItemCard(
item = item,
animatedVisibilityScope = this@AnimatedContent,
sharedTransitionScope = this@SharedTransitionLayout,
onClick = { selectedItem = item }
)
}
}
} else {
ItemDetailScreen(
item = item,
animatedVisibilityScope = this@AnimatedContent,
sharedTransitionScope = this@SharedTransitionLayout,
onBack = { selectedItem = null }
)
}
}
}
}
// ✅ In list item — mark shared elements
@Composable
fun ItemCard(
item: Item,
sharedTransitionScope: SharedTransitionScope,
animatedVisibilityScope: AnimatedVisibilityScope,
onClick: () -> Unit,
) {
with(sharedTransitionScope) {
Card(onClick = onClick) {
AsyncImage(
model = item.imageUrl,
contentDescription = null,
modifier = Modifier
.sharedElement(
state = rememberSharedContentState("image-${item.id}"),
animatedVisibilityScope = animatedVisibilityScope
)
.fillMaxWidth().aspectRatio(16f / 9f)
)
Text(
item.title,
modifier = Modifier.sharedElement(
state = rememberSharedContentState("title-${item.id}"),
animatedVisibilityScope = animatedVisibilityScope
)
)
}
}
}
// ✅ In detail screen — same shared element keys
@Composable
fun ItemDetailScreen(
item: Item,
sharedTransitionScope: SharedTransitionScope,
animatedVisibilityScope: AnimatedVisibilityScope,
onBack: () -> Unit
) {
with(sharedTransitionScope) {
Column {
AsyncImage(
model = item.imageUrl,
contentDescription = item.title,
modifier = Modifier
.sharedElement(
state = rememberSharedContentState("image-${item.id}"),
animatedVisibilityScope = animatedVisibilityScope
)
.fillMaxWidth().aspectRatio(16f / 9f)
)
Text(
item.title,
style = MaterialTheme.typography.headlineMedium,
modifier = Modifier.sharedElement(
state = rememberSharedContentState("title-${item.id}"),
animatedVisibilityScope = animatedVisibilityScope
).padding(Spacing.md)
)
}
}
}

Rule 5: Deep links with type-safe routes

kotlin
// ✅ Deep link registered on destination
composable<ItemDetailRoute>(
deepLinks = listOf(
navDeepLink<ItemDetailRoute>(basePath = "https://myapp.com/items")
// matches: https://myapp.com/items/{itemId}
)
) { entry ->
val route: ItemDetailRoute = entry.toRoute()
ItemDetailScreen(itemId = route.itemId)
}
// AndroidManifest.xml — intent filter
// <activity android:name=".MainActivity">
// <intent-filter android:autoVerify="true">
// <action android:name="android.intent.action.VIEW"/>
// <category android:name="android.intent.category.DEFAULT"/>
// <category android:name="android.intent.category.BROWSABLE"/>
// <data android:scheme="https" android:host="myapp.com"/>
// </intent-filter>
// </activity>

Rule 6: Shared ViewModel scoped to NavGraph

kotlin
// ✅ Share state across multiple screens in a graph
navigation<CheckoutGraph>(startDestination = CartRoute) {
composable<CartRoute> { entry ->
val parentEntry = remember(entry) { navController.getBackStackEntry(CheckoutGraph) }
val viewModel: CheckoutViewModel = hiltViewModel(parentEntry)
CartScreen(viewModel)
}
composable<ShippingRoute> { entry ->
val parentEntry = remember(entry) { navController.getBackStackEntry(CheckoutGraph) }
val viewModel: CheckoutViewModel = hiltViewModel(parentEntry)
ShippingScreen(viewModel)
}
composable<PaymentRoute> { entry ->
val parentEntry = remember(entry) { navController.getBackStackEntry(CheckoutGraph) }
val viewModel: CheckoutViewModel = hiltViewModel(parentEntry)
PaymentScreen(viewModel)
}
}

Rule 7: Result passing via SavedStateHandle

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
15
7-day trend score
14

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/piyushverma0/android-agent-skills/compose-navigation/badge)](https://verified-skill.com/skills/piyushverma0/android-agent-skills/compose-navigation)

Something wrong with this skill or its page? Tell us.