Android Compose Migration
ASecurityFor 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...
- 584 stars
- 0 votes
- 0 copies
- 3 views
- Added September 5, 2026
Security analysis
100/100Pro scans all 13 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill android-compose-migration --agent claude-codeAre you the author of Android Compose Migration?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-android-compose-migration-28933c9d)# 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.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
- trigger-5.md
- trigger-6.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.