Skip to content

Commit

Permalink
library: Add windowDimming param to PopupUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
YuKongA committed Jan 11, 2025
1 parent b665cfd commit c1ee628
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion composeApp/src/commonMain/kotlin/UITest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ fun UITest(
alignment = PopupPositionProvider.Align.BottomRight,
onDismissRequest = {
isBottomPopupExpanded.value = false
}
},
windowDimming = false
) {
ListPopupColumn {
items.take(3).forEachIndexed { index, navigationItem ->
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ android-minSdk = "26"
android-compileSdk = "35"
android-targetSdk = "35"

androidGradlePlugin = "8.7.3"
androidGradlePlugin = "8.8.0"
androidx-activity-compose = "1.9.3"
androidx-window = "1.3.0"
compose-plugin = "1.7.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import kotlin.math.min
* @param popupModifier The modifier to be applied to the [ListPopup].
* @param popupPositionProvider The [PopupPositionProvider] of the [ListPopup].
* @param alignment The alignment of the [ListPopup].
* @param windowDimming Whether to dim the window when the [ListPopup] is shown.
* @param onDismissRequest The callback when the [ListPopup] is dismissed.
* @param maxHeight The maximum height of the [ListPopup]. If null, the height will be calculated automatically.
* @param content The [Composable] content of the [ListPopup]. You should use the [ListPopupColumn] in general.
Expand All @@ -66,6 +67,7 @@ fun ListPopup(
popupModifier: Modifier = Modifier,
popupPositionProvider: PopupPositionProvider = ListPopupDefaults.DropdownPositionProvider,
alignment: PopupPositionProvider.Align = PopupPositionProvider.Align.Right,
windowDimming: Boolean = true,
onDismissRequest: (() -> Unit)? = null,
maxHeight: Dp? = null,
content: @Composable () -> Unit
Expand Down Expand Up @@ -143,7 +145,8 @@ fun ListPopup(
11.dp.toPx()
})
showPopup(
transformOrigin = { transformOrigin }
transformOrigin = { transformOrigin },
windowDimming = windowDimming,
) {
Box(
modifier = popupModifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class MiuixPopupUtil {
companion object {
private var isPopupShowing = mutableStateOf(false)
private var isDialogShowing = mutableStateOf(false)
private var isWindowDimming = mutableStateOf(false)
private var popupContext = mutableStateOf<(@Composable () -> Unit)?>(null)
private var dialogContext = mutableStateOf<(@Composable () -> Unit)?>(null)
private var popupTransformOrigin = mutableStateOf({ TransformOrigin.Center })
Expand Down Expand Up @@ -73,16 +74,19 @@ class MiuixPopupUtil {
*
* @param transformOrigin The pivot point in terms of fraction of the overall size,
* used for scale transformations. By default it's [TransformOrigin.Center].
* @param windowDimming Whether to dim the window when the popup is showing.
* @param content The [Composable] content of the popup.
*/
@Composable
fun showPopup(
transformOrigin: (() -> TransformOrigin) = { TransformOrigin.Center },
windowDimming: Boolean = true,
content: (@Composable () -> Unit)? = null,
) {
if (isPopupShowing.value) return
popupTransformOrigin.value = transformOrigin
isPopupShowing.value = true
isWindowDimming.value = windowDimming
popupContext.value = content
}

Expand Down Expand Up @@ -118,7 +122,7 @@ class MiuixPopupUtil {
dimExitDuration = 150
}
AnimatedVisibility(
visible = isDialogShowing.value || isPopupShowing.value,
visible = (isDialogShowing.value || isPopupShowing.value) && isWindowDimming.value,
modifier = Modifier.zIndex(1f).fillMaxSize(),
enter = fadeIn(animationSpec = tween(dimEnterDuration, easing = DecelerateEasing(1.5f))),
exit = fadeOut(animationSpec = tween(dimExitDuration, easing = DecelerateEasing(1.5f)))
Expand Down Expand Up @@ -165,7 +169,7 @@ class MiuixPopupUtil {
dialogContext.value?.invoke()
}
AnimatedVisibility(
visible = isPopupShowing.value && isDialogShowing.value,
visible = isPopupShowing.value && isDialogShowing.value && isWindowDimming.value,
modifier = Modifier.zIndex(1f).fillMaxSize(),
) {
Box(
Expand Down

0 comments on commit c1ee628

Please sign in to comment.