Navigation Event
Android (Google)OfficialCreated by Google LLCDistributed by Android (Google)
- Skill
- Tool integration
- Software development
- Apache-2.0
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
The NavigationEvent library provides a structured way to intercept back gestures and implement Predictive Back animations within Jetpack Compose applications. It manages the dispatcher hierarchy, allowing developers to link parent and child navigation containers, handle back events in nested UI components like ViewPagers or tabs, and migrate from legacy back-handling patterns. The library enforces strict state management to prevent collisions and ensures proper resource cleanup through Compose-native lifecycle integration.
What it does
- Intercepts system back gestures for custom UI responses.
- Supports Predictive Back animations using progress-based event tracking.
- Manages parent-child dispatcher hierarchies for nested navigation.
- Provides the NavigationBackHandler composable for localized event handling.
- Automates resource cleanup for dispatchers and handlers in Compose.
- Facilitates migration from legacy back-handling APIs to modern standards.
When to use it
- When implementing custom Predictive Back animations in a Compose Android app.
- When managing back navigation in complex, nested UI structures like tabs or ViewPagers.
- When migrating legacy back-handling logic to the modern NavigationEvent framework.
- When you need to ensure back gesture handling is scoped correctly to specific composables.
Advantages
- Native integration with Jetpack Compose lifecycle and state management.
- Automatic cleanup of handlers and dispatchers prevents memory leaks.
- Prevents common runtime errors like duplicate handler registration.
- Simplifies complex navigation hierarchies through scoped dispatcher owners.
Usage examples
- “How do I handle back navigation in a Compose screen with unsaved changes?”
- Use a single NavigationBackHandler with a state object, checking your 'hasUnsavedChanges' flag inside the onBackCompleted callback to decide whether to show a dialog or navigate up.
- “How do I scope back navigation to a specific tab in a ViewPager?”
- Use rememberNavigationEventDispatcherOwner(enabled = isSelected) and wrap the tab content in a CompositionLocalProvider to link the child dispatcher to the parent.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/android/navigation-event/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip navigation-event.zip -d .agents/skills
Documentation by Google LLC
Common guidelines
For architecture concepts : To understand the foundational architecture, continuous gesture event lifecycles, or class definitions of the Navigation Event library, read Navigation Event overview.
For Android target : If compile SDK is lower than 36, set it to
36or higher inbuild.gradle.kts.For Compose Android target: The project must use Jetpack Compose for Compose-specific APIs. This skill is scoped exclusively to Compose Android (Android Views and non-Compose implementations are excluded).
For activity dispatchers :
ComponentActivityautomatically implementsNavigationEventDispatcherOwnerout-of-the-box. You must use the built-innavigationEventDispatcherwithout creating anonymous delegate owners or overriding member properties.For dialog scoping : Floating windows (Compose
Dialog,ModalBottomSheet,ComponentDialog) automatically provide aNavigationEventDispatcherOwner. You don't need manualCompositionLocalProviderpropagation for dialogs.For parent-child dispatcher hierarchies : When scoping navigation handling to
ViewPagers, tabbed interfaces, or nested navigation containers in Compose, userememberNavigationEventDispatcherOwner()to create a child owner linked to the parent. Disabling the owner (enabled = false) automatically cascades to disable all child handlers.For Compose handlers : A one-to-one relationship between
NavigationEventStateand handlers is strictly enforced. Never bind the sameNavigationEventStateto multiple activeNavigationBackHandlerinstances (IllegalArgumentException).
Step 1: Plan
To complete this step, you MUST ensure the following:
Identify the target platform : Verify the app is targeting Compose Android. If
compileSdkis lower than 36, set it to36or higher inbuild.gradle.kts.Navigation check: Check if Navigation 3 is in use. If it is in use, use Navigation 3's built-in back navigation support rather than manually implementing low-level dispatchers from this skill.
Hierarchy check : Identify host Activities,
ViewPagers, tabbed interfaces, or nested navigation hosts that require back gesture interception or parent-child dispatcher linking.Migration check : Check if the project is migrating from back handling (
OnBackPressedCallback,BackHandler,onBackPresser) toNavigationEventandNavigationBackHandler.Input interception : Detect where the app is intercepting navigation events from gestures or hardware button presses requiring translation to
NavigationEvent.
Step 2: Set up dependencies
To complete this step, you MUST ensure the following:
For setting up compile SDKs, declaring catalog versions, and adding dependencies, follow setup guide.
Step 3: Configure dispatcher and inputs
To complete this step, you MUST ensure the following:
To configure your dispatcher, leverage automatic
ComponentActivityorComponentDialogowner resolution.Link parent-child dispatchers in Compose following dispatcher guide.
Step 4: Handle back navigation and UI transitions
To complete this step, you MUST ensure the following:
To create navigation event handlers, integrate back gesture interception in Compose, animate UI components during swipes, and migrate from legacy back handlers, follow handle back guide.
Step 5: Clean up resources
[!WARNING] Warning: Compose APIs perform teardown automatically. When using Compose APIs such as
NavigationBackHandlerandrememberNavigationEventDispatcherOwner(), handler removal and dispatcher disposal occur automatically when the composable leaves the composition.
You MUST perform explicit manual cleanup only when managing custom dispatchers or non-Compose handlers:
Call
remove()on active handlers during teardown.Call
isEnabled = falseto temporarily disable navigation subtrees.Call
dispose()on dispatcher instances when hosting components are destroyed. Disposing a parent dispatcher automatically cascades to all child dispatchers.
Core troubleshooting guidelines
1. Activity dispatcher setup (StackOverflowError recursion)
ComponentActivity implements NavigationEventDispatcherOwner automatically
out-of-the-box. Don't override navigationEventDispatcher or wrap it in an
anonymous delegate owner.
RIGHT
Why this is RIGHT : Compose apps use ComponentActivity as the host.
LocalNavigationEventDispatcherOwner.current automatically resolves the
Activity's built-in dispatcher.
// RIGHT
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyApplicationContent()
}
}
}<br />
WRONG
Why this is WRONG : Implementing NavigationEventDispatcherOwner directly on
MainActivity and overriding navigationEventDispatcher with a new instance
shadows the library's extension property, causing a recursive infinite loop
crash on launch (StackOverflowError). Creating redundant anonymous delegate
owners (object : NavigationEventDispatcherOwner) is unnecessary.
// WRONG
class MainActivity : ComponentActivity(), NavigationEventDispatcherOwner {
override val navigationEventDispatcher = NavigationEventDispatcher() // Shadow loop crash
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyApplicationContent()
}
}
}<br />
2. Floating window and dialog scoping (automatic ComponentDialog owner)
Floating windows (Compose Dialog, ModalBottomSheet, and any window backed by
ComponentDialog) automatically provide a NavigationEventDispatcherOwner.
Don't manually re-provide LocalNavigationEventDispatcherOwner using
CompositionLocalProvider inside dialogs.
RIGHT
Why this is RIGHT : ComponentDialog handles navigation dispatchers
automatically. Compose Dialog components resolve their dispatcher owner
out-of-the-box without manual propagation.
// RIGHT
@Composable
fun MyDialog(onDismiss: () -> Unit) {
Dialog(onDismissRequest = onDismiss) {
val navigationState = rememberNavigationEventState(currentInfo = NavigationEventInfo.None)
NavigationBackHandler(
state = navigationState,
onBackCompleted = onDismiss
)
}
}<br />
WRONG
Why this is WRONG : Wrapping dialog content in a manual
CompositionLocalProvider creates redundant boilerplate and obscures the
automatic dispatcher resolution provided by ComponentDialog.
// WRONG
@Composable
fun MyDialog(onDismiss: () -> Unit) {
val dispatcherOwner = LocalNavigationEventDispatcherOwner.current!!
Dialog(onDismissRequest = onDismiss) {
// Redundant: ComponentDialog provides NavigationEventDispatcherOwner automatically
CompositionLocalProvider( LocalNavigationEventDispatcherOwner provides dispatcherOwner) {
val navigationState = rememberNavigationEventState(currentInfo = NavigationEventInfo.None)
NavigationBackHandler(
state = navigationState,
onBackCompleted = onDismiss
)
}
}
}<br />
3. Parent-child dispatcher hierarchy (ViewPagers and nested navigation)
When managing nested UI hierarchies such as ViewPagers, tabbed
interfaces, or custom navigation containers in Compose, use
rememberNavigationEventDispatcherOwner() to create a child owner linked to the
composition hierarchy. Setting enabled = false on the child owner
automatically disables its dispatcher and all registered child handlers.
RIGHT
Why this is RIGHT : Using rememberNavigationEventDispatcherOwner(enabled = isSelected) creates a scoped child dispatcher linked to the parent from
LocalNavigationEventDispatcherOwner.current. Providing it using
CompositionLocalProvider ensures non-visible tabs or pages automatically stop
intercepting back gestures without leaking handlers.
// RIGHT: Scoping child navigation in a ViewPager or Tab interface
@Composable
fun TabPage(isSelected: Boolean) {
val childOwner = rememberNavigationEventDispatcherOwner(enabled = isSelected)
CompositionLocalProvider(LocalNavigationEventDispatcherOwner provides childOwner) {
val navigationState = rememberNavigationEventState(currentInfo = NavigationEventInfo.None)
NavigationBackHandler(
state = navigationState,
onBackCompleted = { /* Handle page back navigation */ }
)
// Page content
}
}<br />
WRONG
Why this is WRONG : Creating unlinked standalone dispatchers, instantiating
raw dispatchers without remembering them across recompositions, or attempting to
use non-existent methods like .addChild() breaks hierarchy routing and leaves
child handlers active even when the page is inactive.
// WRONG
@Composable
fun TabPage(isSelected: Boolean) {
val parentDispatcher = LocalNavigationEventDispatcherOwner.current?.navigationEventDispatcher
val childDispatcher = NavigationEventDispatcher() // Unlinked and not remembered across recompositions
// WRONG: Method does not exist
parentDispatcher?.addChild(childDispatcher)
}<br />
4. Compose multi-handler registration (IllegalArgumentException)
You must not bind the same NavigationEventState to multiple active
NavigationBackHandler instances, as this throws an IllegalArgumentException
at runtime. To handle conditional workflows (such as checking for unsaved
changes versus navigating back immediately), you must register a single unified
handler and branch logic inside onBackCompleted.
RIGHT
Why this is RIGHT : Using a single NavigationBackHandler with internal
branching logic inside onBackCompleted maintains a strict 1:1 mapping between
NavigationEventState and the handler, preventing state collisions.
// RIGHT
val navigationState = rememberNavigationEventState(currentInfo = NavigationEventInfo.None)
NavigationBackHandler(
state = navigationState,
isBackEnabled = true,
onBackCompleted = {
if (hasUnsavedChanges) {
showDiscardDialog()
} else {
onNavigateUp()
}
}
)<br />
WRONG
Why this is WRONG : Attaching multiple NavigationBackHandler composables to
the same navigationState instance attempts to bind duplicate handlers to a
single state object, which throws an IllegalArgumentException at runtime.
// WRONG
val navigationState = rememberNavigationEventState(currentInfo = NavigationEventInfo.None)
NavigationBackHandler(
state = navigationState,
isBackEnabled = hasUnsavedChanges,
onBackCompleted = { /* Discard changes */ }
)
NavigationBackHandler(
state = navigationState,
isBackEnabled = !hasUnsavedChanges,
onBackCompleted = { /* Navigate up */ }
)<br />
Checklist
For Compose Android targets:
[ ] Is compile SDK set to
36or higher? (If compile SDK is lower than 36, set it to36or higher inbuild.gradle.kts).[ ] Is
android:enableOnBackInvokedCallbackNOT explicitly set to"false"inAndroidManifest.xml? (On API 36+, it defaults to"true"; on API 33--35, ensure it is set to"true").[ ] Does the Activity rely on the built-in
ComponentActivitydispatcher owner without redundant anonymous delegate wrapping?[ ] Do dialogs or sheets rely on automatic
ComponentDialogdispatcher resolution without redundantCompositionLocalProviderwrapping?[ ] Are parent-child dispatcher relationships in Compose scoped using
rememberNavigationEventDispatcherOwner()when managing nested hierarchies?[ ] Is conditional back logic handled within a single unified
NavigationBackHandlerto avoid duplicate registration (IllegalArgumentException)?[ ] Are legacy
BackHandlerusages migrated toNavigationBackHandlerwith predictive progress support?[ ] Does the project build and pass tests successfully?
Files
- ATTRIBUTION.mdAdded by AutoGineer967 B
- LICENSELicence file added by AutoGineer11.1 KiB
- SKILL.md12.8 KiB
- references/android/guide/navigation/navigation-event/dispatcher.md4.3 KiB
- references/android/guide/navigation/navigation-event/handle-back.md7.2 KiB
- references/android/guide/navigation/navigation-event/index.md4.0 KiB
- references/android/guide/navigation/navigation-event/setup.md1.0 KiB
references/android/guide/navigation/navigation-event/setup.md
To set up your development environment for NavigationEvent, follow these
steps.
Declare dependencies
Add the
navigationeventartifact to your project. This is the core library containing the sharedNavigationEventDispatcherandNavigationEventHandlerclasses.For Jetpack Compose integration, you also need to add the corresponding Compose artifact:
[versions] navigationevent = "1.0.0" [libraries] # NavigationEvent libraries androidx-navigationevent = { module = "androidx.navigationevent:navigationevent", version.ref = "navigationevent" } androidx-navigationevent-compose = { module = "androidx.navigationevent:navigationevent-compose", version.ref = "navigationevent" }Update your compile SDK to 36 or above:
[versions] compileSdk = "36"Add the following to your app build file,
app/build.gradle.kts:dependencies { ... implementation(libs.androidx.navigationevent) implementation(libs.androidx.navigationevent.compose) }
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Google LLC
- Publisher
- Android (Google) (Official)
- Distributed by
- Android (Google)
- Source
- android/skills · navigation/navigation-event · commit bf68e2d
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE.txt)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Google LLC or Android (Google).
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download navigation-event.zip