Skip to content
Back to skills

Android Compose Migration

ASecurity

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

  • 584 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 5, 2026
developmentkotlin

Security analysis

A100/100

Pro scans all 13 files and shows the line behind each finding

Scanned September 5, 2026

npx -y skills add HoangNguyen0403/agent-skills-standard --skill android-compose-migration --agent claude-code

Installs 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 with every re-scan.

Security grade badge for Android Compose Migration
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-android-compose-migration-28933c9d/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-android-compose-migration-28933c9d)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# 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.md1.8 KB
  • eval-1.with-skill.md1.9 KB
  • eval-2.baseline.md1.8 KB
  • eval-2.with-skill.md1.9 KB
  • eval-3.baseline.md1.5 KB
  • eval-3.with-skill.md1.5 KB
  • trigger-1.md82 B
  • trigger-2.md115 B
  • trigger-3.md111 B
  • trigger-4.md113 B
  • trigger-5.md100 B
  • trigger-6.md104 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.