Skip to content

Commit e3d6569

Browse files
committed
library: improve ListPopup anim again
1 parent f4d36b6 commit e3d6569

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

iosApp/iosApp/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundleShortVersionString</key>
1818
<string>1.0.5</string>
1919
<key>CFBundleVersion</key>
20-
<string>599</string>
20+
<string>600</string>
2121
<key>LSRequiresIPhoneOS</key>
2222
<true/>
2323
<key>CADisableMinimumFrameDurationOnPhone</key>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2025, compose-miuix-ui contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package top.yukonga.miuix.kmp.anim
5+
6+
import androidx.compose.animation.core.Easing
7+
import kotlin.math.PI
8+
import kotlin.math.sin
9+
10+
val SinOutEasing: Easing = Easing { fraction ->
11+
sin((fraction * PI / 2).toFloat())
12+
}

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/ListPopup.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
package top.yukonga.miuix.kmp.basic
55

6+
import androidx.compose.animation.core.animateFloat
7+
import androidx.compose.animation.core.spring
8+
import androidx.compose.animation.core.updateTransition
69
import androidx.compose.foundation.background
710
import androidx.compose.foundation.gestures.detectTapGestures
811
import androidx.compose.foundation.layout.Box
@@ -213,7 +216,20 @@ fun ListPopup(
213216
enableWindowDim = enableWindowDim,
214217
transformOrigin = { effectiveTransformOrigin },
215218
) {
216-
val shape = remember { ContinuousRoundedRectangle(16.dp) }
219+
val transition = updateTransition(targetState = show.value)
220+
val scale by transition.animateFloat(
221+
transitionSpec = {
222+
spring(dampingRatio = 0.82f, stiffness = 800f, visibilityThreshold = 0.001f)
223+
}
224+
) { isShown ->
225+
if (isShown) 1f else 0.15f
226+
}
227+
228+
val baseCornerRadiusPx = with(density) { 16.dp.toPx() }
229+
val appliedCornerDp = with(density) {
230+
(baseCornerRadiusPx / scale.coerceAtLeast(0.001f)).toDp()
231+
}
232+
val shape = ContinuousRoundedRectangle(appliedCornerDp)
217233
val elevationPx by remember(shadowElevation, density) {
218234
derivedStateOf { with(density) { shadowElevation.toPx() } }
219235
}

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/utils/MiuixPopupUtils.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import androidx.compose.ui.platform.LocalDensity
3939
import androidx.compose.ui.unit.dp
4040
import androidx.compose.ui.zIndex
4141
import top.yukonga.miuix.kmp.anim.DecelerateEasing
42+
import top.yukonga.miuix.kmp.anim.SinOutEasing
4243
import top.yukonga.miuix.kmp.basic.Scaffold
4344
import top.yukonga.miuix.kmp.theme.MiuixTheme
4445

@@ -80,14 +81,14 @@ class MiuixPopupUtils {
8081
private var nextZIndex = 1f
8182

8283
private val DialogDimEnter: EnterTransition =
83-
fadeIn(animationSpec = tween(300, easing = DecelerateEasing(1.5f)))
84+
fadeIn(animationSpec = tween(300, easing = SinOutEasing))
8485
private val DialogDimExit: ExitTransition =
85-
fadeOut(animationSpec = tween(250, easing = DecelerateEasing(1.5f)))
86+
fadeOut(animationSpec = tween(250, easing = SinOutEasing))
8687

8788
private val PopupDimEnter: EnterTransition =
88-
fadeIn(animationSpec = tween(150, easing = DecelerateEasing(1.5f)))
89+
fadeIn(animationSpec = tween(300, easing = SinOutEasing))
8990
private val PopupDimExit: ExitTransition =
90-
fadeOut(animationSpec = tween(150, easing = DecelerateEasing(1.5f)))
91+
fadeOut(animationSpec = tween(150, easing = SinOutEasing))
9192

9293
@Composable
9394
private fun rememberDefaultDialogEnterTransition(largeScreen: Boolean): EnterTransition {
@@ -131,9 +132,10 @@ class MiuixPopupUtils {
131132
private fun rememberDefaultPopupEnterTransition(transformOrigin: () -> TransformOrigin): EnterTransition {
132133
return remember(transformOrigin()) {
133134
fadeIn(
134-
animationSpec = tween(durationMillis = 150, easing = DecelerateEasing(2f))
135+
animationSpec = tween(durationMillis = 200, easing = DecelerateEasing(1.5f))
135136
) + scaleIn(
136-
animationSpec = spring(dampingRatio = 0.88f, stiffness = 300f, visibilityThreshold = 0.001f),
137+
initialScale = 0.15f,
138+
animationSpec = spring(dampingRatio = 0.82f, stiffness = 800f, visibilityThreshold = 0.001f),
137139
transformOrigin = transformOrigin()
138140
)
139141
}
@@ -143,9 +145,9 @@ class MiuixPopupUtils {
143145
private fun rememberDefaultPopupExitTransition(transformOrigin: () -> TransformOrigin): ExitTransition {
144146
return remember(transformOrigin()) {
145147
fadeOut(
146-
animationSpec = tween(durationMillis = 150, easing = DecelerateEasing(0.8f))
148+
animationSpec = tween(durationMillis = 150, easing = DecelerateEasing(1.5f))
147149
) + scaleOut(
148-
animationSpec = tween(durationMillis = 150, easing = DecelerateEasing(0.8f)),
150+
animationSpec = spring(dampingRatio = 0.82f, stiffness = 800f, visibilityThreshold = 0.001f),
149151
transformOrigin = transformOrigin()
150152
)
151153
}

0 commit comments

Comments
 (0)