Skip to content
Agentmart
Submit a tool

kmp-navigation

Compose Navigation for TV: state-based screen switching, BackHandler, focus-aware transitions, and drawer/sidebar patterns

Skill by giolaq

IndexedMIT-0★ 4
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/giolaq-kmp-navigation

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Compose Navigation for TV: state-based screen switching, BackHandler, focus-aware transitions, and drawer/sidebar patterns

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/kmp-navigation

What's inside

Skill name
kmp-navigation
Description
Compose Navigation for TV: state-based screen switching, BackHandler, focus-aware transitions, and drawer/sidebar patterns
License
MIT-0
Instructions
204 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# KMP Navigation

> The kmptv template uses state-based navigation (not Jetpack Navigation Compose). This is intentional — Navigation Compose has known focus-restoration issues on TV that make it unreliable for D-pad apps.

## Navigation model

The Android TV app manages navigation via state variables in `MainScreen()`:

```kotlin
@Composable
private fun MainScreen() {
    var selectedItem by remember { mutableStateOf<ContentItem?>(null) }
    var showingDetail by rememberSaveable { mutableStateOf(false) }
    var showingVideoPlayer by rememberSaveable { mutableStateOf(false) }

    BackHandler(enabled = showingVideoPlayer || showingDetail) {
        if (showingVideoPlayer) {
            showingVideoPlayer = false
        } else if (showingDetail) {
            showingDetail = false
            selectedItem = null
        }
    }

    when {
        showingVideoPlayer && selectedItem?.videoUrl != null ->
            VideoPlayerScreen(item = selectedItem!!, onBack = { showingVideoPlayer = false })
        showingDetail && selectedItem != null ->
            ContentDetailScreen(item = selectedItem!!, onBack = { showingDetail = false })
        else ->
            HomeScreen(onItemClick = { item ->
                selectedItem = item
                showingDetail = true
            })
    }
}
```

### Why state-based, not NavHost

1. **Focus restoration:** NavHost loses focus position when popping the back stack. TV users expect to return to the exact card they left.
2. **Simplicity:** Three screens with boolean flags is easier to reason about than a NavGraph with arguments.
3. **Animation control:** `Crossfade` and custom transitions work naturally with `when` blocks.
4. **rememberSaveable:** Screen state survives configuration changes without NavGraph SavedState complexity.

## BackHandler — back stack behavior

```kotlin
import androidx.activity.compose.BackHandler

BackHandler(enabled = /* when this screen is active */) {
    // Pop this screen
}
```

**Rules:**
- Always provide `enabled` parameter scoped to the current screen. Without it, back handling fires when it shouldn't.
- Priority: innermost enabled BackHandler wins. So the player's BackHandler fires before the detail's.
- On the home screen, don't add a BackHandler — let the system handle app exit.

### Back stack ordering

```
Home (no BackHandler — system exits app)
  └── Detail (BackHandler → goes back to Home)
       └── VideoPlayer (BackHandler → goes back to Detail)
```

## Adding a new screen

1. **Create the composable** in `androidtv-app/src/main/java/.../compose/`:

```kotlin
@Composable
fun NewScreen(
    item: ContentItem,
    onBack: () -> Unit,
) {
    // Screen content
}
```

2. **Add state variable** in MainScreen:

```kotlin
var showingNewScreen by rememberSaveable { mutableStateOf(false) }
```

3. **Add to the `when` block** (order matters — more specific screens first):

```kotlin
when {
    showingVideoPlayer -> VideoPlayerScreen(...)
    showingNewScreen -> NewScreen(item = selectedItem!!, onBack = { showingNewScreen = false })
    showingDetail -> ContentDetailScreen(...)
    else -> HomeScreen(...)
}
```

4. **Add BackHandler** entry:

```kotlin
BackHandler(enabled = showingNewScreen) {
    showingNewScreen = false
}
```

## Screen transitions

The template uses `Crossfade` for the hero banner. For screen transitions, the `when` block provides an instant swap. To add animated transitions:

```kotlin
AnimatedContent(
    targetState = currentScreen,
    transitionSpec = {
        fadeIn(tween(300)) togetherWith fadeOut(tween(300))
    }
) { screen ->
    when (screen) {

From giolaq/tv-build-harness, MIT-0.

More from giolaq/tv-build-harness

Signals

Stars
4
Forks
0
Open issues
3
Last commit (this folder)
Jun 24, 2026 (4 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT-0
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from giolaq

Cite this page

kmp-navigation skill. Agent Mart. https://agentmart.dev/skills/giolaq-kmp-navigation (last updated 2026-10-24)