navigation-event
Qué hace
Esta skill guía la captura de los gestos de retroceso y la ejecución de animaciones de retroceso predictivo en una app de Android con Jetpack Compose. También cubre los contenedores anidados, como las pestañas, y el paso desde el antiguo BackHandler. Es para desarrolladores de Android que necesitan un comportamiento de retroceso personalizado.
Cuándo usarla
- ✓Cuando necesitas interceptar el gesto de retroceso en una pantalla de Compose.
- ✓Cuando quieres animaciones de retroceso predictivo en tu app de Android.
- ✓Cuando necesitas pasar código antiguo de BackHandler a la biblioteca NavigationEvent.
Link de la skill
https://github.com/android/skills/blob/main/navigation/navigation-event/SKILL.mdCópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.
Cómo usar
La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.
Mensaje listo para pegar
Para Claude Code, Codex o Cursor: ejecútalo en la carpeta del proyecto y la skill queda instalada.
Descarga el SKILL.md y ponlo en la carpeta de skills de tu agente.
Ejemplo de qué pedirle a la IA
“Haz que el gesto de retroceso cierre primero mi hoja inferior en mi app de Compose, con la animación de retroceso predictivo.”
5 skills nuevas por semana. 1 minuto de lectura.
Cómo funciona
La skill configura el despachador de la actividad y el manejador de retroceso de Compose, y después limita cada uno a la pantalla, pestaña o diálogo correcto. También cubre la migración del código heredado de BackHandler en versiones nuevas de Android.
Contenido técnico (SKILL.md original)
Texto original del autor, en inglés, directo de GitHub.
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 im
Preguntas frecuentes
¿Funciona en apps de Android con Views?
No. La skill se limita a apps de Android con Compose, y las Views quedan excluidas.
¿Qué objetivo de Android se necesita?
Si el compileSdk de la app es inferior a 36, la skill lo sube a 36 o superior.
¿Los diálogos necesitan configuración extra?
No. Los diálogos y las hojas inferiores tienen su propio despachador, así que no necesitan conexiones adicionales.
Detalles
Descripción original del autor
Intercept back gestures and run Predictive Back animations using the NavigationEvent (androidx.navigationevent) library in Compose Android. Handles Activity setup, parent-child dispatcher scoping in `ViewPagers` or tabs, Compose `NavigationBackHandler`, and migration from legacy `BackHandler` on SDK 36+.
repo: android/skills
Popularidad
- Estrellas en GitHub
- 10 mil
- Posición en el ranking
- #11925
- Licencia
- Apache-2.0
- Actualizada
- 29/10/2026
Comentarios
- …
Más skills de este repositorio
agp-9-upgrade
10 milAyuda a tu agente a actualizar una app de Android a Android Gradle Plugin 9 y a resolver sus cambios incompatibles. No sirve para proyectos multiplataforma.
camerax
10 milAyuda a tu agente a crear funciones de cámara en Android con CameraX, incluida la grabación de vídeo, los controles del hardware y los efectos de ML Kit y Media3.
android-for-cars-parked-apps
10 milAyuda a tu agente a adaptar una app de Android de vídeo, juegos o navegador para que funcione como app aparcada en Android Auto y Android Automotive.
appfunctions
10 milAyuda a tu agente a encontrar los flujos de trabajo clave de una app de Android y a exponerlos como AppFunctions que los agentes de IA y los comandos de voz pueden ejecutar.
Skills parecidas
android-clean-architecture
280 milHace que tu agente organice proyectos de Android de forma eficiente. Estructura el código para facilitar el mantenimiento y el desarrollo de nuevas funciones.
compose-multiplatform-patterns
280 milAyuda a tu agente a usar patrones de Compose Multiplatform y Jetpack Compose en proyectos KMP, incluyendo estado, navegación, temas y rendimiento.
dart-flutter-patterns
280 milHace que tu agente escriba código para apps de Dart y Flutter. Usa patrones modernos para crear apps robustas y fáciles de mantener.