navigation-event
ما الذي تفعله
تُرشد هذه المهارة إلى التقاط إيماءات الرجوع وتشغيل رسوم الرجوع التنبؤية في تطبيق Android مبني بـ Jetpack Compose. وتغطي أيضًا الحاويات المتداخلة مثل التبويبات، والانتقال من BackHandler القديم. وهي موجهة لمطوري Android الذين يحتاجون إلى سلوك رجوع مخصص.
متى تستخدمها
- ✓عندما تحتاج إلى اعتراض إيماءة الرجوع في شاشة Compose.
- ✓عندما تريد رسوم رجوع تنبؤية في تطبيق Android لديك.
- ✓عندما تحتاج إلى نقل شيفرة BackHandler القديمة إلى مكتبة NavigationEvent.
رابط المهارة
https://github.com/android/skills/blob/main/navigation/navigation-event/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“اجعل إيماءة الرجوع تغلق الورقة السفلية أولًا في تطبيق Compose لدي، مع رسوم الرجوع التنبؤية.”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
تضبط المهارة موزّع النشاط ومعالج الرجوع في Compose، ثم تحصر كلًا منهما في الشاشة أو التبويب أو الحوار المناسب. وتغطي أيضًا ترحيل شيفرة BackHandler القديمة على إصدارات Android الأحدث.
المحتوى التقني (ملف 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
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
الأسئلة الشائعة
هل تعمل مع تطبيقات Android Views؟
لا. تقتصر المهارة على تطبيقات Compose، وتستثني Views.
ما الهدف المطلوب في 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
- آخر تحديث
- 29/10/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
agp-9-upgrade
10kيساعد وكيلك على ترقية تطبيق Android إلى Android Gradle Plugin 9 ومعالجة التغييرات الجذرية فيه. لا يناسب مشاريع Multiplatform.
camerax
10kيساعد وكيلك على بناء ميزات الكاميرا في Android باستخدام CameraX، بما في ذلك تسجيل الفيديو وأدوات الأجهزة وتأثيرات ML Kit وMedia3.
android-for-cars-parked-apps
10kيساعد وكيلك على تكييف تطبيق فيديو أو لعبة أو متصفح في Android ليعمل كتطبيق متوقف على Android Auto وAndroid Automotive.
appfunctions
10kيساعد وكيلك على إيجاد أهم المسارات في تطبيق Android وعرضها كـ AppFunctions يمكن لوكلاء الذكاء الاصطناعي وأوامر الصوت تشغيلها.
مهارات مشابهة
android-clean-architecture
280kينظّم وكيلك مشاريع أندرويد بكفاءة، ويبني الشيفرة بطريقة تجعل الصيانة وإضافة الميزات الجديدة أسهل.
compose-multiplatform-patterns
280kيساعد وكيلك على استعمال أنماط Compose Multiplatform وJetpack Compose في مشاريع KMP، وتشمل الحالة والتنقل والتصميم والأداء.
dart-flutter-patterns
280kيساعد وكيلك على كتابة شيفرة تطبيقات Dart وFlutter، باستعمال أنماط حديثة لبناء تطبيقات متينة وسهلة الإدارة.