Skip to content

Commit f05e9ee

Browse files
committed
library: improve SuperDialog&SuperBottomSheet
1 parent 7df9a03 commit f05e9ee

File tree

4 files changed

+75
-7
lines changed

4 files changed

+75
-7
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>597</string>
20+
<string>598</string>
2121
<key>LSRequiresIPhoneOS</key>
2222
<true/>
2323
<key>CADisableMinimumFrameDurationOnPhone</key>

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/extra/SuperBottomSheet.kt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33

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

6+
import androidx.compose.animation.EnterTransition
7+
import androidx.compose.animation.ExitTransition
68
import androidx.compose.animation.core.Animatable
79
import androidx.compose.animation.core.tween
10+
import androidx.compose.animation.slideInVertically
11+
import androidx.compose.animation.slideOutVertically
812
import androidx.compose.foundation.background
913
import androidx.compose.foundation.gestures.detectTapGestures
1014
import androidx.compose.foundation.gestures.detectVerticalDragGestures
@@ -56,6 +60,7 @@ import com.mocharealm.gaze.capsule.ContinuousRoundedRectangle
5660
import kotlinx.coroutines.CoroutineScope
5761
import kotlinx.coroutines.channels.Channel
5862
import kotlinx.coroutines.launch
63+
import top.yukonga.miuix.kmp.anim.DecelerateEasing
5964
import top.yukonga.miuix.kmp.basic.Text
6065
import top.yukonga.miuix.kmp.theme.MiuixTheme
6166
import top.yukonga.miuix.kmp.utils.MiuixPopupUtils.Companion.DialogLayout
@@ -117,8 +122,30 @@ fun SuperBottomSheet(
117122
}
118123
}
119124

125+
@Composable
126+
fun rememberDefaultSheetEnterTransition(): EnterTransition {
127+
return remember {
128+
slideInVertically(
129+
initialOffsetY = { fullHeight -> fullHeight },
130+
animationSpec = tween(450, easing = DecelerateEasing(1.5f))
131+
)
132+
}
133+
}
134+
135+
@Composable
136+
fun rememberDefaultSheetExitTransition(): ExitTransition {
137+
return remember {
138+
slideOutVertically(
139+
targetOffsetY = { fullHeight -> fullHeight },
140+
animationSpec = tween(450, easing = DecelerateEasing(0.8f))
141+
)
142+
}
143+
}
144+
120145
DialogLayout(
121146
visible = show,
147+
enterTransition = rememberDefaultSheetEnterTransition(),
148+
exitTransition = rememberDefaultSheetExitTransition(),
122149
enableWindowDim = enableWindowDim,
123150
enableAutoLargeScreen = false,
124151
dimAlpha = dimAlpha
@@ -389,6 +416,44 @@ private fun DragHandleArea(
389416
modifier = Modifier
390417
.fillMaxWidth()
391418
.height(24.dp)
419+
.pointerInput(Unit) {
420+
detectTapGestures(
421+
onPress = {
422+
// Provide immediate press feedback even before dragging
423+
isPressing.floatValue = 1f
424+
coroutineScope.launch {
425+
pressScale.animateTo(
426+
targetValue = 1.15f,
427+
animationSpec = tween(durationMillis = 100)
428+
)
429+
}
430+
coroutineScope.launch {
431+
pressWidth.animateTo(
432+
targetValue = 55f,
433+
animationSpec = tween(durationMillis = 100)
434+
)
435+
}
436+
437+
// Wait for release; if released without drag, reset here.
438+
val released = tryAwaitRelease()
439+
if (released) {
440+
isPressing.floatValue = 0f
441+
coroutineScope.launch {
442+
pressScale.animateTo(
443+
targetValue = 1f,
444+
animationSpec = tween(durationMillis = 150)
445+
)
446+
}
447+
coroutineScope.launch {
448+
pressWidth.animateTo(
449+
targetValue = 45f,
450+
animationSpec = tween(durationMillis = 150)
451+
)
452+
}
453+
}
454+
}
455+
)
456+
}
392457
.pointerInput(allowDismiss) {
393458
detectVerticalDragGestures(
394459
onDragStart = {

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/extra/SuperDialog.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.Column
1010
import androidx.compose.foundation.layout.captionBarPadding
1111
import androidx.compose.foundation.layout.fillMaxSize
1212
import androidx.compose.foundation.layout.fillMaxWidth
13+
import androidx.compose.foundation.layout.heightIn
1314
import androidx.compose.foundation.layout.imePadding
1415
import androidx.compose.foundation.layout.navigationBarsPadding
1516
import androidx.compose.foundation.layout.padding
@@ -34,6 +35,7 @@ import androidx.compose.ui.layout.onGloballyPositioned
3435
import androidx.compose.ui.platform.LocalDensity
3536
import androidx.compose.ui.text.font.FontWeight
3637
import androidx.compose.ui.text.style.TextAlign
38+
import androidx.compose.ui.unit.Dp
3739
import androidx.compose.ui.unit.DpSize
3840
import androidx.compose.ui.unit.dp
3941
import com.mocharealm.gaze.capsule.ContinuousRoundedRectangle
@@ -193,6 +195,7 @@ private fun SuperDialogContent(
193195

194196
val columnModifier = modifier
195197
.widthIn(max = 420.dp)
198+
.heightIn(max = if (isLargeScreen) windowHeight * (2f / 3f) else Dp.Unspecified)
196199
.onGloballyPositioned { coordinates ->
197200
dialogHeightPx.value = coordinates.size.height
198201
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ class MiuixPopupUtils {
9595
return remember(largeScreen) {
9696
if (largeScreen) {
9797
fadeIn(
98-
animationSpec = spring(dampingRatio = 0.9f, stiffness = 900f)
98+
animationSpec = spring(dampingRatio = 0.82f, stiffness = 800f)
9999
) + scaleIn(
100100
initialScale = 0.8f,
101-
animationSpec = spring(0.73f, 900f)
101+
animationSpec = spring(dampingRatio = 0.73f, stiffness = 800f)
102102
)
103103
} else {
104104
slideInVertically(
105105
initialOffsetY = { fullHeight -> fullHeight },
106-
animationSpec = spring(dampingRatio = 0.92f, stiffness = 400f)
106+
animationSpec = spring(dampingRatio = 0.88f, stiffness = 450f)
107107
)
108108
}
109109
}
@@ -122,7 +122,7 @@ class MiuixPopupUtils {
122122
} else {
123123
slideOutVertically(
124124
targetOffsetY = { fullHeight -> fullHeight },
125-
animationSpec = tween(200, easing = DecelerateEasing(1.5f))
125+
animationSpec = tween(300, easing = DecelerateEasing(0.8f))
126126
)
127127
}
128128
}
@@ -223,7 +223,7 @@ class MiuixPopupUtils {
223223
}
224224
onDispose {
225225
if (state.showState.value) {
226-
dialogStates.removeAll { it.showState === state.showState }
226+
state.showState.value = false
227227
}
228228
}
229229
}
@@ -288,7 +288,7 @@ class MiuixPopupUtils {
288288
}
289289
onDispose {
290290
if (state.showState.value) {
291-
popupStates.removeAll { it.showState === state.showState }
291+
state.showState.value = false
292292
}
293293
}
294294
}

0 commit comments

Comments
 (0)