وجهات Composable والمسارات
سجّل كل شاشة كمسار
وجهات Composable والمسارات درس مجاني في Jetpack Compose Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Jetpack Compose Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Screens as Destinations
Every screen in your graph is a destination. You register one with the composable builder inside the NavHost, naming it with a route.
composable("home") { HomeScreen() }What a Route Really Is
A route is a unique string key for a destination. Compose matches the string you navigate to against the routes you declared.
Keep Routes in Constants
Typos in raw strings cause silent failures. Store each route as a constant so the compiler catches mistakes for you.
object Routes {
const val HOME = "home"
const val SETTINGS = "settings"
}A Sealed Class of Screens
For larger apps, a sealed class groups all routes in one place. It makes adding screens safe and easy to discover.
sealed class Screen(val route: String) {
object Home : Screen("home")
object Settings : Screen("settings")
}Register Each Destination
List every screen with its own composable block. The lambda body is the UI shown when that route becomes active.
NavHost(navController, startDestination = Screen.Home.route) {
composable(Screen.Home.route) { HomeScreen() }
composable(Screen.Settings.route) { SettingsScreen() }
}Navigate to a Route
Use the same route string to move there. The NavController finds the matching destination and the NavHost renders it.
navController.navigate(Screen.Settings.route)Routes Must Be Unique
Two destinations cannot share a route. Each route is an address, and duplicate addresses make navigation ambiguous and unreliable.
Pass the Controller Down
Screens often trigger navigation, so hand each destination a way to navigate. A common pattern passes lambdas instead of the whole controller.
composable("home") {
HomeScreen(onOpenSettings = { navController.navigate("settings") })
}Keep Screens Decoupled
Passing lambdas instead of the NavController keeps screens testable and reusable. The screen says what happened, not how to navigate.
Routes Look Like URLs
Treat routes like little URLs. This style pays off later when you add arguments and deep links that open routes from outside the app.
Group Related Flows
As graphs grow, you can split screens into nested graphs with their own routes. This keeps a feature's destinations tidy and self-contained.
Quick Check
Why prefer constants or a sealed class for routes?
Recap
You learned that each screen is a destination with a unique route, and that constants or a sealed class keep those routes safe and organized. 🗂️
الأسئلة الشائعة
هل درس «وجهات Composable والمسارات» مجاني؟
نعم — نص درس «وجهات Composable والمسارات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Jetpack Compose Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Jetpack Compose Academy 4 دروس في المجموع.
ماذا ستتعلم في «وجهات Composable والمسارات»؟
سجّل كل شاشة كمسار تتمرن على Jetpack Compose Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Jetpack Compose Academy؟
لا تُشترط خبرة سابقة. Jetpack Compose Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «وجهات Composable والمسارات»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Jetpack Compose Academy هذا؟
نعم. كل درس في Jetpack Compose Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- NavController وNavHost
- وجهات Composable والمسارات
- تمرير الوسائط بين الشاشات
- مكدس الرجوع والروابط العميقة