From e179ef9a3149256cd00acce4c6582d50338ec373 Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Sun, 29 Jun 2025 16:48:22 +0200 Subject: [PATCH] Make home transition more bouncy --- .../de/mm20/launcher2/ui/ktx/MutableState.kt | 17 +++++++++++++---- .../ui/launcher/SharedLauncherActivity.kt | 17 +++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/ktx/MutableState.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/ktx/MutableState.kt index 851bbd43..1c52061c 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/ktx/MutableState.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/ktx/MutableState.kt @@ -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.animateTo(targetValue: Dp) { animateTo(targetValue, Dp.VectorConverter) } -suspend fun MutableState.animateTo(targetValue: Float) { - animateTo(targetValue, Float.VectorConverter) +suspend fun MutableState.animateTo( + targetValue: Float, + animationSpec: AnimationSpec = SpringSpec(), +) { + animateTo(targetValue, Float.VectorConverter, animationSpec) } -suspend inline fun MutableState.animateTo(targetValue: T, converter: TwoWayConverter) { +suspend inline fun MutableState.animateTo( + targetValue: T, + converter: TwoWayConverter, + animationSpec: AnimationSpec = SpringSpec(), +) { val animatable = Animatable(this.value, converter) - animatable.animateTo(targetValue) animatable@ { + animatable.animateTo(targetValue, animationSpec = animationSpec) animatable@ { this@animateTo.value = this.value } } \ No newline at end of file diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/SharedLauncherActivity.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/SharedLauncherActivity.kt index f41cd40a..3156a8b6 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/SharedLauncherActivity.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/launcher/SharedLauncherActivity.kt @@ -176,13 +176,14 @@ abstract class SharedLauncherActivity( } } - val enterTransitionProgress = remember { mutableStateOf(1f) } + val enterTransitionProgress = remember { mutableStateOf(100f) } var enterTransition by remember { mutableStateOf( null ) } + val animMotionSpec = MaterialTheme.motionScheme.defaultSpatialSpec() 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()