Use motion scheme transition spec for grid popup

This commit is contained in:
MM20 2025-06-29 19:11:45 +02:00
parent 85bfd9d79a
commit 8f4766d28a
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389

View File

@ -216,21 +216,17 @@ fun ItemPopup(origin: IntRect, searchable: Searchable, onDismissRequest: () -> U
val animationProgress = remember { val animationProgress = remember {
Animatable(0f) Animatable(0f)
} }
val animationSpec = MaterialTheme.motionScheme.defaultSpatialSpec<Float>()
LaunchedEffect(show.targetState) { LaunchedEffect(show.targetState) {
if (!show.targetState) { if (!show.targetState) {
animationProgress.animateTo( animationProgress.animateTo(
0f, spring( 0f, animationSpec
Spring.DampingRatioNoBouncy,
Spring.StiffnessMediumLow,
)
) )
onDismissRequest() onDismissRequest()
} else { } else {
animationProgress.animateTo( animationProgress.animateTo(
1f, spring( 100f, animationSpec
Spring.DampingRatioLowBouncy,
Spring.StiffnessMediumLow,
)
) )
} }
} }
@ -239,11 +235,12 @@ fun ItemPopup(origin: IntRect, searchable: Searchable, onDismissRequest: () -> U
} }
Overlay { Overlay {
val p = animationProgress.value * 0.01f
Box( Box(
modifier = Modifier modifier = Modifier
.background( .background(
MaterialTheme.colorScheme.scrim.copy( MaterialTheme.colorScheme.scrim.copy(
alpha = 0.32f * animationProgress.value.coerceIn( alpha = 0.32f * p.coerceIn(
0f, 0f,
1f 1f
) )
@ -266,7 +263,7 @@ fun ItemPopup(origin: IntRect, searchable: Searchable, onDismissRequest: () -> U
) )
) { ) {
LauncherCard( LauncherCard(
elevation = 8.dp * animationProgress.value, elevation = 8.dp * p,
backgroundOpacity = MaterialTheme.transparency.elevatedSurface, backgroundOpacity = MaterialTheme.transparency.elevatedSurface,
modifier = Modifier modifier = Modifier
.placeOverlay( .placeOverlay(
@ -275,7 +272,7 @@ fun ItemPopup(origin: IntRect, searchable: Searchable, onDismissRequest: () -> U
-WindowInsets.systemBars.union(WindowInsets.ime) -WindowInsets.systemBars.union(WindowInsets.ime)
.getTop(LocalDensity.current) .getTop(LocalDensity.current)
), ),
animationProgress.value p,
) )
) { ) {
when (searchable) { when (searchable) {
@ -283,7 +280,7 @@ fun ItemPopup(origin: IntRect, searchable: Searchable, onDismissRequest: () -> U
AppItemGridPopup( AppItemGridPopup(
app = searchable, app = searchable,
show = show, show = show,
animationProgress = animationProgress.value, animationProgress = p,
origin = origin, origin = origin,
onDismiss = { onDismiss = {
show.targetState = false show.targetState = false
@ -295,7 +292,7 @@ fun ItemPopup(origin: IntRect, searchable: Searchable, onDismissRequest: () -> U
WebsiteItemGridPopup( WebsiteItemGridPopup(
website = searchable, website = searchable,
show = show, show = show,
animationProgress = animationProgress.value, animationProgress = p,
origin = origin, origin = origin,
onDismiss = { onDismiss = {
show.targetState = false show.targetState = false
@ -307,7 +304,7 @@ fun ItemPopup(origin: IntRect, searchable: Searchable, onDismissRequest: () -> U
ArticleItemGridPopup( ArticleItemGridPopup(
article = searchable, article = searchable,
show = show, show = show,
animationProgress = animationProgress.value, animationProgress = p,
origin = origin, origin = origin,
onDismiss = { onDismiss = {
show.targetState = false show.targetState = false
@ -319,7 +316,7 @@ fun ItemPopup(origin: IntRect, searchable: Searchable, onDismissRequest: () -> U
ContactItemGridPopup( ContactItemGridPopup(
contact = searchable, contact = searchable,
show = show, show = show,
animationProgress = animationProgress.value, animationProgress = p,
origin = origin, origin = origin,
onDismiss = { onDismiss = {
show.targetState = false show.targetState = false
@ -331,7 +328,7 @@ fun ItemPopup(origin: IntRect, searchable: Searchable, onDismissRequest: () -> U
FileItemGridPopup( FileItemGridPopup(
file = searchable, file = searchable,
show = show, show = show,
animationProgress = animationProgress.value, animationProgress = p,
origin = origin, origin = origin,
onDismiss = { onDismiss = {
show.targetState = false show.targetState = false
@ -343,7 +340,7 @@ fun ItemPopup(origin: IntRect, searchable: Searchable, onDismissRequest: () -> U
CalendarItemGridPopup( CalendarItemGridPopup(
calendar = searchable, calendar = searchable,
show = show, show = show,
animationProgress = animationProgress.value, animationProgress = p,
origin = origin, origin = origin,
onDismiss = { onDismiss = {
show.targetState = false show.targetState = false
@ -355,7 +352,7 @@ fun ItemPopup(origin: IntRect, searchable: Searchable, onDismissRequest: () -> U
ShortcutItemGridPopup( ShortcutItemGridPopup(
shortcut = searchable, shortcut = searchable,
show = show, show = show,
animationProgress = animationProgress.value, animationProgress = p,
origin = origin, origin = origin,
onDismiss = { onDismiss = {
show.targetState = false show.targetState = false
@ -367,7 +364,7 @@ fun ItemPopup(origin: IntRect, searchable: Searchable, onDismissRequest: () -> U
LocationItemGridPopup( LocationItemGridPopup(
location = searchable, location = searchable,
show = show, show = show,
animationProgress = animationProgress.value, animationProgress = p,
origin = origin, origin = origin,
onDismiss = { onDismiss = {
show.targetState = false show.targetState = false