Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,16 @@ fun TvSearchScreen(
LaunchedEffect(scrollHeaderIntoView) {
if (scrollHeaderIntoView > 0) searchGridState.animateScrollToItem(0)
}
// The shell's counter stays raised after it is handled, and this effect
// relaunches whenever the screen re-enters composition — a Back out of a
// result included. Remember which request was handled so a return does not
// replay it, scroll to the top and pull focus off the card being restored.
var handledBackToSearchFieldRequest by rememberSaveable {
mutableIntStateOf(backToSearchFieldRequest)
}
LaunchedEffect(backToSearchFieldRequest) {
if (backToSearchFieldRequest <= 0) return@LaunchedEffect
if (backToSearchFieldRequest == handledBackToSearchFieldRequest) return@LaunchedEffect
Comment thread
Quick104 marked this conversation as resolved.
Resolved
handledBackToSearchFieldRequest = backToSearchFieldRequest
searchGridState.animateScrollToItem(0)
requestFocusUntilObserved(
maxAttempts = TvFrameRelocationMaxAttempts,
Expand Down Expand Up @@ -750,16 +758,18 @@ fun TvSearchScreen(
index,
)
},
// Same precedence as the handoff: UP from the request row
// goes to the results, else the error's "Try again", else
// the chips. Spatial search alone skipped the button and
// landed on the chips or the field.
// With results above, spatial search takes UP to the card
// just above. Pinning it to the first result failed once
// the grid scrolled that card out of composition, and the
// shell parked focus on the top bar. Otherwise the same
// precedence as the handoff: spatial search alone skipped
// "Try again" and landed on the chips or the field.
cardModifier = Modifier.focusProperties {
up = when {
state.items.isNotEmpty() -> firstResultFocusRequester
state.error != null -> feedbackActionFocusRequester
state.people.isNotEmpty() -> firstPersonFocusRequester
else -> firstFilterChipFocusRequester
when {
state.items.isNotEmpty() -> Unit
state.error != null -> up = feedbackActionFocusRequester
state.people.isNotEmpty() -> up = firstPersonFocusRequester
else -> up = firstFilterChipFocusRequester
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
},
onOpenRequestDetail = onOpenRequestDetail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,10 @@ fun TvMainShell(
val forYouFirstRowContainerFocusRequester = remember { FocusRequester() }
val searchInputFocusRequester = remember { FocusRequester() }
var searchInputHasFocus by remember { mutableStateOf(false) }
var searchBackToInputRequest by remember { mutableIntStateOf(0) }
// Saveable to match the Search screen's record of the last request it
// handled: a counter that reset on recreation while that record survived
// would read as a new request and replay the scroll and field focus.
var searchBackToInputRequest by rememberSaveable { mutableIntStateOf(0) }
// Same failure as the bar handoff: Back asks the search field to take
// focus and consumes the press. If the field never reports focus, every
// Back repeats that forever and Search cannot be left. Records the attempt
Expand Down Expand Up @@ -761,8 +764,20 @@ fun TvMainShell(
// to be guarded — and that guard is what used to swallow the failure whole.
val claimContentFocus: (String) -> Boolean = { route ->
when {
// The field is the header of the results grid, so once the results
// are scrolled it is no longer composed and cannot take focus.
// Fall back to the content group, which restores the last focused
// card, rather than failing and parking the viewer on the bar.
//
// Only when Search was already on screen as this claim began
// (currentRoute is this composition's value). Entering Search from
// another tab, the content group still holds the outgoing screen:
// the fallback would focus that and end the retries that wait for
// the field to compose.
route == TvMainRoute.Search.route ->
runCatching { searchInputFocusRequester.requestFocus() }.getOrDefault(false)
runCatching { searchInputFocusRequester.requestFocus() }.getOrDefault(false) ||
(currentRoute == TvMainRoute.Search.route &&
runCatching { contentFocusRequester.requestFocus() }.getOrDefault(false))

route == TvMainRoute.Home.route || route == TvMainRoute.Video.route -> {
val content =
Expand Down Expand Up @@ -942,8 +957,14 @@ fun TvMainShell(
val onSearchPressed: () -> Unit = {
if (TvMainRoute.Search.route != currentRoute) {
navigateToRoute(TvMainRoute.Search.route)
moveFocusToContent(TvMainRoute.Search.route)
} else {
// Already on Search, perhaps scrolled far down the results, where
// the field is not composed. Ask the screen to scroll back to the
// top and focus the field, the same as Back does.
focusState.closeProfileMenuForContent()
searchBackToInputRequest += 1
Comment thread
Quick104 marked this conversation as resolved.
Resolved
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
moveFocusToContent(TvMainRoute.Search.route)
}

fun closeMenuAnd(action: () -> Unit): () -> Unit = {
Expand Down
Loading