Skip to content

inehemiasm/AiAssistant / skills/migrate-xml-views-to-jetpack-compose

migrate-xml-views-to-jetpack-compose

Verified

Provides a structured workflow for migrating an Android XML View to Jetpack Compose. This skill details the step-by-step process, from planning and dependency setup, to theming and layout migration, validation and XML cleanup. Use this skill when you need to migrate an XML View to Jetpack Compose in an Android project. It solves the problem of converting the UI of a legacy XML View into modern, declarative Compose components while maintaining interoperability.

references/xml-layout-migration.md

View on GitHub
## 1. Structural analysis \& mapping

**Identify the precise mapping** between XML elements and Compose equivalents.
You must determine:

- The exact `@Composable` functions (e.g., `ConstraintLayout`, `Column`, `LazyColumn`) that replace the XML tag hierarchy.
- The specific parameters and `Modifier` extensions required to replicate XML attributes (e.g., `layout_width`, `padding`, `elevation`).
- The appropriate state management strategy for interactive elements.

## 2. Migration execution

**Convert the XML layout code to Jetpack Compose**, ensuring the visual
hierarchy and layout logic are preserved while leveraging Compose's declarative
nature.

## 3. Theming \& design system integrity

**Do not use hard-coded values.** Follow these rules for styling:

- **Token Alignment:** Cross-reference XML dimensions, colors, and style attributes with the existing Compose `Theme` (e.g., `MaterialTheme.colorScheme` or custom design system tokens).
- **Reuse over Creation:** If matching values exist in the current Compose theme, reuse them. If a value is missing but required for the design, define it within the theme structure rather than hard-coding it in the Composable.
- **Project Consistency:** You **MUST** strictly adhere to existing code conventions, naming standards, and implementation patterns found in the project. **Prioritize** project-specific reusable components over generic Material defaults.

## 4. Component layering \& reusability

Evaluate if the XML layout serves as a foundation-level design system component
(reused across the app with a distinct role). If it is:

- **Create a reusable composable:** Do not just inline the code. Define a new standalone `@Composable`.
- **Parameterization:** Expose specific parameters for variable data (text, colors, styles) and use `Modifier` for layout-specific customizations.
- **Feature parity \& restriction:** Ensure the new composable enforces the same UI constraints as the original XML component, preventing unauthorized style overrides while maintaining the intended flexibility.

Example before migration:

    <style
        name="Widget.Rounded.Button"
        parent="Widget.Button.Borderless">
        <item name="android:fontFamily">sans-serif-medium</item>
        <item name="android:minWidth">@dimen/min_width</item>
        <item name="android:paddingStart">@dimen/padding_2</item>
        <item name="android:paddingEnd">@dimen/padding_2</item>
        <item name="cornerRadius">8dp</item>
    </style>

Example after migration:


```kotlin
@Composable
fun RoundedBorderlessButton(
    text: String,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    enabled: Boolean = true
) {
    TextButton(
        onClick, modifier
            .defaultMinSize(minWidth = dimensionResource(R.dimen.min_width))
            .padding(
                start = dimensionResource(R.dimen.padding_2),
                end = dimensionResource(R.dimen.padding_2)
            ), enabled, shape = RoundedCornerShape(8.dp),
        colors = ButtonDefaults.textButtonColors(
            contentColor = MaterialTheme.colorScheme.primary
        )
    ) {
        Text(
            text = text,
            style = MaterialTheme.typography.bodyMedium.copy(
                fontFamily = FontFamily.SansSerif,
                fontWeight = FontWeight.Medium
            )
        )
    }
}
```

<br />

*** ** * ** ***

## 5. Output requirements

- Provide the full Kotlin file content.
- Include necessary imports.
- Add documentation comments (`/** ... */`) explaining the mapping logic for complex transformations.
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall