Skip to content

Commit c1ee628

Browse files
committed
library: Add windowDimming param to PopupUtil
1 parent b665cfd commit c1ee628

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

composeApp/src/commonMain/kotlin/UITest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ fun UITest(
230230
alignment = PopupPositionProvider.Align.BottomRight,
231231
onDismissRequest = {
232232
isBottomPopupExpanded.value = false
233-
}
233+
},
234+
windowDimming = false
234235
) {
235236
ListPopupColumn {
236237
items.take(3).forEachIndexed { index, navigationItem ->

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ android-minSdk = "26"
33
android-compileSdk = "35"
44
android-targetSdk = "35"
55

6-
androidGradlePlugin = "8.7.3"
6+
androidGradlePlugin = "8.8.0"
77
androidx-activity-compose = "1.9.3"
88
androidx-window = "1.3.0"
99
compose-plugin = "1.7.3"

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import kotlin.math.min
5656
* @param popupModifier The modifier to be applied to the [ListPopup].
5757
* @param popupPositionProvider The [PopupPositionProvider] of the [ListPopup].
5858
* @param alignment The alignment of the [ListPopup].
59+
* @param windowDimming Whether to dim the window when the [ListPopup] is shown.
5960
* @param onDismissRequest The callback when the [ListPopup] is dismissed.
6061
* @param maxHeight The maximum height of the [ListPopup]. If null, the height will be calculated automatically.
6162
* @param content The [Composable] content of the [ListPopup]. You should use the [ListPopupColumn] in general.
@@ -66,6 +67,7 @@ fun ListPopup(
6667
popupModifier: Modifier = Modifier,
6768
popupPositionProvider: PopupPositionProvider = ListPopupDefaults.DropdownPositionProvider,
6869
alignment: PopupPositionProvider.Align = PopupPositionProvider.Align.Right,
70+
windowDimming: Boolean = true,
6971
onDismissRequest: (() -> Unit)? = null,
7072
maxHeight: Dp? = null,
7173
content: @Composable () -> Unit
@@ -143,7 +145,8 @@ fun ListPopup(
143145
11.dp.toPx()
144146
})
145147
showPopup(
146-
transformOrigin = { transformOrigin }
148+
transformOrigin = { transformOrigin },
149+
windowDimming = windowDimming,
147150
) {
148151
Box(
149152
modifier = popupModifier

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class MiuixPopupUtil {
3838
companion object {
3939
private var isPopupShowing = mutableStateOf(false)
4040
private var isDialogShowing = mutableStateOf(false)
41+
private var isWindowDimming = mutableStateOf(false)
4142
private var popupContext = mutableStateOf<(@Composable () -> Unit)?>(null)
4243
private var dialogContext = mutableStateOf<(@Composable () -> Unit)?>(null)
4344
private var popupTransformOrigin = mutableStateOf({ TransformOrigin.Center })
@@ -73,16 +74,19 @@ class MiuixPopupUtil {
7374
*
7475
* @param transformOrigin The pivot point in terms of fraction of the overall size,
7576
* used for scale transformations. By default it's [TransformOrigin.Center].
77+
* @param windowDimming Whether to dim the window when the popup is showing.
7678
* @param content The [Composable] content of the popup.
7779
*/
7880
@Composable
7981
fun showPopup(
8082
transformOrigin: (() -> TransformOrigin) = { TransformOrigin.Center },
83+
windowDimming: Boolean = true,
8184
content: (@Composable () -> Unit)? = null,
8285
) {
8386
if (isPopupShowing.value) return
8487
popupTransformOrigin.value = transformOrigin
8588
isPopupShowing.value = true
89+
isWindowDimming.value = windowDimming
8690
popupContext.value = content
8791
}
8892

@@ -118,7 +122,7 @@ class MiuixPopupUtil {
118122
dimExitDuration = 150
119123
}
120124
AnimatedVisibility(
121-
visible = isDialogShowing.value || isPopupShowing.value,
125+
visible = (isDialogShowing.value || isPopupShowing.value) && isWindowDimming.value,
122126
modifier = Modifier.zIndex(1f).fillMaxSize(),
123127
enter = fadeIn(animationSpec = tween(dimEnterDuration, easing = DecelerateEasing(1.5f))),
124128
exit = fadeOut(animationSpec = tween(dimExitDuration, easing = DecelerateEasing(1.5f)))
@@ -165,7 +169,7 @@ class MiuixPopupUtil {
165169
dialogContext.value?.invoke()
166170
}
167171
AnimatedVisibility(
168-
visible = isPopupShowing.value && isDialogShowing.value,
172+
visible = isPopupShowing.value && isDialogShowing.value && isWindowDimming.value,
169173
modifier = Modifier.zIndex(1f).fillMaxSize(),
170174
) {
171175
Box(

0 commit comments

Comments
 (0)