Aller au contenu
Skillpedia
Applis mobiles10k · #11925

navigation-event

Ce qu’il fait

Ce skill guide l'interception des gestes de retour et l'exécution des animations de retour prédictif dans une application Android Jetpack Compose. Il couvre aussi les conteneurs imbriqués comme les onglets, ainsi que le passage de l'ancien BackHandler. Il s'adresse aux développeurs Android qui ont besoin d'un comportement de retour personnalisé.

Quand l’utiliser

  • ✓Quand vous devez intercepter le geste de retour dans un écran Compose.
  • ✓Quand vous voulez des animations de retour prédictif dans votre application Android.
  • ✓Quand vous devez migrer un ancien code BackHandler vers la bibliothèque NavigationEvent.

Lien du skill

https://github.com/android/skills/blob/main/navigation/navigation-event/SKILL.md

Copiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.

Comment l’utiliser

Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.

Message prêt à coller

Utilise ce skill pour m’aider : https://github.com/android/skills/blob/main/navigation/navigation-event/SKILL.md Lis le fichier SKILL.md de ce lien et suis ses instructions pour ma tâche.
Envie que votre IA trouve seule des skills comme celui-ci ?Installez le MCP gratuit de Skillpedia : une ligne, et elle cherche parmi 15 000+ skills avant chaque tâche.Installer en 1 minute →

Exemple de demande à votre IA

“Fais en sorte que le geste de retour ferme d'abord ma feuille modale dans mon application Compose, avec l'animation de retour prédictif.”

5 nouveaux skills par semaine. 1 minute de lecture.

Comment ça marche

Le skill configure le distributeur de l'activité et le gestionnaire de retour de Compose, puis limite chacun à l'écran, à l'onglet ou à la boîte de dialogue concerné. Il couvre aussi la migration du code BackHandler historique sur les versions récentes d'Android.

Contenu technique (SKILL.md original)

Texte original de l’auteur, en anglais, directement depuis 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 36 or higher in build.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 : ComponentActivity automatically implements NavigationEventDispatcherOwner out-of-the-box. You must use the built-in navigationEventDispatcher without creating anonymous delegate owners or overriding member properties.
  • For dialog scoping : Floating windows (Compose Dialog, ModalBottomSheet, ComponentDialog) automatically provide a NavigationEventDispatcherOwner. You don't need manual CompositionLocalProvider propagation for dialogs.
  • For parent-child dispatcher hierarchies : When scoping navigation handling to ViewPagers, tabbed interfaces, or nested navigation containers in Compose, use rememberNavigationEventDispatcherOwner() 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 NavigationEventState and handlers is strictly enforced. Never bind the same NavigationEventState to multiple active NavigationBackHandler instances (IllegalArgumentException).

Step 1: Plan

To complete this step, you MUST ensure the following:

  1. Identify the target platform : Verify the app is targeting Compose Android. If compileSdk is lower than 36, set it to 36 or higher in build.gradle.kts.
  2. 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.
  3. Hierarchy check : Identify host Activities, ViewPagers, tabbed interfaces, or nested navigation hosts that require back gesture interception or parent-child dispatcher linking.
  4. Migration check : Check if the project is migrating from back handling (OnBackPressedCallback, BackHandler, onBackPresser) to NavigationEvent and NavigationBackHandler.
  5. 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 ComponentActivity or ComponentDialog owner 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 NavigationBackHandler and rememberNavigationEventDispatcherOwner(), 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 = false to 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

Questions fréquentes

Fonctionne-t-il pour les applications à Views Android ?

Non. Le skill se limite aux applications Android Compose, les Views sont exclues.

Quelle cible Android faut-il ?

Si le compile SDK de l'application est inférieur à 36, le skill le porte à 36 ou plus.

Les boîtes de dialogue demandent-elles une configuration supplémentaire ?

Non. Les boîtes de dialogue et les feuilles modales fournissent leur propre distributeur, aucun raccordement supplémentaire n'est donc nécessaire.

Détails

Description originale de l’auteur

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

Popularité

Étoiles GitHub
10k
Position au classement
#11925
Licence
Apache-2.0
Mis à jour
29/10/2026

Ce skill vous est-il utile ?

0

Connectez-vous pour voter.

Commentaires

  • …

Autres skills de ce dépôt

Skills similaires