For incremental migration, keep the Fragment and replace one XML region with a `ComposeView`. If the XML already contains a Compose container, configure it in `onViewCreated`: ```kotlin override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding.composeContent.apply { setViewCompositionStrategy( ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed ) setContent { AppTheme { DetailsScreen( state = viewModel.uiState.collectAs...
Scanned 9/5/2026
Install to Claude Code
npx -y skills add HoangNguyen0403/agent-skills-standard --skill android-compose-migration --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Android Compose Migration?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-android-compose-migration-28933c9d)More formats (shields.io, HTML) on the badges page.
# Hosting Compose in an existing Fragment
For incremental migration, keep the Fragment and replace one XML region with a `ComposeView`. If the XML already contains a Compose container, configure it in `onViewCreated`:
```kotlin
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.composeContent.apply {
setViewCompositionStrategy(
ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed
)
setContent {
AppTheme {
DetailsScreen(
state = viewModel.uiState.collectAsStateWithLifecycle().value,
onAction = viewModel::onAction,
)
}
}
}
}
```
The XML container can be as small as:
```xml
<androidx.compose.ui.platform.ComposeView
android:id="@+id/composeContent"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
```
Alternatively, return a `ComposeView` directly from `onCreateView` when the entire Fragment view is the migrated surface:
```kotlin
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View = ComposeView(requireContext()).apply {
setViewCompositionStrategy(
ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed
)
setContent { AppTheme { DetailsScreen(/* state and callbacks */) } }
}
```
Keep business state in the existing `ViewModel` and pass state/callbacks into the Composable. Use `AndroidView` only for legacy Views that remain inside a Compose hierarchy, and mutate the existing View in `update` rather than creating a new one. Add a `@Preview`, compare against the XML baseline, and run `./gradlew build`. The lifecycle composition strategy is required to avoid retaining the Fragment’s view after its view lifecycle is destroyed.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!