Skip to content

Commit

Permalink
fix: focus between toolbar and content on global anime search
Browse files Browse the repository at this point in the history
  • Loading branch information
hollowshiroyuki committed Jun 1, 2024
1 parent 6d642cb commit e692e2b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.focus.focusRequester
import eu.kanade.presentation.browse.GlobalSearchErrorResultItem
import eu.kanade.presentation.browse.GlobalSearchLoadingResultItem
import eu.kanade.presentation.browse.GlobalSearchResultItem
Expand All @@ -30,6 +34,7 @@ fun GlobalAnimeSearchScreen(
onClickItem: (Anime) -> Unit,
onLongClickItem: (Anime) -> Unit,
) {
val (toolbarFocus, contentFocus) = FocusRequester.createRefs()
Scaffold(
topBar = { scrollBehavior ->
GlobalAnimeSearchToolbar(
Expand All @@ -44,6 +49,11 @@ fun GlobalAnimeSearchScreen(
onlyShowHasResults = state.onlyShowHasResults,
onToggleResults = onToggleResults,
scrollBehavior = scrollBehavior,
modifier = Modifier
.focusRequester(toolbarFocus)
.focusProperties {
down = contentFocus
}
)
},
) { paddingValues ->
Expand All @@ -54,6 +64,7 @@ fun GlobalAnimeSearchScreen(
onClickSource = onClickSource,
onClickItem = onClickItem,
onLongClickItem = onLongClickItem,
modifier = Modifier.focusRequester(contentFocus)
)
}
}
Expand All @@ -66,10 +77,12 @@ internal fun GlobalSearchContent(
onClickSource: (AnimeCatalogueSource) -> Unit,
onClickItem: (Anime) -> Unit,
onLongClickItem: (Anime) -> Unit,
modifier: Modifier = Modifier,
fromSourceId: Long? = null,
) {
LazyColumn(
contentPadding = contentPadding,
modifier = modifier
) {
items.forEach { (source, result) ->
item(key = source.id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.material3.VerticalDivider
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.focusRequester
import eu.kanade.presentation.components.SearchToolbar
import eu.kanade.tachiyomi.ui.browse.anime.source.globalsearch.AnimeSourceFilter
import tachiyomi.i18n.MR
Expand All @@ -45,6 +46,7 @@ fun GlobalAnimeSearchToolbar(
onlyShowHasResults: Boolean,
onToggleResults: () -> Unit,
scrollBehavior: TopAppBarScrollBehavior,
modifier: Modifier = Modifier,
) {
Column(modifier = Modifier.background(MaterialTheme.colorScheme.surface)) {
Box {
Expand All @@ -69,7 +71,8 @@ fun GlobalAnimeSearchToolbar(
Row(
modifier = Modifier
.horizontalScroll(rememberScrollState())
.padding(horizontal = MaterialTheme.padding.small),
.padding(horizontal = MaterialTheme.padding.small)
.then(modifier),
horizontalArrangement = Arrangement.spacedBy(MaterialTheme.padding.small),
) {
// TODO: make this UX better; it only applies when triggering a new search
Expand Down

0 comments on commit e692e2b

Please sign in to comment.