android/skills

wear-compose-m3

Expert guidance for working with Wear OS Compose Material3.

查看源码
仓库原始内容

按源仓库内容呈现,保留标题、案例、代码、表格、链接以及原文引用的演示图片。

Prerequisites and compatibility

  1. Current Wear OS Compose version in-use: To find the installed library version, read gradle/libs.versions.toml or build.gradle.kts directly. Don't run ./gradlew dependencies or other shell commands to resolve versions.
  2. Wear OS Compose Material3 version: If an internal tool is available to establish the latest stable version {VERSION} of androidx.wear.compose:compose-material3, use that tool.
  1. Strict compliance: If a version is listed as stable, you MUST use it, unless overridden by the user. Do not downgrade based on initial "Unresolved reference" errors in the editor or outdated web search results.
  2. Kotlin version: For Wear Compose Material3, use Kotlin **2.0.0 or

higher**.

  1. Compose compiler:
  • If Kotlin version is 2.0.0+ , the project must use the org.jetbrains.kotlin.plugin.compose Gradle plugin.
  • If Kotlin version is \< 2.0.0 , the project must use kotlinCompilerExtensionVersion in composeOptions, matching the Compose to Kotlin Compatibility Map.
  1. Min SDK: Ensure minSdk is at least 25.

Gotchas

  1. Mandatory sync and validation: After updating versions in libs.versions.toml or build.gradle.kts, you must perform a Gradle sync before refactoring any code. This ensures the environment has resolved the libraries correctly.
  2. Prohibition of guessing (error protocol): If you encounter an 'Unresolved Reference' or API mismatch after a successful sync, do not attempt to 'fix' it by downgrading the library version.

Capabilities and tools

Capability 1: Migration

Use this guidance when migrating from an older version of Wear OS Compose or Horologist.

  1. Unless otherwise indicated by the developer, use the latest stable version of Wear Compose Material3 from {VERSION}.
  2. Read the migration guide.
  3. Use the official component mappings from the migration guide.
  4. Before refactoring any component (for example, Chip -\> Button), check the parameter names, slot types, and "Expressive" design tokens.
  5. Do not use the Horologist Composables, Compose Layout, or Compose Material libraries.
  6. Always check against the component guidance in Capability 4.
  7. Expect screenshot tests to fail when a migration has been performed: Even when migrating to very similar components, expected defaults for padding and positioning will have changed. Do not seek to artificially match the pre-migration screenshot, but give preference to the Material3 defaults.

Capability 2: Adding Wear OS Compose Material3 features or updating the app

Use this guidance when the developer asks to update a project which is using an earlier version of Wear OS Compose Material3, or when they ask to add further features.

  1. Unless otherwise indicated by the developer, use the latest stable version of Wear Compose Material3 from {VERSION}.
  2. Do not use the Horologist Composables, Compose Layout, or Compose Material libraries.
  3. Always check against the component guidance in Capability 4.
  4. Expect screenshot tests to fail when a migration has been performed: Even when migrating to very similar components, expected defaults for padding and positioning will have changed. Do not seek to artificially match the pre-migration screenshot, but give preference to the Material3 defaults.

Capability 3: Component samples

Use this table of reference to find canonical samples for Wear Compose components. When working with a Wear Compose component, you must use the samples linked from the table to ensure you know how to correctly use it.

Material 3 components in androidx.wear.compose.material3.*

Component / SymbolReference Samples
AlertDialog, AlertDialogDefaultsAlertDialogSample
AnimatedPage, HorizontalPagerScaffold, VerticalPagerScaffoldOneHandedGestureSamples, PageIndicatorSample, PagerScaffoldSample
AnimatedText, rememberAnimatedTextFontRegistryAnimatedTextSample
AppCardCardSample
AppScaffoldListHeaderSample, PagerScaffoldSample, ScaffoldSample, SurfaceTransformationSample, TransformingLazyColumnNotificationsSample, TransformingLazyColumnSample
ArcProgressIndicator, ArcProgressIndicatorDefaults, CircularProgressIndicator, CircularProgressIndicatorDefaults, ProgressIndicatorDefaults, SegmentedCircularProgressIndicator, drawCircularProgressIndicatorProgressIndicatorSample
ButtonAlertDialogSample, AnimatedTextSample, ButtonGroupSample, ButtonSample, DatePickerSample, DynamicColorSchemeSample, FadingExpandingLabelSample, ListHeaderSample, OneHandedGestureSamples, PageIndicatorSample, PagerScaffoldSample, PickerSample, ScaffoldSample, ScrollIndicatorSample, StepperSample, SurfaceTransformationSample, SwipeDismissableSceneStrategySample, SwipeToRevealSample, TimePickerSample, TransformationSpecSample, TransformingLazyColumnSample, TransformingLazyColumnSample
ButtonDefaultsButtonSample, CurvedTextSamples, DynamicColorSchemeSample, EdgeButtonSample, ListHeaderSample, OneHandedGestureSamples, PlaceholderSample, ScaffoldSample, ScrollAwaySample, ScrollIndicatorSample, SurfaceTransformationSample, TextButtonSample, TransformationSpecSample, TransformingLazyColumnSample, TransformingLazyColumnSample
ButtonGroupButtonGroupSample, TransformationSpecSample
CardCardSample, SwipeDismissableSceneStrategySample, SwipeToRevealSample, TransformingLazyColumnSample
CardDefaultsCardSample, SurfaceTransformationSample, SwipeToRevealSample, TransformingLazyColumnSample, TransformingLazyColumnSample
CheckboxButtonCheckboxButtonSample, SwipeToDismissBoxSample
ChildButton, OutlinedButtonButtonSample
ColorScheme, dynamicColorSchemeDynamicColorSchemeSample
CompactButton, CompactButtonDefaultsButtonSample, TransformingLazyColumnSample
ConfirmationDialog, ConfirmationDialogDefaults, FailureConfirmationDialog, FavoriteIcon, SuccessConfirmationDialog, confirmationDialogCurvedTextConfirmationDialogSample
CurvedTextDefaultsCurvedTextSamples
DatePicker, DatePickerTypeDatePickerSample
EdgeButtonEdgeButtonSample, OneHandedGestureSamples, ScaffoldSample, SwipeDismissableSceneStrategySample, TransformingLazyColumnSample
EdgeButtonSizeEdgeButtonSample
FadingExpandingLabelFadingExpandingLabelSample
FilledIconButton, FilledTonalIconButton, IconButtonColors, IconButtonShapes, OutlinedIconButtonIconButtonSample
FilledTonalButtonAlertDialogSample, ButtonSample, ConfirmationDialogSample, OpenOnPhoneDialogSample, PlaceholderSample, ScrollAwaySample, SwipeToDismissBoxSample
HeadphoneIcon, Stepper, StepperLevelIndicator, rangeSemanticsStepperSample
HorizontalPageIndicator, VerticalPageIndicatorPageIndicatorSample
IconAlertDialogSample, ButtonSample, CardSample, CheckboxButtonSample, ConfirmationDialogSample, CurvedTextSamples, DatePickerSample, EdgeButtonSample, IconButtonSample, ListHeaderSample, PlaceholderSample, ProgressIndicatorSample, RadioButtonSample, SwipeToRevealSample, SwitchButtonSample, TimePickerSample
IconButtonIconButtonSample, LevelIndicatorSample, ProgressIndicatorSample
IconButtonDefaultsIconButtonSample, ProgressIndicatorSample
IconToggleButton, IconToggleButtonDefaults, WifiOffIcon, WifiOnIconIconToggleButtonSample
LevelIndicatorLevelIndicatorSample
LinearProgressIndicatorLinearProgressIndicatorSample
ListHeaderListHeaderSample, ScrollAwaySample, SwipeDismissableSceneStrategySample, TransformingLazyColumnNotificationsSample, TransformingLazyColumnSample
ListHeaderDefaultsListHeaderSample, ScrollAwaySample, TransformingLazyColumnSample
ListSubHeaderListHeaderSample
LocalOneHandedGestureEnabled, OneHandedGestureDefaults, OneHandedGestureHorizontalPageIndicator, OneHandedGesturePageIndicatorState, OneHandedGesturePriority, OneHandedGestureScrollIndicator, OneHandedGestureScrollIndicatorState, OneHandedGestureVerticalPageIndicatorOneHandedGestureSamples
MaterialThemeAlertDialogSample, ButtonSample, CardSample, CurvedTextSamples, DynamicColorSchemeSample, LinearProgressIndicatorSample, PagerScaffoldSample, ProgressIndicatorSample, SwipeToDismissBoxSample, TimeTextSample, TransformingLazyColumnNotificationsSample
OneHandedGestureAction, OneHandedGestureClickIndicator, OneHandedGestureClickIndicatorState, oneHandedGesture, rememberOneHandedGestureConfigurationButtonSample, CardSample, OneHandedGestureSamples
OpenOnPhoneDialog, OpenOnPhoneDialogDefaults, openOnPhoneDialogCurvedTextOpenOnPhoneDialogSample
OutlinedCardCardSample, TransformingLazyColumnSample
PagerScaffoldDefaultsPageIndicatorSample, PagerScaffoldSample
PickerPickerSample
PickerGroupPickerGroupSample
RadioButton, SplitRadioButtonRadioButtonSample
ResponsiveTransformationSpec, TransformationVariableSpecSurfaceTransformationSample, TransformationSpecSample
RevealValue, SwipeToReveal, SwipeToRevealDefaults, rememberRevealStateSwipeToRevealSample
ScreenScaffoldListHeaderSample, OneHandedGestureSamples, PagerScaffoldSample, ScaffoldSample, SurfaceTransformationSample, SwipeDismissableSceneStrategySample, TransformingLazyColumnNotificationsSample, TransformingLazyColumnSample
ScreenScaffoldDefaults, ScrollIndicatorScrollIndicatorSample
ScreenStage, scrollAwayScrollAwaySample
Slider, SliderDefaultsSliderSample
SplitCheckboxButtonCheckboxButtonSample
SplitSwitchButtonSwitchButtonSample
StepperDefaults, VolumeDownIcon, VolumeUpIconLevelIndicatorSample, StepperSample
SurfaceTransformationAlertDialogSample, DynamicColorSchemeSample, ListHeaderSample, ScaffoldSample, SurfaceTransformationSample, SwipeDismissableSceneStrategySample, TransformationSpecSample, TransformingLazyColumnNotificationsSample, TransformingLazyColumnSample, TransformingLazyColumnSample
SwipeToDismissBoxSwipeToDismissBoxSample
SwitchButtonAlertDialogSample, OneHandedGestureSamples, SwitchButtonSample
TextAlertDialogSample, AnimatedTextSample, ButtonGroupSample, ButtonSample, CardSample, CheckboxButtonSample, ConfirmationDialogSample, DatePickerSample, DynamicColorSchemeSample, EdgeButtonSample, ListHeaderSample, OneHandedGestureSamples, OpenOnPhoneDialogSample, PageIndicatorSample, PagerScaffoldSample, PickerGroupSample, PickerSample, PlaceholderSample, RadioButtonSample, ScaffoldSample, ScrollAwaySample, ScrollIndicatorSample, StepperSample, SurfaceTransformationSample, SwipeDismissableSceneStrategySample, SwipeToDismissBoxSample, SwipeToRevealSample, SwitchButtonSample, TextButtonSample, TextToggleButtonSample, TimePickerSample, TransformationSpecSample, TransformingLazyColumnNotificationsSample, TransformingLazyColumnSample
TextButtonTextButtonSample
TextButtonDefaultsTextButtonSample, TextToggleButtonSample
TextToggleButton, TextToggleButtonDefaults, touchTargetAwareSizeTextToggleButtonSample
TimePicker, TimePickerTypeTimePickerSample
TimeTextScrollAwaySample, ScrollIndicatorSample, TimeTextSample
TimeTextDefaults, timeTextCurvedTextTimeTextSample
TitleCardCardSample, SurfaceTransformationSample, SwipeDismissableSceneStrategySample, SwipeToRevealSample, TransformingLazyColumnNotificationsSample, TransformingLazyColumnSample
TransformationSpecTransformationSpecSample
curvedTextCurvedTextSamples, ScrollAwaySample, TimeTextSample
firstVisibleItemLayoutItemInfo, layoutItemInfoOf, rememberTransformingLazyColumnFirstLayoutItemProviderTransformingLazyColumnSample
placeholder, placeholderShimmer, rememberPlaceholderStatePlaceholderSample
rememberPickerStatePickerGroupSample, PickerSample
rememberTransformationSpec, transformedHeightAlertDialogSample, DynamicColorSchemeSample, ListHeaderSample, ScaffoldSample, SurfaceTransformationSample, SwipeDismissableSceneStrategySample, SwipeToRevealSample, TransformationSpecSample, TransformingLazyColumnNotificationsSample, TransformingLazyColumnSample, TransformingLazyColumnSample
timeTextSeparatorScrollAwaySample, TimeTextSample

Foundation components in androidx.wear.compose.foundation.*

Component / SymbolReference Samples
AmbientMode, LocalAmbientModeManager, rememberAmbientModeManagerAmbientModeSample, OneHandedGestureSamples
AmbientTickEffectAmbientModeSample
AutoCenteringParams, ScalingLazyColumnDefaults, ScalingLazyListAnchorTypeScalingLazyColumnSample
BasicSwipeToDismissBoxSwipeToDismissBoxSample
CurvedAlignment, CurvedTextStyle, angularGradientBackground, angularSize, basicCurvedText, clearAndSetSemantics, curvedColumn, padding, radialGradientBackground, radialSize, semantics, sizeCurvedWorldSample
CurvedDirection, CurvedLayout, angularSizeDp, background, curvedBox, curvedComposable, curvedRowCurvedTextSamples, CurvedWorldSample
CurvedModifierCurvedTextSamples, CurvedWorldSample, TimeTextSample
ExperimentalWearFoundationApi, RevealValue, SwipeToReveal, rememberRevealStateSwipeToRevealSample
HorizontalPager, VerticalPager, rememberPagerStateOneHandedGestureSamples, PageIndicatorSample, PagerSamples, PagerScaffoldSample
ItemEdge, TransformingLazyColumnDefaultsTransformingLazyColumnSample
PagerDefaultsPagerScaffoldSample
RotaryScrollableDefaultsPagerScaffoldSample, RotarySamples, ScalingLazyColumnSample, TransformingLazyColumnSample
RotarySnapLayoutInfoProvider, rotaryScrollableRotarySamples
ScalingLazyColumnExpandableSample, HierarchicalFocusSample, OneHandedGestureSamples, ScalingLazyColumnSample, SwipeToRevealSample, SwipeToRevealSample
ScrollInfoProviderScrollAwaySample
SwipeToDismissValue, edgeSwipeToDismiss, rememberSwipeToDismissBoxStateSwipeToDismissBoxSample, SwipeToDismissBoxSample
TransformingLazyColumnDynamicColorSchemeSample, ListHeaderSample, OneHandedGestureSamples, ScaffoldSample, ScrollAwaySample, ScrollIndicatorSample, SurfaceTransformationSample, SwipeDismissableSceneStrategySample, SwipeToRevealSample, TransformationSpecSample, TransformingLazyColumnNotificationsSample, TransformingLazyColumnSample, TransformingLazyColumnSample
TransformingLazyColumnFirstLayoutItemProviderTransformingLazyColumnSample, TransformingLazyColumnSample
TransformingLazyColumnItemScrollProgressTransformationSpecSample
expandableButton, expandableItemsExpandableSample
expandableItem, rememberExpandableStateExpandableSample, SwipeToRevealSample
hierarchicalFocusGroupHierarchicalFocusSample
itemsSwipeDismissableSceneStrategySample, SwipeToRevealSample, TransformingLazyColumnNotificationsSample
itemsIndexedTransformingLazyColumnSample
rememberScalingLazyListStateOneHandedGestureSamples, ScalingLazyColumnSample, SwipeToRevealSample
rememberTransformingLazyColumnStateListHeaderSample, OneHandedGestureSamples, ScaffoldSample, ScrollAwaySample, ScrollIndicatorSample, SurfaceTransformationSample, SwipeDismissableSceneStrategySample, SwipeToRevealSample, TransformingLazyColumnNotificationsSample, TransformingLazyColumnSample, TransformingLazyColumnSample
requestFocusOnHierarchyActiveHierarchicalFocusSample, RotarySamples
weightCurvedWorldSample, TimeTextSample

Navigation 3 components in androidx.wear.compose.navigation3.*

Component / SymbolReference Samples
rememberSwipeDismissableSceneStrategySwipeDismissableSceneStrategySample

Capability 4: Component guidance

Mandatory: Use this capability as a checklist against any component use. It provides more holistic guidance on how to use each component in practice, beyond the component syntax.

  1. AppScaffold and ScreenScaffold
  • \[ \] Use AppScaffold as the outer container, with ScreenScaffold children.
  • \[ \] Use only ONE AppScaffold and any number of ScreenScaffold.
  1. ScalingLazyColumn - Use TransformingLazyColumn instead.
  2. TransformingLazyColumn - You will need the following imports:
kotlin
   import androidx.wear.compose.foundation.lazy.TransformingLazyColumn
   import androidx.wear.compose.foundation.lazy.TransformingLazyColumnDefaults
   import androidx.wear.compose.foundation.lazy.rememberTransformingLazyColumnState
   // ...
   import androidx.wear.compose.material3.lazy.rememberTransformationSpec
   import androidx.wear.compose.material3.lazy.transformedHeight

<br />

Canonical example:

kotlin
   val columnState = rememberTransformingLazyColumnState()
   val transformationSpec = rememberTransformationSpec()
   ScreenScaffold(
       scrollState = columnState
   ) { contentPadding ->
       TransformingLazyColumn(
           state = columnState,
           contentPadding = contentPadding
       ) {
           item {
               ListHeader(
                   modifier = Modifier
                       .fillMaxWidth()
                       .transformedHeight(this, transformationSpec)
                       .minimumVerticalContentPadding(ListHeaderDefaults.minimumTopListContentPadding),
                   transformation = SurfaceTransformation(transformationSpec)
               ) {
                   Text(text = "Header")
               }
           }
           // ... other items
           item {
               Button(
                   modifier = Modifier
                       .fillMaxWidth()
                       .transformedHeight(this, transformationSpec)
                       .minimumVerticalContentPadding(ButtonDefaults.minimumVerticalListContentPadding),
                   transformation = SurfaceTransformation(transformationSpec),
                   onClick = { /* ... */ },
                   icon = {
                       Icon(
                           imageVector = Icons.Default.Build,
                           contentDescription = "build",
                       )
                   },
               ) {
                   Text(
                       text = "Build",
                       maxLines = 1,
                       overflow = TextOverflow.Ellipsis,
                   )
               }
           }
       }
   }

<br />

  • \[ \] Use TransformingLazyColumn instead of ScalingLazyColumn.
  • \[ \] You must pass the contentPadding parameter from ScreenScaffold to the TransformingLazyColumn.
  • \[ \] Use the minimumVerticalContentPadding modifier to achieve required padding top and bottom.
  • This expects a value from defaults, such as ButtonDefaults, CardDefaults, \`ListHeaderDefaults.
  • Note: This is a scoped modifier available within TransformingLazyColumnItemScope.
  • \[ \] Ensure the list morphs and scales.
  • \[ \] Use transformedHeight modifier.
  • \[ \] Use transform = SurfaceTransform(...).
  • \[ \] If configuring a list for snapping, use flingBehavior and rotaryScrollableBehavior together:
kotlin
   val columnState = rememberTransformingLazyColumnState()
   ScreenScaffold(scrollState = columnState) { contentPadding ->
       TransformingLazyColumn(
           state = columnState,
           flingBehavior = TransformingLazyColumnDefaults.snapFlingBehavior(columnState),
           rotaryScrollableBehavior = RotaryScrollableDefaults.snapBehavior(columnState)
       ) {
           // ...
           // ...
       }
   }

<br />

  1. ScreenScaffold
  • \[ \] Guard the scrollIndicator with !LocalScrollCaptureInProgress.current.
  1. EdgeButton
  • \[ \] Do NOT use as the final item within a TransformingLazyColumn. Instead, use the slot in ScreenScaffold.
  • \[ \] When used in a TransformingLazyColumn, add the required overscroll behavior:
kotlin
   val columnState = rememberTransformingLazyColumnState()
   ScreenScaffold(
       scrollState = columnState,
       edgeButton = {
           EdgeButton(
               onClick = { /* TODO */ },
               modifier = Modifier.scrollable(
                   columnState,
                   orientation = Orientation.Vertical,
                   reverseDirection = true,
                   // Apply overscroll to the EdgeButton for proper scrolling behavior.
                   overscrollEffect = rememberOverscrollEffect(),
               )
           ) {
               Text("More")
           }
       }
   ) { contentPadding ->
       TransformingLazyColumn(
           contentPadding = contentPadding,
           state = columnState,
       ) {
           // ...
           // ...
       }
   }

<br />

  1. Column
  • \[ \] USE as a direct child of ScreenScaffold if the screen is will never scroll, even with the largest system font.
  • \[ \] Use TransformingLazyColumn instead for all other cases.
  1. Styles
  • \[ \] Do NOT hard-code text sizes, use typography from MaterialTheme.
  • \[ \] Do NOT hard-code colors, use colorScheme from MaterialTheme.
  1. Use component defaults:
  • \[ \] Components such as Button have a corresponding ButtonDefaults object.
  • \[ \] Check for and use the *Defaults object for any component when working with padding and styling values, in preference to hard-coded values.
  1. Use Wear-specific preview annotations:
  • \[ \] @WearPreviewDevices
  • \[ \] @WearPreviewFontScales
  • \[ \] Ensure the androidx.wear.compose:compose-ui-tooling dependency is included.
  1. Ambient mode
  • \[ \] Use LocalAmbientModeManager instead of AmbientLifecycleObserver.
  1. Navigation
  • \[ \] When adding navigation fresh, use Navigation3.
  • \[ \] For Navigation3 in Wear OS, use SwipeDismissableSceneStrategy() from the Wear Compose compose-navigation3 library.
  1. Comments
  • \[ \] Where any Kotlin file has been modified, ensure that the existing comments are up to date and accurately reflect any changes to the implementation.
  1. HorizontalPager or VerticalPager
  • \[ \] Use the Composable hierarchy in this order: AppScaffold, HorizontalPagerScaffold, HorizontalPager, AnimatedPage, ScreenScaffold. Or similarly for VerticalPager.
来自同一仓库

更多 Skills

全部 Skills
android
社区

android-cli

Provides instructions for installing and using the android CLI. The android command-line tool is a critical tool for Android development and helps you create new Android projects, run Android apps on devices, manage and interact with Android virtual devices (including screenshots and UI inspection), manage Android SDK components, look up official Android documentation, and discover and install official Android skills.

安装量
1
GitHub Stars
8983
最近更新
10月19日
android
社区

android-profiler

'Records and analyzes Android performance data and diagnoses performance bottlenecks across user apps, system apps, and system services, even if the user does not explicitly mention profiling or traces. Use when: recording system traces, CPU call stacks, Vulkan GPU/DRM memory, or Java/native heap profiles; analyzing Perfetto traces for UI jank, frame drops, ANRs, or app startup latency issues; investigating CPU bottlenecks, IPC/Binder storms, or thread scheduling stalls; diagnosing battery drain

安装量
1
GitHub Stars
8983
最近更新
10月19日
android
社区

agp-9-upgrade

Upgrades, or migrates, an Android project to use Android Gradle Plugin (AGP) version 9. Do not use this skill for migrating Kotlin Multiplatform (KMP) projects.

安装量
1
GitHub Stars
7850
最近更新
10月14日
android
社区

navigation-event

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+.

安装量
1
GitHub Stars
7789
最近更新
10月12日