xml-to-compose-migration-pro
Skill8 starsChanged 12 days agoMITView on GitHub
Reviews and assists migration from XML layouts + Fragments to Jetpack Compose. Covers incremental interop (AndroidView / ComposeView), layout translation (ConstraintLayout / LinearLayout / FrameLayout → Modifier), RecyclerView → LazyColumn with keys, Fragment → Composable, Navigation Component → Navigation-Compose, ViewModel bridging, and XML themes → MaterialTheme.
In this repository40 other files it gives its agents.
- AGENTS.mdAGENTS.md
- docs/agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- android-accessibility-proSkill
- android-adaptive-layout-proSkill
- android-compose-proSkill
- android-coroutines-proSkill
- android-design-system-proSkill
- android-gradle-architecture-proSkill
- android-library-proSkill
- android-memory-storage-proSkill
- android-modularization-proSkill
- app-intents-proSkill
- beta-deployment-proSkill
- coredata-swift6-proSkill
- cross-platform-parity-proSkill
- flaky-tests-proSkill
- foundation-models-proSkill
- instruments-profiling-proSkill
- linting-proSkill
- localization-proSkill
- motion-design-proSkill
- r8-shrink-proSkill
- store-compliance-proSkill
- swift-accessibility-proSkill
- swift-adaptive-layout-proSkill
- swift-concurrency-proSkill
- swiftdata-proSkill
- swift-design-system-proSkill
- swift-docc-proSkill
- swift-error-handling-proSkill
- swift-library-proSkill
- swift-logging-proSkill
- swift-memory-storage-proSkill
- swift-modularization-proSkill
- swift-package-proSkill
- swift-testing-proSkill
- swiftui-proSkill
- visionos-proSkill
- xcode-security-proSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 23
If doing a partial review, load only the relevant reference files.
- Very specific: line 25
Official companion: when Google's Android skills (android/skills, Apache-2.0) are installed, see migrate-xml-views-to-jetpack-compose.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Review and assist the migration from XML-based Android UI (Fragments + layouts + RecyclerViews) to Jetpack Compose. Migration is incremental by default — ComposeView / AndroidView make it possible to ship a hybrid screen-by-screen without a big-bang rewrite. Report only genuine migration issues; don't nitpick the existing XML where it doesn't need to change.
Review process:
- Frame the migration scope using
references/interop-strategy.md— incremental vs all-at-once, where to put interop boundaries. - Translate layouts using
references/layout-migration.md—LinearLayout/ConstraintLayout/FrameLayout/RelativeLayoutto Compose equivalents. - Translate RecyclerViews using
references/recyclerview-to-lazy.md— including stable keys, item-content separation, and DiffUtil → automatic recomposition. - Translate Fragments using
references/fragment-to-composable.md— lifecycle ownership, ViewBinding → parameters, animations. - Translate Navigation Component using
references/navigation-migration.md—NavGraphXML →NavHostKotlin DSL. - Bridge ViewModels using
references/viewmodel-bridge.md— existing ViewModels stay; only the View layer changes. - Translate themes using
references/themes-styles.md—styles.xml→MaterialTheme(colorScheme, typography, shapes).
If doing a partial review, load only the relevant reference files.
Official companion: when Google's Android skills (android/skills, Apache-2.0) are installed, see migrate-xml-views-to-jetpack-compose. Follow its step order when it's installed; this skill adds the interop, RecyclerView, Fragment, and theme mappings.
Core Instructions
- Migrate incrementally. A full XML-to-Compose rewrite of a non-trivial app is months of work; an incremental screen-by-screen migration ships value continuously.
ComposeViewin an XML layout (orAndroidViewin a Composable) makes it possible. - Existing ViewModels stay. Compose works with
ViewModel+StateFlow+LiveDatawithout changes. The migration is a View-layer concern, not a state-layer one. - Don't preserve XML idioms in Compose. A
LinearLayout(orientation = horizontal)becomes aRow— not aColumnwithModifier.fillMaxWidth().wrapContentHeight(). A literal translation produces awkward Compose. - Test parity before deleting XML. Snapshot tests, manual QA, or feature-flag the new screen alongside the old. Don't delete the XML in the same PR that introduces the Composable.
- Use semantic
testTagfor tests, not preservedandroid:idvalues. XML view IDs (R.id.submit_button) don't carry over; Compose usesModifier.testTag(...)andModifier.semantics { contentDescription = ... }. AndroidView { factory: ... update: ... }is for one-way binding from Compose state to aView. Don't try to round-trip — if state needs to flow back, lift it.
Output Format
For migration reviews, organize findings by file. For each issue:
- State the file and the XML element / Kotlin class.
- Name the migration concern.
- Show the XML/Fragment "before" and the Compose "after".
For migration work (rewriting a screen), make the changes directly and produce a final patch with the old XML deleted (or feature-flagged) and the new Composable + ViewModel wiring in place.
Example output:
res/layout/fragment_settings.xml + SettingsFragment.kt
Migrate to SettingsScreen Composable + Navigation-Compose route.
// Before (SettingsFragment.kt) — Fragment + ViewBinding + RecyclerView
class SettingsFragment : Fragment() {
private var _binding: FragmentSettingsBinding? = null
private val binding get() = _binding!!
private val viewModel: SettingsViewModel by viewModels()
override fun onCreateView(...): View {
_binding = FragmentSettingsBinding.inflate(inflater, container, false)
binding.recyclerView.adapter = SettingsAdapter { onClick(it) }
viewModel.items.observe(viewLifecycleOwner) { /* ... */ }
return binding.root
}
}
// After
@Composable
fun SettingsScreen(
onItemClick: (SettingsItem) -> Unit,
viewModel: SettingsViewModel = hiltViewModel()
) {
val state by viewModel.state.collectAsStateWithLifecycle()
LazyColumn(modifier = Modifier.fillMaxSize()) {
items(state.items, key = { it.id }) { item ->
SettingsRow(item = item, onClick = { onItemClick(item) })
}
}
}RecyclerView's DiffUtil is replaced by Compose's reference-equality-based recomposition. Provide a stable key (e.g., it.id) so Compose can match items across emissions.
Summary
- State exposure (medium):
SettingsViewModel.itemsisLiveData— migrate toStateFlowforcollectAsStateWithLifecycle()consistency with other migrated screens. - Theme (low): New
SettingsScreenreferencesMaterialTheme.colorScheme.surface; ensure the host theme defines a non-defaultcolorScheme.surface.
End of example.
References
references/interop-strategy.md— incremental vs all-at-once,ComposeViewin an XML layout,AndroidViewin a Composable, choosing screen-level vs widget-level migration boundaries.references/layout-migration.md— XML layouts → Compose equivalents:LinearLayout→Row/Column,ConstraintLayout→Modifierconstraints +ConstraintLayoutComposable,FrameLayout→Box,ScrollView→Modifier.verticalScroll(). Padding/margin/weight translation.references/recyclerview-to-lazy.md—RecyclerView.Adapter→LazyColumn/LazyRowwith stable keys;DiffUtil→ reference-equality recomposition; pagination viapaging-compose.references/fragment-to-composable.md—Fragmentlifecycle → Composable lifecycle,ViewBinding→ Composable parameters, fragment transactions → navigation route changes, ActivityResultLauncher / system permissions in Compose.references/navigation-migration.md— XMLnavigation/nav_graph.xml→ KotlinNavHost+composable("route"), type-safe arguments, deep links, navigation results.references/viewmodel-bridge.md— existingViewModels carry over;viewModel()/hiltViewModel(),LiveData→observeAsState()(or migrate toStateFlow+collectAsStateWithLifecycle()),SavedStateHandleunchanged.references/themes-styles.md—styles.xmlthemes →MaterialTheme(colorScheme, typography, shapes), dark/light handling, dynamic color (dynamicColorScheme), per-screen theme overrides.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

