Skip to content

Commit 51a67ff

Browse files
committed
library: Allow to set backgroundColor of the SuperDialog
1 parent 2040214 commit 51a67ff

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

composeApp/src/commonMain/kotlin/component/TextComponent.kt

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.Arrangement
1111
import androidx.compose.foundation.layout.Row
1212
import androidx.compose.foundation.layout.Spacer
1313
import androidx.compose.foundation.layout.fillMaxWidth
14+
import androidx.compose.foundation.layout.height
1415
import androidx.compose.foundation.layout.padding
1516
import androidx.compose.foundation.layout.size
1617
import androidx.compose.foundation.layout.width
@@ -266,10 +267,10 @@ fun TextComponent() {
266267
dialog2(showDialog2)
267268
}
268269

269-
270270
@Composable
271271
fun dialog(showDialog: MutableState<Boolean>) {
272272
if (!showDialog.value) return
273+
val value = remember { mutableStateOf("") }
273274
showDialog(
274275
content = {
275276
SuperDialog(
@@ -280,6 +281,12 @@ fun dialog(showDialog: MutableState<Boolean>) {
280281
showDialog.value = false
281282
},
282283
) {
284+
TextField(
285+
modifier = Modifier.padding(bottom = 16.dp),
286+
value = value.value,
287+
maxLines = 1,
288+
onValueChange = { value.value = it }
289+
)
283290
Row(
284291
horizontalArrangement = Arrangement.SpaceBetween
285292
) {
@@ -310,23 +317,27 @@ fun dialog(showDialog: MutableState<Boolean>) {
310317
@Composable
311318
fun dialog2(showDialog: MutableState<Boolean>) {
312319
if (!showDialog.value) return
313-
val value = remember { mutableStateOf("") }
320+
val dropdownOptions = listOf("Option 1", "Option 2")
321+
val dropdownSelectedOption = remember { mutableStateOf(0) }
314322
showDialog(
315323
content = {
316324
SuperDialog(
317325
title = "Dialog 2",
318-
summary = "Summary",
326+
backgroundColor = MiuixTheme.colorScheme.background,
319327
show = showDialog,
320328
onDismissRequest = {
321329
showDialog.value = false
322330
},
323331
) {
324-
TextField(
325-
modifier = Modifier.padding(bottom = 16.dp),
326-
value = value.value,
327-
maxLines = 1,
328-
onValueChange = { value.value = it }
329-
)
332+
Card {
333+
SuperDropdown(
334+
title = "Dropdown",
335+
items = dropdownOptions,
336+
selectedIndex = dropdownSelectedOption.value,
337+
onSelectedIndexChange = { newOption -> dropdownSelectedOption.value = newOption },
338+
)
339+
}
340+
Spacer(Modifier.height(12.dp))
330341
Row(
331342
horizontalArrangement = Arrangement.SpaceBetween
332343
) {
@@ -352,4 +363,4 @@ fun dialog2(showDialog: MutableState<Boolean>) {
352363
}
353364
}
354365
)
355-
}
366+
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import top.yukonga.miuix.kmp.utils.squircleshape.SquircleShape
4848
* @param titleColor The color of the title.
4949
* @param summary The summary of the [SuperDialog].
5050
* @param summaryColor The color of the summary.
51+
* @param backgroundColor The background color of the [SuperDialog].
5152
* @param show The state of the [SuperDialog].
5253
* @param onDismissRequest The callback when the [SuperDialog] is dismissed.
5354
* @param insideMargin The margin inside the [SuperDialog].
@@ -61,6 +62,7 @@ fun SuperDialog(
6162
titleColor: Color = MiuixTheme.colorScheme.onSurface,
6263
summary: String? = null,
6364
summaryColor: Color = MiuixTheme.colorScheme.onSurfaceVariantDialog,
65+
backgroundColor: Color = MiuixTheme.colorScheme.surfaceVariant,
6466
show: MutableState<Boolean>,
6567
onDismissRequest: () -> Unit,
6668
insideMargin: DpSize? = null,
@@ -84,13 +86,13 @@ fun SuperDialog(
8486

8587
Box(
8688
modifier = if (defaultWindowInsetsPadding) {
87-
modifier
89+
Modifier
8890
.imePadding()
8991
.navigationBarsPadding()
9092
.windowInsetsPadding(WindowInsets.displayCutout.only(WindowInsetsSides.Horizontal))
9193
.windowInsetsPadding(WindowInsets.captionBar.only(WindowInsetsSides.Top))
9294
} else {
93-
modifier
95+
Modifier
9496
}
9597
.fillMaxSize()
9698
.pointerInput(Unit) {
@@ -99,11 +101,10 @@ fun SuperDialog(
99101
onDismissRequest()
100102
})
101103
}
102-
103104
.then(paddingModifier)
104105
) {
105106
Column(
106-
modifier = Modifier
107+
modifier = modifier
107108
.then(if (contentAlignment != Alignment.Center) Modifier.fillMaxWidth() else Modifier.widthIn(max = 400.dp))
108109
.pointerInput(Unit) {
109110
detectTapGestures { /* Do nothing to consume the click */ }
@@ -115,7 +116,7 @@ fun SuperDialog(
115116
clip = false
116117
)
117118
.background(
118-
color = MiuixTheme.colorScheme.surfaceVariant,
119+
color = backgroundColor,
119120
shape = SquircleShape(bottomCornerRadius)
120121
)
121122
.padding(24.dp),

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ class MiuixPopupUtil {
108108
) {
109109
dialogContext.value?.invoke()
110110
}
111+
AnimatedVisibility(
112+
visible = isPopupShowing.value && isDialogShowing.value,
113+
modifier = Modifier.zIndex(1f).fillMaxSize(),
114+
) {
115+
Box(
116+
modifier = Modifier
117+
.fillMaxSize()
118+
.background(Color.Black.copy(alpha = 0.3f))
119+
)
120+
}
111121
}
112122
AnimatedVisibility(
113123
visible = isPopupShowing.value,

0 commit comments

Comments
 (0)