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 edcefd2
Show file tree
Hide file tree
Showing 2 changed files with 15 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 contentFocus = FocusRequester()
Scaffold(
topBar = { scrollBehavior ->
GlobalAnimeSearchToolbar(
Expand All @@ -44,6 +49,10 @@ fun GlobalAnimeSearchScreen(
onlyShowHasResults = state.onlyShowHasResults,
onToggleResults = onToggleResults,
scrollBehavior = scrollBehavior,
modifier = Modifier
.focusProperties {
down = contentFocus
}
)
},
) { paddingValues ->
Expand All @@ -54,6 +63,7 @@ fun GlobalAnimeSearchScreen(
onClickSource = onClickSource,
onClickItem = onClickItem,
onLongClickItem = onLongClickItem,
modifier = Modifier.focusRequester(contentFocus)
)
}
}
Expand All @@ -66,10 +76,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 @@ -45,6 +45,7 @@ fun GlobalAnimeSearchToolbar(
onlyShowHasResults: Boolean,
onToggleResults: () -> Unit,
scrollBehavior: TopAppBarScrollBehavior,
modifier: Modifier = Modifier,
) {
Column(modifier = Modifier.background(MaterialTheme.colorScheme.surface)) {
Box {
Expand All @@ -69,7 +70,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 edcefd2

Please sign in to comment.