Make home transition more bouncy

This commit is contained in:
MM20 2025-06-29 16:48:22 +02:00
parent 1852c3e3d6
commit e179ef9a31
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
2 changed files with 22 additions and 12 deletions

View File

@ -1,7 +1,9 @@
package de.mm20.launcher2.ui.ktx
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.AnimationSpec
import androidx.compose.animation.core.AnimationVector
import androidx.compose.animation.core.SpringSpec
import androidx.compose.animation.core.TwoWayConverter
import androidx.compose.animation.core.VectorConverter
import androidx.compose.runtime.MutableState
@ -11,13 +13,20 @@ suspend fun MutableState<Dp>.animateTo(targetValue: Dp) {
animateTo(targetValue, Dp.VectorConverter)
}
suspend fun MutableState<Float>.animateTo(targetValue: Float) {
animateTo(targetValue, Float.VectorConverter)
suspend fun MutableState<Float>.animateTo(
targetValue: Float,
animationSpec: AnimationSpec<Float> = SpringSpec(),
) {
animateTo(targetValue, Float.VectorConverter, animationSpec)
}
suspend inline fun <T, V: AnimationVector> MutableState<T>.animateTo(targetValue: T, converter: TwoWayConverter<T, V>) {
suspend inline fun <T, V: AnimationVector> MutableState<T>.animateTo(
targetValue: T,
converter: TwoWayConverter<T, V>,
animationSpec: AnimationSpec<T> = SpringSpec(),
) {
val animatable = Animatable(this.value, converter)
animatable.animateTo(targetValue) animatable@ {
animatable.animateTo(targetValue, animationSpec = animationSpec) animatable@ {
this@animateTo.value = this.value
}
}

View File

@ -176,13 +176,14 @@ abstract class SharedLauncherActivity(
}
}
val enterTransitionProgress = remember { mutableStateOf(1f) }
val enterTransitionProgress = remember { mutableStateOf(100f) }
var enterTransition by remember {
mutableStateOf<EnterHomeTransition?>(
null
)
}
val animMotionSpec = MaterialTheme.motionScheme.defaultSpatialSpec<Float>()
LaunchedEffect(null) {
enterHomeTransitionManager
.currentTransition
@ -191,7 +192,7 @@ abstract class SharedLauncherActivity(
if (it != null) {
enterTransitionProgress.value = 0f
enterTransition = it
enterTransitionProgress.animateTo(1f)
enterTransitionProgress.animateTo(100f, animationSpec = animMotionSpec)
enterTransition = null
}
}
@ -378,10 +379,10 @@ abstract class SharedLauncherActivity(
.fillMaxSize()
.graphicsLayer {
scaleX =
0.5f + enterTransitionProgress.value * 0.5f
0.5f + enterTransitionProgress.value * 0.005f
scaleY =
0.5f + enterTransitionProgress.value * 0.5f
alpha = enterTransitionProgress.value
0.5f + enterTransitionProgress.value * 0.005f
alpha = enterTransitionProgress.value * 0.01f
}
)
@ -401,11 +402,11 @@ abstract class SharedLauncherActivity(
modifier = Modifier
.align(Alignment.TopStart)
.graphicsLayer {
val p = (enterTransitionProgress.value).pow(2f)
val p = (enterTransitionProgress.value * 0.01f)
transformOrigin = TransformOrigin.Center
translationX = it.targetBounds.left + dX * (1 - p)
translationY = it.targetBounds.top + dY * (1 - p)
alpha = enterTransitionProgress.value
alpha = p
scaleX = 1f + s * (1 - p)
scaleY = 1f + s * (1 - p)
}) {
@ -414,7 +415,7 @@ abstract class SharedLauncherActivity(
dX,
dY
)
) { enterTransitionProgress.value }
) { enterTransitionProgress.value * 0.01f }
}
}
LauncherBottomSheets()