Repository navigation
fix(tv): return to the last focused hero action when moving up #1099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
d9c61ec
ddb4945
7b0d0f9
a32f726
0b0f8ee
c81b2eb
7892889
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,7 @@ import androidx.compose.material3.CircularProgressIndicator | |
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.CompositionLocalProvider | ||
| import androidx.compose.runtime.SideEffect | ||
| import androidx.compose.runtime.Stable | ||
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.compose.runtime.collectAsState | ||
| import androidx.compose.runtime.getValue | ||
|
|
@@ -451,10 +452,7 @@ private fun TvDetailContent( | |
| val resources = localizedResources() | ||
| val configuration = LocalConfiguration.current | ||
| val playFocus = remember { FocusRequester() } | ||
| // The circular Version control in the hero action cluster. Hoisted here so | ||
| // an Up press from the body can return to the bottom-most playback control | ||
| // without skipping straight to Play. | ||
| val selectorFocus = remember { FocusRequester() } | ||
| val heroActionFocus = remember(detail.contentId) { TvHeroActionFocus(playFocus) } | ||
| val firstCastFocus = remember { FocusRequester() } | ||
| // Focus restore for the cast rail: remembers which cast card pushed the | ||
| // person page so the return trip lands back on it instead of Play. | ||
|
|
@@ -855,9 +853,8 @@ private fun TvDetailContent( | |
| // actions section. | ||
| val returnToHero: () -> Boolean = { | ||
| coroutineScope.launch { | ||
| // Land on the selector row (the bottom-most primary control) when | ||
| // it is composed; otherwise fall back to Play | ||
| // (audiobooks, or the next-up placeholder pill). Focus moves | ||
| // Land on the hero action the viewer left; otherwise fall back to | ||
| // Play (audiobooks, or the next-up placeholder pill). Focus moves | ||
| // BEFORE the scroll so the highlight travels with the window | ||
| // instead of appearing only after it settles; when the hero has | ||
| // been disposed off-screen the requests fail and we re-focus | ||
|
|
@@ -866,14 +863,7 @@ private fun TvDetailContent( | |
| // so a requestFocus that returned false still counted as focused — | ||
| // the scroll then ran as though the highlight had already moved. | ||
| // These report the request's own answer. | ||
| val focusedImmediately = | ||
| selectorFocus.claimFocusOrReport( | ||
| target = "detail_selector", | ||
| action = "return_to_top", | ||
| ) || playFocus.claimFocusOrReport( | ||
| target = "detail_play", | ||
| action = "return_to_top", | ||
| ) | ||
| val focusedImmediately = heroActionFocus.claim(action = "return_to_top") | ||
| if (focusedImmediately) { | ||
| // Let the focus system enqueue its automatic bring-into-view | ||
| // first, then cancel/replace that scroll with the paced | ||
|
|
@@ -882,16 +872,7 @@ private fun TvDetailContent( | |
| } | ||
| listState.animateScrollToItemPaced(0) | ||
| if (!focusedImmediately) { | ||
| if (!selectorFocus.claimFocusOrReport( | ||
| target = "detail_selector", | ||
| action = "return_to_top_retry", | ||
| ) | ||
| ) { | ||
| playFocus.claimFocusOrReport( | ||
| target = "detail_play", | ||
| action = "return_to_top_retry", | ||
| ) | ||
| } | ||
| heroActionFocus.claim(action = "return_to_top_retry") | ||
| } | ||
| } | ||
| true | ||
|
|
@@ -1121,8 +1102,7 @@ private fun TvDetailContent( | |
| detail = detail, | ||
| state = state, | ||
| viewModel = viewModel, | ||
| playFocus = playFocus, | ||
| selectorFocus = selectorFocus, | ||
| focus = heroActionFocus, | ||
| onPlay = onPlay, | ||
| onSeriesClick = onSeriesClick, | ||
| onSeasonClick = onSeasonClick, | ||
|
|
@@ -1324,12 +1304,9 @@ private fun TvDetailContent( | |
| ?.takeUnless { state.entryEpisodeSelectionApplied }, | ||
| showsSeasonChips = showsSeasonChips, | ||
| onReturnToHero = returnToHero, | ||
| onReturnToSeriesSelector = if (isSeriesDetail) { | ||
| onReturnToHeroAction = if (isSeriesDetail) { | ||
| { | ||
| selectorFocus.claimFocusOrReport( | ||
| target = "detail_series_selector", | ||
| action = "season_up", | ||
| ) || returnToHero() | ||
| heroActionFocus.claim(action = "season_up") || returnToHero() | ||
| } | ||
| } else { | ||
| null | ||
|
|
@@ -1607,9 +1584,9 @@ private fun TvDetailContent( | |
| }, | ||
| // When Similar is the first body rail (movie with no | ||
| // episode rail, cast, trailers or box set), Up returns to the hero | ||
| // Play button instead of relying on geometry. | ||
| // action the viewer left instead of relying on geometry. | ||
| upFocusRequester = if (!hasEpisodeNavAbove && !showsCastSection && !showsTrailersSection && !showsBoxSetRow && collectionsRow == null) { | ||
| playFocus | ||
| heroActionFocus.target | ||
| } else { | ||
| null | ||
| }, | ||
|
|
@@ -1878,14 +1855,55 @@ internal fun seriesStarringNames(detail: ItemDetail): String? { | |
| return names.takeIf { it.isNotEmpty() }?.joinToString(", ") | ||
| } | ||
|
|
||
| /** | ||
| * The hero action row's focus targets, hoisted above the lazy hero item so the | ||
| * action the viewer left survives the hero scrolling out of composition. Up | ||
| * from the body and entry into the row return to [last], else Play, matching | ||
| * tvOS `TVDetailActionRow`. | ||
| */ | ||
| @Stable | ||
| private class TvHeroActionFocus(val play: FocusRequester) { | ||
| val startOver = FocusRequester() | ||
| val edition = FocusRequester() | ||
| val version = FocusRequester() | ||
| val audio = FocusRequester() | ||
| val subtitles = FocusRequester() | ||
| val watchlist = FocusRequester() | ||
| val more = FocusRequester() | ||
| var last by mutableStateOf(play) | ||
| var startOverShown by mutableStateOf(false) | ||
| var editionShown by mutableStateOf(false) | ||
|
|
||
| /** | ||
| * Where focus returns: [last], unless that control is hidden right now. | ||
| * Resolved on each read, not stored, because Start Over and Edition | ||
| * hide only while the next episode's details load and come back after. | ||
|
Quick104 marked this conversation as resolved.
Resolved
|
||
| */ | ||
| val target: FocusRequester | ||
| get() = when { | ||
| last === startOver && !startOverShown -> play | ||
| last === edition && !editionShown -> version | ||
|
Comment on lines
+1889
to
+1890
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Temporary fallback focus overwrites the remembered hero action When Start Over or Edition is temporarily hidden, the fallback focus callback replaces Prompt for LLMTalk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked this against the code and I'm leaving it as is. If the viewer presses Up while Start Over or Edition is hidden, focus lands on Play or Version and stays there, so that is the hero action they focused last. Up returning there next time is the rule #793 asks for. When the gap passes without the viewer entering the row, 🤖 Claude Code (claude-opus-5-5) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That distinction makes sense. If the viewer enters the hero row during the loading gap, Play or Version becomes the action they most recently focused, so subsequent returns should go there. If they don’t enter the row during the gap, resolving the fallback on read preserves the original target. I withdraw the suggestion to preserve the earlier action after focus lands on the fallback. The implementation matches the stated “last focused hero action” behavior. |
||
| else -> last | ||
| } | ||
|
|
||
| /** Focuses [target], else Play; false when neither is attached. */ | ||
| fun claim(action: String): Boolean { | ||
| val requester = target | ||
| return (requester !== play && requester.claimFocusOrReport(target = "detail_hero_action", action = action)) || | ||
| play.claimFocusOrReport(target = "detail_play", action = action) | ||
| } | ||
| } | ||
|
|
||
| private fun Modifier.rememberHeroAction(focus: TvHeroActionFocus, target: FocusRequester): Modifier = | ||
| onFocusChanged { state -> if (state.hasFocus) focus.last = target } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| @OptIn(ExperimentalComposeUiApi::class) | ||
| @Composable | ||
| private fun HeroActionRow( | ||
| detail: ItemDetail, | ||
| state: TvItemDetailUiState, | ||
| viewModel: TvItemDetailViewModel, | ||
| playFocus: FocusRequester, | ||
| selectorFocus: FocusRequester, | ||
| focus: TvHeroActionFocus, | ||
| onPlay: (contentId: String, fileId: Int?, versionChosen: Boolean, audioTrackIndex: Int?, audioPickedThisSession: Boolean, subtitleSelection: TvSubtitleLaunchSelection?, itemType: String?, resumePositionSeconds: Double?) -> Unit, | ||
| onSeriesClick: (seriesId: String) -> Unit, | ||
| onSeasonClick: (seriesId: String, seasonNumber: Int) -> Unit, | ||
|
|
@@ -2060,6 +2078,9 @@ private fun HeroActionRow( | |
| // when next-up resolves would only risk yanking focus back if the viewer had | ||
| // already moved into the seasons/episodes rails. | ||
|
|
||
| // Start Over shows only while the item is in progress. | ||
| SideEffect { focus.startOverShown = hasResume } | ||
|
|
||
| Column(verticalArrangement = Arrangement.spacedBy(12.dp)) { | ||
| // Action row — approved tvOS `HStack(spacing: 18)` mapped through the | ||
| // half-scale dp port as the button internals. Version and Subtitles use | ||
|
|
@@ -2069,10 +2090,10 @@ private fun HeroActionRow( | |
| .fillMaxWidth() | ||
| .focusProperties { | ||
| // Entering the cluster from outside (Down from the | ||
| // synopsis/facts, Up from the body) always | ||
| // lands on Play — geometric nearest-child search would | ||
| // otherwise pick whichever toggle sits closest. | ||
| enter = { playFocus } | ||
| // synopsis/facts, Up from the body) lands on the action | ||
| // the viewer left, else Play — geometric nearest-child | ||
| // search would otherwise pick whichever toggle sits closest. | ||
| enter = { focus.target } | ||
| } | ||
| .focusGroup(), | ||
| ) { | ||
|
|
@@ -2122,8 +2143,8 @@ private fun HeroActionRow( | |
| detail.type != "series" -> Modifier | ||
| EpisodeLabel.labelsByAirDate(detail.episodeLabels) -> Modifier.widthIn(min = 170.dp) | ||
| else -> Modifier.width(170.dp) | ||
| }, | ||
| focusRequester = playFocus, | ||
| }.rememberHeroAction(focus, focus.play), | ||
| focusRequester = focus.play, | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -2137,6 +2158,8 @@ private fun HeroActionRow( | |
| contentDescription = stringResource(CommonR.string.detail_startOver), | ||
| titleOnFocus = stringResource(CommonR.string.detail_startOver), | ||
| isActive = false, | ||
| modifier = Modifier.rememberHeroAction(focus, focus.startOver), | ||
| focusRequester = focus.startOver, | ||
| onClick = { | ||
| if (playReady && !playLaunchPending) { | ||
| playLaunchPending = true | ||
|
|
@@ -2191,7 +2214,12 @@ private fun HeroActionRow( | |
| } else { | ||
| viewModel::onSubtitleTrackSelected | ||
| }, | ||
| versionFocusRequester = selectorFocus, | ||
| editionFocusRequester = focus.edition, | ||
| versionFocusRequester = focus.version, | ||
| audioFocusRequester = focus.audio, | ||
| subtitleFocusRequester = focus.subtitles, | ||
| onTriggerFocused = { focus.last = it }, | ||
| onEditionsShown = { focus.editionShown = it }, | ||
| ) | ||
|
|
||
| TvSquareToggleButton( | ||
|
|
@@ -2204,6 +2232,8 @@ private fun HeroActionRow( | |
| stringResource(CommonR.string.detail_watchlistAdd) | ||
| }, | ||
| onClick = viewModel::onToggleWatchlist, | ||
| modifier = Modifier.rememberHeroAction(focus, focus.watchlist), | ||
| focusRequester = focus.watchlist, | ||
| titleOnFocus = stringResource(CommonR.string.detail_watchlist), | ||
| ) | ||
|
|
||
|
|
@@ -2214,6 +2244,8 @@ private fun HeroActionRow( | |
| contentDescription = stringResource(CommonR.string.detail_moreOptions), | ||
| titleOnFocus = stringResource(CommonR.string.detail_more), | ||
| onClick = { if (!state.isProvisional) moreOpen = true }, | ||
| modifier = Modifier.rememberHeroAction(focus, focus.more), | ||
| focusRequester = focus.more, | ||
| ) | ||
| } | ||
| } | ||
|
|
@@ -2471,7 +2503,7 @@ private fun EpisodesSection( | |
| entryEpisodeContentId: String?, | ||
| showsSeasonChips: Boolean, | ||
| onReturnToHero: () -> Boolean, | ||
| onReturnToSeriesSelector: (() -> Boolean)? = null, | ||
| onReturnToHeroAction: (() -> Boolean)? = null, | ||
| onSeasonSelected: (org.siloserver.silo.model.catalog.Season) -> Unit, | ||
| onEpisodeSelected: (EpisodeListItem) -> Unit, | ||
| onEpisodeFocused: (EpisodeListItem) -> Unit = {}, | ||
|
|
@@ -2515,9 +2547,8 @@ private fun EpisodesSection( | |
| seasons = state.seasons, | ||
| selectedSeason = state.selectedSeason, | ||
| onSeasonSelected = onSeasonSelected, | ||
| // Return to the circular Version control in the hero; if | ||
| // it is not attached yet, fall back to Play. | ||
| onDirectionUp = onReturnToSeriesSelector ?: onReturnToHero, | ||
| // Return to the hero action the viewer left, else Play. | ||
| onDirectionUp = onReturnToHeroAction ?: onReturnToHero, | ||
| horizontalContentPadding = TvDetailHorizontalInset, | ||
| ) | ||
| } else { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.