Fix browse search query display and keyboard focus (#8781)

This commit is contained in:
stevenyomi 2022-12-22 11:14:04 +08:00 committed by GitHub
parent 8e1b5b4803
commit a8230ad574
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 16 deletions

View file

@ -319,6 +319,7 @@ fun SearchToolbar(
)
LaunchedEffect(searchClickCount) {
if (searchQuery == null) return@LaunchedEffect
if (searchClickCount == 0 && searchQuery.isNotEmpty()) return@LaunchedEffect
try {
focusRequester.requestFocus()
} catch (_: Throwable) {

View file

@ -103,6 +103,24 @@ class BrowseSourceScreenModel(
val source = sourceManager.get(sourceId) as CatalogueSource
init {
mutableState.update {
var query: String? = null
var listing = it.listing
if (listing is Listing.Search) {
query = listing.query
listing = Listing.Search(query, source.getFilterList())
}
it.copy(
listing = listing,
filters = source.getFilterList(),
toolbarQuery = query,
)
}
}
/**
* Sheet containing filter items.
*/
@ -132,22 +150,6 @@ class BrowseSourceScreenModel(
}
.stateIn(coroutineScope, SharingStarted.Lazily, emptyFlow())
init {
mutableState.update {
val initialListing = it.listing
val listing = if (initialListing is Listing.Search) {
initialListing.copy(filters = source.getFilterList())
} else {
initialListing
}
it.copy(
listing = listing,
filters = source.getFilterList(),
)
}
}
fun getColumnsPreference(orientation: Int): GridCells {
val isLandscape = orientation == Configuration.ORIENTATION_LANDSCAPE
val columns = if (isLandscape) {