Bring back tag expand / collapse shared element transition

Surely the bug that crashes the launcher has been fixed by now :clueless:
This commit is contained in:
MM20 2024-11-22 17:51:54 +01:00
parent 5dd387fe32
commit cd803974de
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389

View File

@ -2,6 +2,7 @@ package de.mm20.launcher2.ui.common
import androidx.compose.animation.AnimatedContent import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.EnterExitState import androidx.compose.animation.EnterExitState
import androidx.compose.animation.SharedTransitionScope
import androidx.compose.animation.core.animateFloat import androidx.compose.animation.core.animateFloat
import androidx.compose.foundation.ScrollState import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.horizontalScroll
@ -53,146 +54,94 @@ fun FavoritesTagSelector(
) { ) {
val sheetManager = LocalBottomSheetManager.current val sheetManager = LocalBottomSheetManager.current
AnimatedContent( SharedTransitionScope {
modifier = Modifier AnimatedContent(
.fillMaxWidth() modifier = it
.padding( .fillMaxWidth()
top = if (reverse) 8.dp else 4.dp, .padding(
bottom = if (reverse) 4.dp else 8.dp, top = if (reverse) 8.dp else 4.dp,
end = if (editButton) 8.dp else 0.dp bottom = if (reverse) 4.dp else 8.dp,
), end = if (editButton) 8.dp else 0.dp
targetState = expanded, ),
) { targetState = expanded,
if (!it) { ) {
val canScroll by remember { if (!it) {
derivedStateOf { scrollState.canScrollForward || scrollState.canScrollBackward } val canScroll by remember {
} derivedStateOf { scrollState.canScrollForward || scrollState.canScrollBackward }
Row {
Row(
modifier = Modifier
.weight(1f)
.consumeAllScrolling()
.horizontalScroll(scrollState)
.padding(end = 12.dp),
) {
FilterChip(
modifier = Modifier
.padding(start = 16.dp),
selected = selectedTag == null,
onClick = { onSelectTag(null) },
leadingIcon = {
Icon(
imageVector = Icons.Rounded.Star,
contentDescription = null,
modifier = Modifier.size(FilterChipDefaults.IconSize),
)
},
label = { Text(stringResource(R.string.favorites)) }
)
for (tag in tags) {
TagChip(
modifier = Modifier
.padding(start = 8.dp),
tag = tag,
selected = selectedTag == tag.tag,
onClick = {
if (selectedTag == tag.tag) {
onSelectTag(null)
} else {
onSelectTag(tag.tag)
}
},
onLongClick = {
sheetManager.showEditTagSheet(tag.tag)
}
)
}
if (canScroll) {
val rot by transition.animateFloat {
if (it == EnterExitState.Visible) 0f else 180f
}
IconButton(
modifier = Modifier
.rotate(rot),
onClick = { onExpand(true) }) {
Icon(Icons.Rounded.ExpandMore, null)
}
}
} }
Row {
if (editButton) { Row(
SmallFloatingActionButton( modifier = Modifier
elevation = FloatingActionButtonDefaults.bottomAppBarFabElevation(), .weight(1f)
onClick = { sheetManager.showEditFavoritesSheet() } .consumeAllScrolling()
.horizontalScroll(scrollState)
.padding(end = 12.dp),
) { ) {
Icon( FilterChip(
imageVector = Icons.Rounded.Edit,
contentDescription = null
)
}
}
}
} else {
Row(
verticalAlignment = if (reverse) Alignment.Top else Alignment.Bottom,
) {
FlowRow(
modifier = Modifier
.weight(1f)
.padding(end = 12.dp, start = 16.dp),
) {
FilterChip(
modifier = Modifier
.padding(end = 8.dp),
selected = selectedTag == null,
onClick = { onSelectTag(null) },
leadingIcon = {
Icon(
imageVector = Icons.Rounded.Star,
contentDescription = null,
modifier = Modifier.size(FilterChipDefaults.IconSize),
)
},
label = { Text(stringResource(R.string.favorites)) }
)
for (tag in tags) {
TagChip(
modifier = Modifier modifier = Modifier
.padding(end = 8.dp), .padding(start = 16.dp)
tag = tag, .sharedBounds(
selected = selectedTag == tag.tag, rememberSharedContentState("favorites"),
onClick = { this@AnimatedContent
if (selectedTag == tag.tag) { ),
onSelectTag(null) selected = selectedTag == null,
} else { onClick = { onSelectTag(null) },
onSelectTag(tag.tag) leadingIcon = {
} Icon(
imageVector = Icons.Rounded.Star,
contentDescription = null,
modifier = Modifier.size(FilterChipDefaults.IconSize),
)
}, },
onLongClick = { label = { Text(stringResource(R.string.favorites)) }
sheetManager.showEditTagSheet(tag.tag)
}
) )
} for (tag in tags) {
} TagChip(
modifier = Modifier
.padding(start = 8.dp)
.sharedBounds(
rememberSharedContentState("tag-${tag.tag}"),
this@AnimatedContent
),
tag = tag,
selected = selectedTag == tag.tag,
onClick = {
if (selectedTag == tag.tag) {
onSelectTag(null)
} else {
onSelectTag(tag.tag)
}
},
onLongClick = {
sheetManager.showEditTagSheet(tag.tag)
}
)
}
if (canScroll) {
val rot by transition.animateFloat {
if (it == EnterExitState.Visible) 0f else 180f
}
IconButton(
modifier = Modifier
.rotate(rot)
.sharedBounds(
rememberSharedContentState("expand"),
this@AnimatedContent
),
onClick = { onExpand(true) }) {
Icon(Icons.Rounded.ExpandMore, null)
}
}
Column(
modifier = Modifier.fillMaxHeight(),
verticalArrangement = if (reverse) Arrangement.TopReversed else Arrangement.Bottom,
) {
val rot by transition.animateFloat {
if (it == EnterExitState.Visible) 0f else 180f
}
IconButton(
modifier = Modifier
.rotate(rot),
onClick = { onExpand(false) }
) {
Icon(Icons.Rounded.ExpandLess, null)
} }
if (editButton) { if (editButton) {
SmallFloatingActionButton( SmallFloatingActionButton(
modifier = Modifier
.sharedBounds(
rememberSharedContentState("edit"),
this@AnimatedContent
),
elevation = FloatingActionButtonDefaults.bottomAppBarFabElevation(), elevation = FloatingActionButtonDefaults.bottomAppBarFabElevation(),
onClick = { sheetManager.showEditFavoritesSheet() } onClick = { sheetManager.showEditFavoritesSheet() }
) { ) {
@ -203,6 +152,82 @@ fun FavoritesTagSelector(
} }
} }
} }
} else {
Row(
verticalAlignment = if (reverse) Alignment.Top else Alignment.Bottom,
) {
FlowRow(
modifier = Modifier
.weight(1f)
.padding(end = 12.dp, start = 16.dp),
) {
FilterChip(
modifier = Modifier
.padding(end = 8.dp)
.sharedBounds(rememberSharedContentState("favorites"), this@AnimatedContent),
selected = selectedTag == null,
onClick = { onSelectTag(null) },
leadingIcon = {
Icon(
imageVector = Icons.Rounded.Star,
contentDescription = null,
modifier = Modifier.size(FilterChipDefaults.IconSize),
)
},
label = { Text(stringResource(R.string.favorites)) }
)
for (tag in tags) {
TagChip(
modifier = Modifier
.padding(end = 8.dp)
.sharedBounds(rememberSharedContentState("tag-${tag.tag}"), this@AnimatedContent),
tag = tag,
selected = selectedTag == tag.tag,
onClick = {
if (selectedTag == tag.tag) {
onSelectTag(null)
} else {
onSelectTag(tag.tag)
}
},
onLongClick = {
sheetManager.showEditTagSheet(tag.tag)
}
)
}
}
Column(
modifier = Modifier.fillMaxHeight(),
verticalArrangement = if (reverse) Arrangement.TopReversed else Arrangement.Bottom,
) {
val rot by transition.animateFloat {
if (it == EnterExitState.Visible) 0f else 180f
}
IconButton(
modifier = Modifier
.rotate(rot)
.sharedBounds(rememberSharedContentState("expand"), this@AnimatedContent),
onClick = { onExpand(false) }
) {
Icon(Icons.Rounded.ExpandLess, null)
}
if (editButton) {
SmallFloatingActionButton(
modifier = Modifier
.sharedBounds(rememberSharedContentState("edit"), this@AnimatedContent),
elevation = FloatingActionButtonDefaults.bottomAppBarFabElevation(),
onClick = { sheetManager.showEditFavoritesSheet() }
) {
Icon(
imageVector = Icons.Rounded.Edit,
contentDescription = null
)
}
}
}
}
} }
} }
} }