@@ -52,7 +52,7 @@ import kotlin.math.min
5252 * @param popupModifier The modifier to be applied to the [ListPopup].
5353 * @param popupPositionProvider The [PopupPositionProvider] of the [ListPopup].
5454 * @param alignment The alignment of the [ListPopup].
55- * @param windowDimming Whether to dim the window when the [ListPopup] is shown.
55+ * @param enableWindowDim Whether to enable window dimming when the [ListPopup] is shown.
5656 * @param shadowElevation The elevation of the shadow of the [ListPopup].
5757 * @param onDismissRequest The callback when the [ListPopup] is dismissed.
5858 * @param maxHeight The maximum height of the [ListPopup]. If null, the height will be calculated automatically.
@@ -65,7 +65,7 @@ fun ListPopup(
6565 popupModifier : Modifier = Modifier ,
6666 popupPositionProvider : PopupPositionProvider = ListPopupDefaults .DropdownPositionProvider ,
6767 alignment : PopupPositionProvider .Align = PopupPositionProvider .Align .Right ,
68- windowDimming : Boolean = true,
68+ enableWindowDim : Boolean = true,
6969 shadowElevation : Dp = 11.dp,
7070 onDismissRequest : (() -> Unit )? = null,
7171 maxHeight : Dp ? = null,
@@ -93,10 +93,6 @@ fun ListPopup(
9393 var popupMargin by remember { mutableStateOf(IntRect .Zero ) }
9494 var transformOrigin by remember { mutableStateOf(TransformOrigin .Center ) }
9595
96- BackHandler (enabled = show.value) {
97- onDismissRequest?.invoke()
98- }
99-
10096 DisposableEffect (popupPositionProvider, alignment) {
10197 val popupMargins = popupPositionProvider.getMargins()
10298 popupMargin = with (density) {
@@ -120,66 +116,7 @@ fun ListPopup(
120116 onDispose {}
121117 }
122118
123- if (show.value) {
124- PopupLayout (
125- visible = show,
126- transformOrigin = { transformOrigin },
127- windowDimming = windowDimming
128- ) {
129- val currentContent by rememberUpdatedState(content)
130- val currentOffset by rememberUpdatedState(offset)
131- val shape = remember { derivedStateOf { SmoothRoundedCornerShape (16 .dp) } }
132- val elevationPx = with (density) { shadowElevation.toPx() }
133- Box (
134- modifier = popupModifier
135- .pointerInput(Unit ) {
136- detectTapGestures {
137- onDismissRequest?.invoke()
138- }
139- }
140- .layout { measurable, constraints ->
141- val placeable = measurable.measure(
142- constraints.copy(
143- minWidth = if (minWidth.roundToPx() <= windowSize.width) minWidth.roundToPx() else windowSize.width,
144- minHeight = if (50 .dp.roundToPx() <= windowSize.height) 50 .dp.roundToPx() else windowSize.height,
145- maxHeight = maxHeight?.roundToPx()?.coerceAtLeast(50 .dp.roundToPx())
146- ? : (windowBounds.height - popupMargin.top - popupMargin.bottom).coerceAtLeast(50 .dp.roundToPx()),
147- maxWidth = if (minWidth.roundToPx() <= windowSize.width) windowSize.width else minWidth.roundToPx()
148- )
149- )
150- popupContentSize = IntSize (placeable.width, placeable.height)
151- offset = popupPositionProvider.calculatePosition(
152- parentBounds,
153- windowBounds,
154- layoutDirection,
155- popupContentSize,
156- popupMargin,
157- alignment
158- )
159- layout(constraints.maxWidth, constraints.maxHeight) {
160- placeable.place(currentOffset)
161- }
162- }
163- ) {
164- Box (
165- Modifier
166- .graphicsLayer(
167- clip = true ,
168- shape = shape.value,
169- shadowElevation = elevationPx,
170- ambientShadowColor = MiuixTheme .colorScheme.windowDimming,
171- spotShadowColor = MiuixTheme .colorScheme.windowDimming
172- )
173- .background(MiuixTheme .colorScheme.surface)
174- ) {
175- currentContent()
176- }
177- }
178- }
179- }
180-
181119 Layout (
182- content = {},
183120 modifier = Modifier .onGloballyPositioned { childCoordinates ->
184121 val parentCoordinates = childCoordinates.parentLayoutCoordinates!!
185122 val positionInWindow = parentCoordinates.positionInWindow()
@@ -212,6 +149,66 @@ fun ListPopup(
212149 ) { _, _ ->
213150 layout(0 , 0 ) {}
214151 }
152+
153+ PopupLayout (
154+ visible = show,
155+ enableWindowDim = enableWindowDim,
156+ transformOrigin = { transformOrigin },
157+ ) {
158+ val currentContent by rememberUpdatedState(content)
159+ val currentOffset by rememberUpdatedState(offset)
160+ val shape = remember { derivedStateOf { SmoothRoundedCornerShape (16 .dp) } }
161+ val elevationPx = with (density) { shadowElevation.toPx() }
162+ Box (
163+ modifier = popupModifier
164+ .pointerInput(Unit ) {
165+ detectTapGestures {
166+ onDismissRequest?.invoke()
167+ }
168+ }
169+ .layout { measurable, constraints ->
170+ val placeable = measurable.measure(
171+ constraints.copy(
172+ minWidth = if (minWidth.roundToPx() <= windowSize.width) minWidth.roundToPx() else windowSize.width,
173+ minHeight = if (50 .dp.roundToPx() <= windowSize.height) 50 .dp.roundToPx() else windowSize.height,
174+ maxHeight = maxHeight?.roundToPx()?.coerceAtLeast(50 .dp.roundToPx())
175+ ? : (windowBounds.height - popupMargin.top - popupMargin.bottom).coerceAtLeast(50 .dp.roundToPx()),
176+ maxWidth = if (minWidth.roundToPx() <= windowSize.width) windowSize.width else minWidth.roundToPx()
177+ )
178+ )
179+ popupContentSize = IntSize (placeable.width, placeable.height)
180+ offset = popupPositionProvider.calculatePosition(
181+ parentBounds,
182+ windowBounds,
183+ layoutDirection,
184+ popupContentSize,
185+ popupMargin,
186+ alignment
187+ )
188+ layout(constraints.maxWidth, constraints.maxHeight) {
189+ placeable.place(currentOffset)
190+ }
191+ }
192+ ) {
193+ Box (
194+ Modifier
195+ .graphicsLayer(
196+ clip = true ,
197+ shape = shape.value,
198+ shadowElevation = elevationPx,
199+ ambientShadowColor = MiuixTheme .colorScheme.windowDimming,
200+ spotShadowColor = MiuixTheme .colorScheme.windowDimming
201+ )
202+ .background(MiuixTheme .colorScheme.surface)
203+ ) {
204+ currentContent()
205+ }
206+ }
207+ }
208+
209+ BackHandler (enabled = show.value) {
210+ onDismissRequest?.invoke()
211+ }
215212}
216213
217214/* *
0 commit comments