Fix searchables closing on refresh

This commit is contained in:
MM20 2024-06-14 12:58:36 +02:00
parent 5a1d2660ca
commit 991f0c88d8
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
3 changed files with 23 additions and 18 deletions

View File

@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.key
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import de.mm20.launcher2.search.SavableSearchable
@ -26,18 +27,20 @@ fun SearchResultGrid(
showLabels: Boolean = LocalGridSettings.current.showLabels,
columns: Int = LocalGridSettings.current.columnCount,
reverse: Boolean = false,
highlightedItem: SavableSearchable? = null
highlightedItem: SavableSearchable? = null,
transitionKey: Any? = items
) {
SharedTransitionScope {
AnimatedContent(
items,
items to transitionKey,
modifier = it then modifier
.fillMaxWidth()
.padding(4.dp),
transitionSpec = {
fadeIn() togetherWith fadeOut()
}
) { items ->
},
contentKey = { it.second }
) { (items, _) ->
Column(
verticalArrangement = if (reverse) Arrangement.BottomReversed else Arrangement.Top
) {
@ -46,18 +49,20 @@ fun SearchResultGrid(
for (j in 0 until columns) {
val item = items.getOrNull(i * columns + j)
if (item != null) {
GridItem(
modifier = Modifier
.sharedElement(
rememberSharedContentState(item.key),
this@AnimatedContent,
)
.weight(1f)
.padding(4.dp),
item = item,
showLabels = showLabels,
highlight = item.key == highlightedItem?.key
)
key(item.key) {
GridItem(
modifier = Modifier
.sharedElement(
rememberSharedContentState(item.key),
this@AnimatedContent,
)
.weight(1f)
.padding(4.dp),
item = item,
showLabels = showLabels,
highlight = item.key == highlightedItem?.key
)
}
} else {
Spacer(modifier = Modifier.weight(1f))
}

View File

@ -54,7 +54,7 @@ fun LazyListScope.SearchFavorites(
)
) {
if (favorites.isNotEmpty()) {
SearchResultGrid(favorites)
SearchResultGrid(favorites, transitionKey = selectedTag)
} else {
Banner(
modifier = Modifier.padding(16.dp),

View File

@ -42,7 +42,7 @@ fun FavoritesWidget(widget: FavoritesWidget) {
Column {
if (favorites.isNotEmpty()) {
SearchResultGrid(favorites)
SearchResultGrid(favorites, transitionKey = selectedTag)
} else {
Banner(
modifier = Modifier.padding(16.dp),