پیمایش با Compose for Wear OS به همان سه جزء مورد نیاز در برنامههای غیر Wear OS نیاز دارد: کنترلکننده پیمایش، میزبان و نمودار.
کاتلین
val navController = rememberSwipeDismissableNavController()
NavController
API اولیه ای است که برای پیمایش در برنامه های Compose استفاده می شود. پیمایش بین اجزای سازنده را در میزبان ناوبری کنترل می کند که در Wear OS SwipeDismissableNavHost
است.
کاتلین
val navController = rememberSwipeDismissableNavController()
SwipeDismissableNavHost(
navController = navController,
startDestination = "message_list"
) {
// TODO: build navigation graph
}
مانند NavHost
composable ، به کنترل کننده ناوبری، مسیر برای مقصد شروع و سازنده گراف ناوبری که در اینجا به عنوان یک لامبدای انتهایی نشان داده شده است، اشاره می کند.
مقصد شروع باید در سازنده نمودار ناوبری، همراه با سایر مقاصدی که باید با کنترل کننده ناوبری قابل پیمایش باشد، ارائه شود.
در برنامه Wear OS خود،
SwipeDismissableNavHost
به عنوان محتوایی از
AppScaffold
برای پشتیبانی از اجزای سطح بالا مانند زمان، نشانگر اسکرول/موقعیت، و نشانگر صفحه اعلام کنید. از یک شی
AppScaffold
در بالای
SwipeDismissableNavHost
و
ScreenScaffold
در سطح صفحه استفاده کنید تا به طور پیشفرض یک شی
TimeText
به صفحه اضافه کنید و مطمئن شوید که هنگام حرکت بین صفحهها به درستی متحرک میشود. علاوه بر این،
ScreenScaffold
یک
PositionIndicator
برای محتوای قابل پیمایش اضافه می کند.
AppScaffold {
val navController = rememberSwipeDismissableNavController()
SwipeDismissableNavHost(
navController = navController,
startDestination = "message_list"
) {
composable("message_list") {
MessageList(onMessageClick = { id ->
navController.navigate("message_detail/$id")
})
}
composable("message_detail/{id}") {
MessageDetail(id = it.arguments?.getString("id")!!)
}
}
}
}
// Implementation of one of the screens in the navigation
@Composable
fun MessageDetail(id: String) {
// .. Screen level content goes here
val scrollState = rememberTransformingLazyColumnState()
val padding = rememberResponsiveColumnPadding(
first = ColumnItemType.BodyText
)
ScreenScaffold(
scrollState = scrollState,
contentPadding = padding
) {
// Screen content goes here
برای کسب اطلاعات بیشتر درباره Jetpack Navigation، به پیمایش با نوشتن مراجعه کنید یا به آزمایشگاه کد پیمایش Jetpack Compose بروید.
{% کلمه به کلمه %}
{% آخر کلمه %} برای شما توصیه می شود
{% کلمه به کلمه %} {% آخر کلمه %}
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-08-28 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-08-28 بهوقت ساعت هماهنگ جهانی."],[],[],null,["Compose for Wear OS Material version 2.5 3\n\n*** ** * ** ***\n\nThe [Navigation component](/guide/navigation) in Android Jetpack provides\nsupport for Jetpack Compose applications. You can navigate between composables\nwhile taking advantage of the Navigation component's infrastructure and\nfeatures.\n\nThis page describes the differences with Jetpack Navigation on Compose for Wear\nOS.\n| **Note:** If you are not familiar with the Navigation component, review the [Navigating with Compose](/jetpack/compose/navigation) resources before continuing.\n\nSetup\n\nUse the following dependency in your app module's build.gradle file: \n\nKotlin \n\n```kotlin\ndependencies {\n def wear_compose_version = \"1.5.0\"\n implementation \"androidx.wear.compose:compose-navigation:$wear_compose_version\"\n}\n```\n\nThis is used **instead** of the `androidx.navigation:navigation-compose`\nartifact because it provides alternative implementations specific to Wear OS.\n\nCreate a navigation controller, host and graph\n\nNavigating with Compose for Wear OS requires the same three components needed on\nnon-Wear OS apps: the navigation controller, host and graph.\n\nUse\n[`rememberSwipeDismissableNavController()`](/reference/kotlin/androidx/wear/compose/navigation/package-summary#rememberSwipeDismissableNavController())\nto create an instance of `WearNavigator`, an implementation of `NavController`\nsuitable for Wear OS applications: \n\nKotlin \n\n```kotlin\nval navController = rememberSwipeDismissableNavController()\n```\n\nThe [`NavController`](/reference/kotlin/androidx/navigation/NavController) is\nthe primary API used to navigate in Compose applications. It controls navigating\nbetween composables in the navigation host which, on Wear OS, is\n[`SwipeDismissableNavHost`](/reference/kotlin/androidx/wear/compose/navigation/package-summary#SwipeDismissableNavHost(androidx.navigation.NavHostController,kotlin.String,androidx.compose.ui.Modifier,androidx.wear.compose.navigation.SwipeDismissableNavHostState,kotlin.String,kotlin.Function1)). \n\nKotlin \n\n```kotlin\nval navController = rememberSwipeDismissableNavController()\nSwipeDismissableNavHost(\n navController = navController,\n startDestination = \"message_list\"\n) {\n // TODO: build navigation graph\n}\n```\n\nLike the\n[`NavHost` composable](/reference/kotlin/androidx/navigation/compose/package-summary#NavHost(androidx.navigation.NavHostController,kotlin.String,androidx.compose.ui.Modifier,kotlin.String,kotlin.Function1)),\nit takes a reference to the navigation controller, the route for the start\ndestination, and the builder for the navigation graph which is shown here as a\ntrailing lambda.\n\nThe start destination must be provided in the navigation graph builder, along\nwith all other destinations that should be navigable with the navigation\ncontroller.\nIn your Wear OS app, declare [`SwipeDismissableNavHost`](/reference/kotlin/androidx/wear/compose/navigation/package-summary#SwipeDismissableNavHost(androidx.navigation.NavHostController,androidx.navigation.NavGraph,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.wear.compose.navigation.SwipeDismissableNavHostState)) as a content of the [`AppScaffold`](/reference/kotlin/androidx/wear/compose/material3/package-summary#AppScaffold(androidx.compose.ui.Modifier,kotlin.Function0,kotlin.Function1)) to support top-level components like time, scroll/position indicator, and page indicator. Use a [`AppScaffold`](/reference/kotlin/androidx/wear/compose/material3/package-summary#AppScaffold(androidx.compose.ui.Modifier,kotlin.Function0,kotlin.Function1)) object above the [`SwipeDismissableNavHost`](/reference/kotlin/androidx/wear/compose/navigation/package-summary#SwipeDismissableNavHost(androidx.navigation.NavHostController,androidx.navigation.NavGraph,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.wear.compose.navigation.SwipeDismissableNavHostState)) and the [`ScreenScaffold`](/reference/kotlin/androidx/wear/compose/material3/package-summary#ScreenScaffold(androidx.wear.compose.foundation.lazy.ScalingLazyListState,kotlin.Function1,androidx.compose.ui.Modifier,androidx.compose.foundation.layout.PaddingValues,kotlin.Function0,kotlin.Function1,androidx.compose.ui.unit.Dp,kotlin.Function2)) at the screen level to add a `TimeText` object to the screen by default and to make sure it animates correctly when navigating between screens. Additionally, `ScreenScaffold` adds a `PositionIndicator` for scrollable content. \n\n```kotlin\n AppScaffold {\n val navController = rememberSwipeDismissableNavController()\n SwipeDismissableNavHost(\n navController = navController,\n startDestination = \"message_list\"\n ) {\n composable(\"message_list\") {\n MessageList(onMessageClick = { id -\u003e\n navController.navigate(\"message_detail/$id\")\n })\n }\n composable(\"message_detail/{id}\") {\n MessageDetail(id = it.arguments?.getString(\"id\")!!)\n }\n }\n }\n}\n\n// Implementation of one of the screens in the navigation\n@Composable\nfun MessageDetail(id: String) {\n // .. Screen level content goes here\n val scrollState = rememberTransformingLazyColumnState()\n\n val padding = rememberResponsiveColumnPadding(\n first = ColumnItemType.BodyText\n )\n\n ScreenScaffold(\n scrollState = scrollState,\n contentPadding = padding\n ) {\n // Screen content goes here \nhttps://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/wear/src/main/java/com/example/wear/snippets/m3/navigation/Navigation.kt#L44-L76\n```\n\nTo learn more about Jetpack Navigation, see\n[Navigating with Compose](/jetpack/compose/navigation) or take the\n[Jetpack Compose Navigation code lab](/codelabs/jetpack-compose-navigation).\n\nRecommended for you\n\n- Note: link text is displayed when JavaScript is off\n- [Migrate Jetpack Navigation to Navigation Compose](/develop/ui/compose/migrate/migration-scenarios/navigation)\n- [Navigation with Compose](/develop/ui/compose/navigation)\n- [Navigate between screens with Compose](/codelabs/basic-android-kotlin-compose-navigation)"]]