يشير "التنقّل" إلى التفاعلات التي تتيح للمستخدمين التنقّل بين أجزاء المحتوى المختلفة في تطبيقك والانتقال إليها والخروج منها.
يتضمّن مكوّن التنقّل في Android Jetpack مكتبة التنقّل ومكوّن إضافي لـ Gradle يُسمى Safe Args وأدوات لمساعدتك في تنفيذ ميزة التنقّل في التطبيق. يعالج مكوّن "التنقّل" حالات استخدام متنوعة للتنقّل، بدءًا من النقرات المباشرة على الأزرار ووصولاً إلى الأنماط الأكثر تعقيدًا، مثل أشرطة التطبيقات ودرج التنقّل.
المفاهيم الرئيسية
يوفّر الجدول التالي نظرة عامة على المفاهيم الرئيسية في التنقّل والأنواع الرئيسية التي تستخدمها لتنفيذها.
الفكرة |
الغرض |
النوع |
---|---|---|
استضِف أصدقاءك وعائلتك |
عنصر واجهة مستخدِم يحتوي على وجهة التنقّل الحالية وهذا يعني أنّه عندما ينتقل المستخدم عبر تطبيق، يبدّل التطبيق بشكل أساسي الوجهات داخل مضيف التنقّل وخارجه. |
|
رسم بياني |
بنية بيانات تحدّد جميع وجهات التنقّل داخل التطبيق وكيفية ربطها ببعضها |
|
فئة "متحكم" (Controller) |
المنسّق المركزي لإدارة التنقّل بين الوجهات يوفّر جهاز التحكّم طُرقًا للتنقّل بين الوجهات ومعالجة الروابط لصفحات في التطبيق وإدارة الحزمة الخلفية وغير ذلك. |
|
الوجهة |
عقدة في الرسم البياني للتنقّل عندما ينتقل المستخدم إلى هذه العقدة، يعرض المضيف محتواها. |
يتم إنشاؤها عادةً عند إنشاء الرسم البياني للتنقّل. |
مسار الجولة |
يحدِّد وجهة بشكلٍ فريد وأي بيانات تتطلّبها. يمكنك التنقّل باستخدام المسارات. تنقلك المسارات إلى الوجهات. |
أي نوع بيانات قابل للتسلسل |
المزايا والميزات
يقدّم مكوّن التنقّل عددًا من المزايا والميزات الأخرى، بما في ذلك ما يلي:
- الحركات الانتقالية والرسوم المتحرّكة: يوفّر هذا القسم موارد موحّدة ل الحركات الانتقالية والرسوم المتحرّكة.
- الربط بصفحة معيّنة: ينفِّذ ويعالج الروابط لصفحات في التطبيق التي تنقل المستخدِم مباشرةً إلى وجهة معيّنة.
- أنماط واجهة المستخدم: تتيح أنماطًا مثل أدراج التنقّل والتنقّل في أسفل الشاشة بأقل قدر من العمل الإضافي.
- أمان النوع: يتضمّن أمان النوع إمكانية تمرير البيانات بين الوجهات مع مراعاة أمان النوع.
- توافق ViewModel: يتيح تحديد نطاق
ViewModel
لرسم بياني للتنقّل لمشاركة البيانات ذات الصلة بواجهة المستخدم بين وجهات الرسم البياني. - معاملات الأجزاء: تتيح هذه الميزة إجراء معاملات الأجزاء ومعالجتها بالكامل.
- الرجوع والانتقال للأعلى: تعالج الإجراءات "الرجوع" و"الانتقال للأعلى" بشكل صحيح تلقائيًا.
إعداد البيئة
لتضمين ميزة التنقّل في مشروعك، أضِف التبعيات التالية إلىملف build.gradle
في تطبيقك:
plugins { // Kotlin serialization plugin for type safe routes and navigation arguments id 'org.jetbrains.kotlin.plugin.serialization' version '2.0.21' } dependencies { def nav_version = "2.8.8" // Jetpack Compose Integration implementation "androidx.navigation:navigation-compose:$nav_version" // Views/Fragments Integration implementation "androidx.navigation:navigation-fragment:$nav_version" implementation "androidx.navigation:navigation-ui:$nav_version" // Feature module support for Fragments implementation "androidx.navigation:navigation-dynamic-features-fragment:$nav_version" // Testing Navigation androidTestImplementation "androidx.navigation:navigation-testing:$nav_version" // JSON serialization library, works with the Kotlin serialization plugin. implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3" }
plugins { // Kotlin serialization plugin for type safe routes and navigation arguments kotlin("plugin.serialization") version "2.0.21" } dependencies { val nav_version = "2.8.8" // Jetpack Compose integration implementation("androidx.navigation:navigation-compose:$nav_version") // Views/Fragments integration implementation("androidx.navigation:navigation-fragment:$nav_version") implementation("androidx.navigation:navigation-ui:$nav_version") // Feature module support for Fragments implementation("androidx.navigation:navigation-dynamic-features-fragment:$nav_version") // Testing Navigation androidTestImplementation("androidx.navigation:navigation-testing:$nav_version") // JSON serialization library, works with the Kotlin serialization plugin implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3") }
للحصول على معلومات عن إضافة مكوّنات معمارية أخرى إلى مشروعك، اطّلِع على مقالة إضافة مكوّنات إلى مشروعك.
الخطوات التالية
لمزيد من المستندات والموارد المتعلّقة بمكوّن التنقّل، يُرجى الاطّلاع على الموارد التالية.
أدلة تفصيلية
لمزيد من المعلومات حول كيفية تنفيذ مضيف التنقّل وNavController
،
بالإضافة إلى تفاصيل حول كيفية تفاعلهما مع ميزة "الإنشاء" وأطر عمل واجهة المستخدم الأخرى، يُرجى الاطّلاع على
الأدلة التالية:
- إنشاء وحدة تحكّم في التنقّل: يوضّح كيفية إنشاء
NavController
. - إنشاء رسم بياني للتنقّل: يوضّح هذا القسم بالتفصيل كيفية إنشاء مضيف تنقّل ورسم بياني للتنقّل.
- التنقّل إلى وجهة: توضِّح كيفية استخدام
NavController
للتنقل بين الوجهات في الرسم البياني.
الدروس التطبيقية حول الترميز
- التعرّف على Jetpack Navigation
- الأجزاء ومكوّن التنقّل
- إنشاء تطبيق قابل للتكيّف مع ميزة التنقّل الديناميكي
الفيديوهات
- التنقّل في شريط التنقّل
- أفضل 10 ممارسات للانتقال إلى نشاط واحد
- نشاط واحد: الأسباب والوقت والطريقة (مؤتمر Android Dev Summit لعام 2018)
- Android Jetpack: إدارة التنقّل في واجهة المستخدم باستخدام وحدة تحكّم في التنقّل (Google I/O '18)
نماذج
تتيح Microsoft للمستخدمين والمؤسسات العمل والتعلّم والتنظيم والتواصل والابتكار من خلال تطبيقاتهم الرائدة في Microsoft 365. ولتحقيق ذلك، تدرك الشركة أنّه من الضروري توفير تجربة إنتاجية مثالية لعملائها على جميع الأجهزة التي يستخدمونها. تساعد منصّة Square ملايين البائعين في إدارة
نشاطك التجاري، بدءًا من المعالجة الآمنة لبطاقات الائتمان ووصولاً إلى حلول نقاط البيع
إعداد متجر مجاني على الإنترنت. تم نقل المربع إلى واجهة المستخدم التعريفية
لفترة من الوقت ولكن بدلاً من الاستمرار في بناء Monzo هو مصرف وتطبيق يقدّمان
الخدمات المالية الرقمية. مهمتهم هي تحقيق الأرباح
للجميع. بدأ نظام تصميم مونزو ينحرف عن Material Design بحيث
أرادوا طريقة سهلة لكتابة المكوّنات المخصصة وصيانتها تتطوّر باستمرار، لذا اختارت Jetpack Compose. باستخدام منصة Twitter هي واحدة من أكثر وسائل التواصل الاجتماعي استخدامًا
ومنصات الوسائط التي تتيح للمستخدمين رؤية ما يحدث في العالم في أي وقت
اللحظة. بدأ الفريق الهندسي باستخدام Jetpack Compose لتجديد
نظام التصميم. بما أنّه تم تطوير مكونات واجهة المستخدم شركة Cuvva تحسّن التأمين بشكل كبير
من خلال منحك طريقة مرنة حقًا لإدارة الغلاف، كل ذلك من خلال هاتفك.
كان على مهندسي Android في Cuvva قضاء بعض الوقت في إعادة هندسة تطبيقاتهم
وقررت اعتماد تدفق بيانات أحادي الاتجاه وJetpack Compose. بهذه الطريقة
يمكنهم ShareChat is a leading social media platform in India that allows users to share their opinions, document their lives, and make new friends in their native language. The standard Red Up Green Down color scheme that many wealth management app users take for granted can be very problematic for colorblind users and those with color vision deficiency.The Futubull team is embracing users’ needs by making concrete improvements so that everyone can grasp the key to wealth. TikTok, the world’s community-driven entertainment destination, brings over 1 billion people together from around the world to discover, create and share content they love. OkCredit is a credit account management app for millions of shop owners and their customers in India. With 140M transactions month over month, and 50M+ downloads, last year alone saw OkCredit recording $50 billion worth of transactions on the app. Operating at such a huge scale scale, OkCredit created a smooth and seamless experience for all their users by focusing on reducing ANRs and improving the app startup time. Lyft is committed to app excellence. They have to be. For a rideshare app — providing a vital, time-sensitive service to millions of drivers and riders every day — a slow or unresponsive app adds unacceptable friction. Josh is a short-video app from India, launched in 2020. One of the fastest growing short-video apps with over 124 million MAUs, optimizing it across a range of devices (high, mid, low end) and maintaining a standard experience across all of them is critical for their success. Improving app startups time and making the app responsive helped them achieve success. Microsoft Lens increases developer productivity using CameraX Zomato is an Indian multinational restaurant aggregator and food delivery company serving customers across 500 cities in India alone. In order to launch new features on their Android app, Headspace spent 8 months refactoring their architecture and rewriting in Kotlin. Learn how this reboot helped their business grow. Google Photos is the home for your memories, and their development team believes people should be able to enjoy those memories across all devices. Learn how Duolingo made the business decision to focus on Android performance and how they improved developer productivity and scaled their business. Mercari allows millions of people to shop and sell almost anything. The company was founded in 2013 in Japan, and it now is the largest smartphone-focused C2C marketplace in Japan. Google Duo is a simple, high quality video calling app for everyone. With the increase of people being at home during the Covid-19 pandemic, the Duo team saw a significant increase in people using the app to stay connected with friends & family, school and work. Headspace drive business growth by investing in Android app quality. SmartNews helps millions of people discover their world everyday by sharing timely news from a diverse set of news sources. Twitter is one of the most widely used social media platforms where users can see what’s happening in the world at any given moment. Delight Room Alarmy is an alarm app that can be turned off only when the pre-selected activities, such as taking a photo, solving a math problem, shaking phone, etc., are performed by the user. The Google Home app helps set up, manage, and control your Google Home, Google Nest, and Chromecast devices—plus thousands of connected home products like lights, cameras, thermostats, and more. Truecaller is an app that offers caller identification, call blocking, chat messaging and organized inbox. The app has a basic offering and a premium version which is ad-free and has a variety of unlocked features like advanced spam blocking and call recording.تمكّنت Microsoft Outlook وTeams وOffice من زيادة عدد المستخدمين النشطين والاحتفاظ بالمستخدمين باستخدام الشاشات الكبيرة.
يحقّق المربع زيادة في الإنتاجية باستخدام Compose
تنشئ Monzo تطبيقًا أكثر فعالية وجودة باستخدام Compose
شركة Twitter تحقّق زيادة في كفاءة وسرعة المطوّرين باستخدام Compose
تنشئ شركة Cuvva أكثر سرعة وبجودة أعلى من خلال Compose.
ShareChat addresses Jank issues to increase feed scrolling by 60%
The Key to Wealth for Everyone
TikTok Optimizes User Experience with Android Tools
OkCredit’s average merchant transaction goes up by 30% after reducing ANR
Lyft improves Android app startup time for drivers by 21%
Josh sees increased customer retention by improving app startup time by 30%
Microsoft Lens increases developer productivity using CameraX
Increasing app speed by 30%: a key ingredient in Zomato’s growth recipe
Headspace's Android reboot increases monthly active users by 15%
Google Photos increased daily active users by building for large screens
Duolingo refactors on Android with MVVM and Jetpack libraries
Mercari improves UI development productivity by 56% with Jetpack Compose
Google Duo sees increased engagement and improved ratings by optimizing for larger screens
Headspace drive business growth by investing in Android app quality
SmartNews reduces lines of code by 20% and improves team morale with Kotlin
Twitter increases developer productivity and code reliability with Kotlin
Delight Room increased 90% of its organic US users with Play Console
Google Home reduces #1 cause of crashes by 33%
Truecaller brings ~40% subscribers back with real time developer notifications