Make popups more bouncy

This commit is contained in:
MM20 2024-06-30 13:11:57 +02:00
parent c2af63a828
commit 429025e5ac
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389

View File

@ -3,6 +3,9 @@ package de.mm20.launcher2.ui.launcher.search.common.grid
import androidx.activity.compose.BackHandler import androidx.activity.compose.BackHandler
import androidx.compose.animation.core.Animatable import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.MutableTransitionState import androidx.compose.animation.core.MutableTransitionState
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.SpringSpec
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween import androidx.compose.animation.core.tween
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.combinedClickable
@ -202,16 +205,20 @@ fun ItemPopup(origin: Rect, searchable: Searchable, onDismissRequest: () -> Unit
} }
} }
val animationProgress = remember { val animationProgress = remember {
Animatable(0f).apply { Animatable(0f)
updateBounds(0f, 1f)
}
} }
LaunchedEffect(show.targetState) { LaunchedEffect(show.targetState) {
if (!show.targetState) { if (!show.targetState) {
animationProgress.animateTo(0f, tween(300)) animationProgress.animateTo(0f, spring(
Spring.DampingRatioNoBouncy,
Spring.StiffnessMediumLow,
))
onDismissRequest() onDismissRequest()
} else { } else {
animationProgress.animateTo(1f, tween(300)) animationProgress.animateTo(1f, spring(
Spring.DampingRatioLowBouncy,
Spring.StiffnessMediumLow,
))
} }
} }
BackHandler { BackHandler {
@ -221,7 +228,7 @@ fun ItemPopup(origin: Rect, searchable: Searchable, onDismissRequest: () -> Unit
Overlay { Overlay {
Box( Box(
modifier = Modifier modifier = Modifier
.background(MaterialTheme.colorScheme.scrim.copy(alpha = 0.32f * animationProgress.value)) .background(MaterialTheme.colorScheme.scrim.copy(alpha = 0.32f * animationProgress.value.coerceIn(0f, 1f)))
.fillMaxSize() .fillMaxSize()
.systemBarsPadding() .systemBarsPadding()
.imePadding() .imePadding()