本文へスキップ
Skillpedia
モバイルアプリ10k · #11925

navigation-event

できること

このスキルは、Jetpack Composeのアプリで戻るジェスチャーを捕まえ、予測的な戻るのアニメーションを動かす方法を導きます。タブのような入れ子のコンテナや、古いBackHandlerからの移行も扱います。独自の戻る操作が必要なAndroid開発者向けです。

使う場面

  • ✓Composeの画面で、戻るジェスチャーを横取りする必要があるとき。
  • ✓Androidアプリで、予測的な戻るのアニメーションを使いたいとき。
  • ✓古いBackHandlerのコードを、NavigationEventライブラリに移行したいとき。

スキルのリンク

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

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/android/skills/blob/main/navigation/navigation-event/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“Composeアプリで、戻るジェスチャーでまず下部のシートを閉じるようにし、予測的な戻るのアニメーションも付けてください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

このスキルは、アクティビティのディスパッチャーとComposeの戻る操作のハンドラーを設定し、それぞれを適切な画面、タブ、ダイアログに限定します。また、新しいAndroidのバージョンで古いBackHandlerのコードを移行する方法も扱います。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)を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

よくある質問

Android Viewsのアプリでも動きますか?

いいえ。このスキルはComposeのAndroidアプリに限られ、Viewは対象外です。

必要なAndroidのターゲットは何ですか?

アプリのcompile SDKが36未満の場合、このスキルは36以上に引き上げます。

ダイアログには追加の設定が必要ですか?

いいえ。ダイアログとボトムシートは独自のディスパッチャーを持つため、追加の配線は不要です。

詳細

作者による元の説明

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

人気

GitHubのスター
10k
ランキング
#11925
ライセンス
Apache-2.0
更新日
2026/10/29

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル