Skip to content

Commit 61188b9

Browse files
committed
1
1 parent 2ab6b28 commit 61188b9

File tree

6 files changed

+402
-165
lines changed

6 files changed

+402
-165
lines changed

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

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ import androidx.compose.runtime.remember
2222
import androidx.compose.runtime.setValue
2323
import androidx.compose.ui.Alignment
2424
import androidx.compose.ui.Modifier
25+
import androidx.compose.ui.geometry.CornerRadius
26+
import androidx.compose.ui.geometry.Size
27+
import androidx.compose.ui.graphics.Color
28+
import androidx.compose.ui.graphics.drawscope.DrawScope
29+
import androidx.compose.ui.graphics.painter.Painter
30+
import androidx.compose.ui.unit.Dp
2531
import androidx.compose.ui.unit.dp
2632
import top.yukonga.miuix.kmp.basic.BasicComponent
2733
import top.yukonga.miuix.kmp.basic.Box
@@ -35,10 +41,15 @@ import top.yukonga.miuix.kmp.basic.Text
3541
import top.yukonga.miuix.kmp.basic.TextButton
3642
import top.yukonga.miuix.kmp.basic.TextField
3743
import top.yukonga.miuix.kmp.extra.CheckboxLocation
44+
import top.yukonga.miuix.kmp.extra.DropDownMode
45+
import top.yukonga.miuix.kmp.extra.SpinnerEntry
46+
import top.yukonga.miuix.kmp.extra.SpinnerMode
3847
import top.yukonga.miuix.kmp.extra.SuperArrow
3948
import top.yukonga.miuix.kmp.extra.SuperCheckbox
4049
import top.yukonga.miuix.kmp.extra.SuperDialog
4150
import top.yukonga.miuix.kmp.extra.SuperDropdown
51+
import top.yukonga.miuix.kmp.extra.SuperSpinner
52+
import top.yukonga.miuix.kmp.extra.SuperSpinnerAsDialog
4253
import top.yukonga.miuix.kmp.extra.SuperSwitch
4354
import top.yukonga.miuix.kmp.theme.MiuixTheme
4455
import top.yukonga.miuix.kmp.utils.MiuixPopupUtil.Companion.dismissDialog
@@ -52,8 +63,17 @@ fun TextComponent() {
5263
var switch by remember { mutableStateOf(false) }
5364
var switchTrue by remember { mutableStateOf(true) }
5465
val dropdownOptions = listOf("Option 1", "Option 2", "Option 3", "Option 4")
55-
val dropdownSelectedOption = remember { mutableStateOf(0) }
56-
val dropdownSelectedOptionRight = remember { mutableStateOf(1) }
66+
val dropdownOptionSelected = remember { mutableStateOf(0) }
67+
val dropdownOptionSelectedRight = remember { mutableStateOf(1) }
68+
val spinnerOptions = listOf(
69+
SpinnerEntry(icon = { Icon(RoundedRectanglePainter(), "Icon", Modifier.padding(end = 12.dp), Color(0xFFFF5B29)) }, "Option 1", "Red"),
70+
SpinnerEntry(icon = { Icon(RoundedRectanglePainter(), "Icon", Modifier.padding(end = 12.dp), Color(0xFF36D167)) }, "Option 2", "Green"),
71+
SpinnerEntry(icon = { Icon(RoundedRectanglePainter(), "Icon", Modifier.padding(end = 12.dp), Color(0xFF3482FF)) }, "Option 3", "Blue"),
72+
SpinnerEntry(icon = { Icon(RoundedRectanglePainter(), "Icon", Modifier.padding(end = 12.dp), Color(0xFFFFB21D)) }, "Option 4", "Yellow"),
73+
)
74+
val spinnerOptionSelected = remember { mutableStateOf(0) }
75+
val spinnerOptionSelectedRight = remember { mutableStateOf(1) }
76+
val spinnerOptionSelectedDialog = remember { mutableStateOf(2) }
5777
var miuixSuperCheckbox by remember { mutableStateOf("State: false") }
5878
var miuixSuperCheckboxState by remember { mutableStateOf(false) }
5979
var miuixSuperRightCheckbox by remember { mutableStateOf("false") }
@@ -295,7 +315,6 @@ fun TextComponent() {
295315
}
296316

297317
SmallTitle(text = "Dropdown")
298-
299318
Card(
300319
modifier = Modifier
301320
.padding(horizontal = 12.dp)
@@ -305,17 +324,17 @@ fun TextComponent() {
305324
title = "Dropdown",
306325
summary = "Popup near click",
307326
items = dropdownOptions,
308-
selectedIndex = dropdownSelectedOption.value,
309-
onSelectedIndexChange = { newOption -> dropdownSelectedOption.value = newOption },
327+
selectedIndex = dropdownOptionSelected.value,
328+
onSelectedIndexChange = { newOption -> dropdownOptionSelected.value = newOption },
310329
)
311330

312331
SuperDropdown(
313332
title = "Dropdown",
314333
summary = "Popup always on right",
315-
alwaysRight = true,
316334
items = dropdownOptions,
317-
selectedIndex = dropdownSelectedOptionRight.value,
318-
onSelectedIndexChange = { newOption -> dropdownSelectedOptionRight.value = newOption },
335+
selectedIndex = dropdownOptionSelectedRight.value,
336+
onSelectedIndexChange = { newOption -> dropdownOptionSelectedRight.value = newOption },
337+
mode = DropDownMode.AlwaysAtRight
319338
)
320339

321340
SuperDropdown(
@@ -327,6 +346,47 @@ fun TextComponent() {
327346
)
328347
}
329348

349+
SmallTitle(text = "Spinner")
350+
Card(
351+
modifier = Modifier
352+
.padding(horizontal = 12.dp)
353+
.padding(bottom = 6.dp)
354+
) {
355+
SuperSpinner(
356+
title = "Spinner",
357+
summary = "Spinner near click",
358+
items = spinnerOptions,
359+
selectedIndex = spinnerOptionSelected.value,
360+
onSelectedIndexChange = { newOption -> spinnerOptionSelected.value = newOption },
361+
)
362+
363+
SuperSpinner(
364+
title = "Spinner",
365+
summary = "Spinner always on right",
366+
items = spinnerOptions,
367+
selectedIndex = spinnerOptionSelectedRight.value,
368+
onSelectedIndexChange = { newOption -> spinnerOptionSelectedRight.value = newOption },
369+
mode = SpinnerMode.AlwaysAtRight,
370+
)
371+
372+
SuperSpinnerAsDialog(
373+
title = "Spinner",
374+
summary = "Spinner as Dialog",
375+
dialogButtonString = "Cancel",
376+
items = spinnerOptions,
377+
selectedIndex = spinnerOptionSelectedDialog.value,
378+
onSelectedIndexChange = { newOption -> spinnerOptionSelectedDialog.value = newOption },
379+
)
380+
381+
SuperSpinner(
382+
title = "Disabled Spinner",
383+
items = listOf(SpinnerEntry(icon = null, title = "Option 4")),
384+
selectedIndex = 0,
385+
onSelectedIndexChange = {},
386+
enabled = false
387+
)
388+
}
389+
330390
dialog(showDialog)
331391
dialog2(showDialog2)
332392
}
@@ -424,3 +484,17 @@ fun dialog2(showDialog: MutableState<Boolean>) {
424484
}
425485
}
426486
}
487+
488+
class RoundedRectanglePainter(
489+
private val cornerRadius: Dp = 6.dp
490+
) : Painter() {
491+
override val intrinsicSize = Size.Unspecified
492+
493+
override fun DrawScope.onDraw() {
494+
drawRoundRect(
495+
color = Color.White,
496+
size = Size(size.width, size.height),
497+
cornerRadius = CornerRadius(cornerRadius.toPx(), cornerRadius.toPx())
498+
)
499+
}
500+
}

miuix/build.gradle.kts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,3 @@ android {
5858
minSdk = libs.versions.android.minSdk.get().toInt()
5959
}
6060
}
61-
62-
compose.resources {
63-
publicResClass = false
64-
packageOfResClass = "top.yukonga.miuix.kmp.resources"
65-
generateResClass = auto
66-
}

miuix/src/commonMain/composeResources/values-zh-rCN/strings.xml

Lines changed: 0 additions & 3 deletions
This file was deleted.

miuix/src/commonMain/composeResources/values/strings.xml

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ import kotlin.math.roundToInt
9292
* @param titleColor The color of the title.
9393
* @param summary The summary of the [SuperDropdown].
9494
* @param summaryColor The color of the summary.
95+
* @param mode The dropdown show mode of the [SuperDropdown].
9596
* @param horizontalPadding The horizontal padding of the [SuperDropdown].
96-
* @param alwaysRight Whether the popup is always show on the right side.
9797
* @param insideMargin The margin inside the [SuperDropdown].
9898
* @param defaultWindowInsetsPadding Whether to apply default window insets padding to the [SuperDropdown].
9999
* @param enabled Whether the [SuperDropdown] is enabled.
@@ -109,7 +109,7 @@ fun SuperDropdown(
109109
titleColor: BasicComponentColors = BasicComponentDefaults.titleColor(),
110110
summary: String? = null,
111111
summaryColor: BasicComponentColors = BasicComponentDefaults.summaryColor(),
112-
alwaysRight: Boolean = false,
112+
mode: DropDownMode = DropDownMode.Normal,
113113
horizontalPadding: Dp = 0.dp,
114114
insideMargin: PaddingValues = BasicComponentDefaults.InsideMargin,
115115
defaultWindowInsetsPadding: Boolean = true,
@@ -275,7 +275,7 @@ fun SuperDropdown(
275275
LazyColumn(
276276
modifier = Modifier
277277
.onGloballyPositioned { layoutCoordinates ->
278-
offsetXPx = if (alwaysRight || !alignLeft) {
278+
offsetXPx = if (mode == DropDownMode.AlwaysAtRight || !alignLeft) {
279279
dropdownOffsetXPx + componentWidthPx - insideRightPx - layoutCoordinates.size.width - paddingPx - if (defaultWindowInsetsPadding) displayCutoutLeftSize.value else 0
280280
} else {
281281
dropdownOffsetXPx + paddingPx + insideLeftPx - if (defaultWindowInsetsPadding) displayCutoutLeftSize.value else 0
@@ -375,7 +375,7 @@ fun DropdownImpl(
375375
Text(
376376
modifier = Modifier.width(textWidthDp ?: 50.dp),
377377
text = text,
378-
fontSize = 16.sp,
378+
fontSize = MiuixTheme.textStyles.body1.fontSize,
379379
fontWeight = FontWeight.Medium,
380380
color = textColor,
381381
)
@@ -437,3 +437,11 @@ fun calculateOffsetYPx(
437437
* Only one dropdown is allowed to be displayed at a time.
438438
*/
439439
val dropdownStates = mutableStateListOf<MutableState<Boolean>>()
440+
441+
/**
442+
* The dropdown show mode.
443+
*/
444+
enum class DropDownMode {
445+
Normal,
446+
AlwaysAtRight
447+
}

0 commit comments

Comments
 (0)