Add keys and item animations to search grid
This commit is contained in:
parent
6d9ce31c2c
commit
1f0db6c03e
@ -2,10 +2,7 @@ package de.mm20.launcher2.ui.launcher.search
|
|||||||
|
|
||||||
import androidx.compose.foundation.horizontalScroll
|
import androidx.compose.foundation.horizontalScroll
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.*
|
||||||
import androidx.compose.foundation.lazy.LazyListScope
|
|
||||||
import androidx.compose.foundation.lazy.LazyListState
|
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.rounded.*
|
import androidx.compose.material.icons.rounded.*
|
||||||
@ -86,6 +83,7 @@ fun SearchColumn(
|
|||||||
items = favorites.toImmutableList(),
|
items = favorites.toImmutableList(),
|
||||||
columns = columns,
|
columns = columns,
|
||||||
showLabels = showLabels,
|
showLabels = showLabels,
|
||||||
|
key = "favorites",
|
||||||
reverse = reverse,
|
reverse = reverse,
|
||||||
after = {
|
after = {
|
||||||
Row(
|
Row(
|
||||||
@ -147,6 +145,7 @@ fun SearchColumn(
|
|||||||
columns = columns,
|
columns = columns,
|
||||||
showLabels = showLabels,
|
showLabels = showLabels,
|
||||||
reverse = reverse,
|
reverse = reverse,
|
||||||
|
key = "apps",
|
||||||
before = if (workApps.isNotEmpty()) {
|
before = if (workApps.isNotEmpty()) {
|
||||||
{
|
{
|
||||||
Row(
|
Row(
|
||||||
@ -191,7 +190,7 @@ fun SearchColumn(
|
|||||||
}
|
}
|
||||||
} else null
|
} else null
|
||||||
)
|
)
|
||||||
ListResults(appShortcuts.toImmutableList(), reverse)
|
ListResults(appShortcuts.toImmutableList(), reverse, key = "shortcuts")
|
||||||
val uc = unitConverter
|
val uc = unitConverter
|
||||||
if (uc != null) {
|
if (uc != null) {
|
||||||
SingleResult {
|
SingleResult {
|
||||||
@ -204,8 +203,8 @@ fun SearchColumn(
|
|||||||
CalculatorItem(calculator = calc)
|
CalculatorItem(calculator = calc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ListResults(events.toImmutableList(), reverse)
|
ListResults(events.toImmutableList(), reverse, key = "events")
|
||||||
ListResults(contacts.toImmutableList(), reverse)
|
ListResults(contacts.toImmutableList(), reverse, key = "contacts")
|
||||||
val wiki = wikipedia
|
val wiki = wikipedia
|
||||||
if (wiki != null) {
|
if (wiki != null) {
|
||||||
SingleResult {
|
SingleResult {
|
||||||
@ -218,7 +217,7 @@ fun SearchColumn(
|
|||||||
WebsiteItem(website = ws)
|
WebsiteItem(website = ws)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ListResults(files.toImmutableList(), reverse)
|
ListResults(files.toImmutableList(), reverse, key = "files")
|
||||||
item {
|
item {
|
||||||
HiddenResults()
|
HiddenResults()
|
||||||
}
|
}
|
||||||
@ -236,21 +235,31 @@ fun LazyListScope.GridResults(
|
|||||||
columns: Int,
|
columns: Int,
|
||||||
reverse: Boolean,
|
reverse: Boolean,
|
||||||
showLabels: Boolean,
|
showLabels: Boolean,
|
||||||
|
key: String,
|
||||||
before: (@Composable () -> Unit)? = null,
|
before: (@Composable () -> Unit)? = null,
|
||||||
after: (@Composable () -> Unit)? = null,
|
after: (@Composable () -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
if (items.isEmpty() && before == null && after == null) return
|
if (items.isEmpty() && before == null && after == null) return
|
||||||
|
|
||||||
if (before != null) {
|
if (before != null) {
|
||||||
item(contentType = "ListItemsBefore") {
|
item(key = "$key-before") {
|
||||||
PartialCardRow(isFirst = true, isLast = items.isEmpty() && after == null, reverse = reverse) {
|
PartialCardRow(
|
||||||
|
isFirst = true,
|
||||||
|
isLast = items.isEmpty() && after == null,
|
||||||
|
reverse = reverse
|
||||||
|
) {
|
||||||
before()
|
before()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val rows = ceil(items.size / columns.toFloat()).toInt()
|
val rows = ceil(items.size / columns.toFloat()).toInt()
|
||||||
items(rows) {
|
items(
|
||||||
|
rows,
|
||||||
|
key = {
|
||||||
|
"$key-${items[it * columns].key}"
|
||||||
|
}
|
||||||
|
) {
|
||||||
PartialCardRow(
|
PartialCardRow(
|
||||||
isFirst = it == 0 && before == null,
|
isFirst = it == 0 && before == null,
|
||||||
isLast = it == rows - 1 && after == null,
|
isLast = it == rows - 1 && after == null,
|
||||||
@ -272,8 +281,12 @@ fun LazyListScope.GridResults(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (after != null) {
|
if (after != null) {
|
||||||
item(contentType = "ListItemsAfter") {
|
item(key = "$key-after") {
|
||||||
PartialCardRow(isFirst = items.isEmpty() && before == null, isLast = true, reverse = reverse) {
|
PartialCardRow(
|
||||||
|
isFirst = items.isEmpty() && before == null,
|
||||||
|
isLast = true,
|
||||||
|
reverse = reverse
|
||||||
|
) {
|
||||||
after()
|
after()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,18 +322,24 @@ fun GridRow(
|
|||||||
fun LazyListScope.ListResults(
|
fun LazyListScope.ListResults(
|
||||||
items: ImmutableList<Searchable>,
|
items: ImmutableList<Searchable>,
|
||||||
reverse: Boolean,
|
reverse: Boolean,
|
||||||
|
key: String,
|
||||||
before: (@Composable () -> Unit)? = null,
|
before: (@Composable () -> Unit)? = null,
|
||||||
after: (@Composable () -> Unit)? = null,
|
after: (@Composable () -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
if (items.isEmpty()) return
|
if (items.isEmpty()) return
|
||||||
if (before != null) {
|
if (before != null) {
|
||||||
item(contentType = "ListItemsBefore") {
|
item(key = "$key-before") {
|
||||||
PartialCardRow(isFirst = true, isLast = false, reverse = reverse) {
|
PartialCardRow(isFirst = true, isLast = false, reverse = reverse) {
|
||||||
before()
|
before()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
items(items.size) {
|
items(
|
||||||
|
items.size,
|
||||||
|
key = {
|
||||||
|
"$key-${items[it].key}"
|
||||||
|
}
|
||||||
|
) {
|
||||||
PartialCardRow(
|
PartialCardRow(
|
||||||
isFirst = it == 0 && before == null,
|
isFirst = it == 0 && before == null,
|
||||||
isLast = it == items.lastIndex && after == null,
|
isLast = it == items.lastIndex && after == null,
|
||||||
@ -336,7 +355,7 @@ fun LazyListScope.ListResults(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (after != null) {
|
if (after != null) {
|
||||||
item(contentType = "ListItemsAfter") {
|
item(key = "$key-after") {
|
||||||
PartialCardRow(isFirst = false, isLast = true, reverse = reverse) {
|
PartialCardRow(isFirst = false, isLast = true, reverse = reverse) {
|
||||||
after()
|
after()
|
||||||
}
|
}
|
||||||
@ -367,10 +386,12 @@ fun LazyListScope.SingleResult(content: @Composable (() -> Unit)?) {
|
|||||||
if (content == null) return
|
if (content == null) return
|
||||||
item {
|
item {
|
||||||
LauncherCard(
|
LauncherCard(
|
||||||
modifier = Modifier.padding(
|
modifier = Modifier
|
||||||
horizontal = 8.dp,
|
.padding(
|
||||||
vertical = 4.dp,
|
horizontal = 8.dp,
|
||||||
)
|
vertical = 4.dp,
|
||||||
|
)
|
||||||
|
.animateItemPlacement()
|
||||||
) {
|
) {
|
||||||
content()
|
content()
|
||||||
}
|
}
|
||||||
@ -378,7 +399,7 @@ fun LazyListScope.SingleResult(content: @Composable (() -> Unit)?) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun PartialCardRow(
|
fun LazyItemScope.PartialCardRow(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
isFirst: Boolean,
|
isFirst: Boolean,
|
||||||
isLast: Boolean,
|
isLast: Boolean,
|
||||||
@ -390,6 +411,7 @@ fun PartialCardRow(
|
|||||||
Box(
|
Box(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.clipToBounds()
|
.clipToBounds()
|
||||||
|
.animateItemPlacement()
|
||||||
) {
|
) {
|
||||||
PartialLauncherCard(
|
PartialLauncherCard(
|
||||||
modifier = Modifier.padding(
|
modifier = Modifier.padding(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user