Skip to content

Commit 342d604

Browse files
committed
misc: cleanup
1 parent 8beca08 commit 342d604

File tree

6 files changed

+42
-29
lines changed

6 files changed

+42
-29
lines changed

composeApp/src/commonMain/kotlin/UITest.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,16 @@ fun UITest(
178178
}
179179
) {
180180
LazyColumn {
181-
items(items.size) { index ->
181+
items(items.take(3).size) { index ->
182182
DropdownImpl(
183183
text = items[index].label,
184-
optionSize = items.size,
185-
isSelected = false,
184+
optionSize = items.take(3).size,
185+
isSelected = items[index] == items[targetPage],
186186
onSelectedIndexChange = {
187+
targetPage = index
188+
coroutineScope.launch {
189+
pagerState.animateScrollToPage(index)
190+
}
187191
dismissPopup(showTopPopup)
188192
isTopPopupExpanded.value = false
189193
},
@@ -228,12 +232,16 @@ fun UITest(
228232
}
229233
) {
230234
LazyColumn {
231-
items(items.size) { index ->
235+
items(items.take(3).size) { index ->
232236
DropdownImpl(
233237
text = items[index].label,
234-
optionSize = items.size,
235-
isSelected = false,
238+
optionSize = items.take(3).size,
239+
isSelected = items[index] == items[targetPage],
236240
onSelectedIndexChange = {
241+
targetPage = index
242+
coroutineScope.launch {
243+
pagerState.animateScrollToPage(index)
244+
}
237245
dismissPopup(showBottomPopup)
238246
isBottomPopupExpanded.value = false
239247
},

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,7 @@ fun dialog2(showDialog: MutableState<Boolean>) {
449449
title = "Dropdown",
450450
items = dropdownOptions,
451451
selectedIndex = dropdownSelectedOption.value,
452-
onSelectedIndexChange = { newOption -> dropdownSelectedOption.value = newOption },
453-
defaultWindowInsetsPadding = false
452+
onSelectedIndexChange = { newOption -> dropdownSelectedOption.value = newOption }
454453
)
455454
SuperSwitch(
456455
title = "Switch",

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ import top.yukonga.miuix.kmp.utils.MiuixPopupUtil.Companion.showPopup
4444
import top.yukonga.miuix.kmp.utils.SmoothRoundedCornerShape
4545
import top.yukonga.miuix.kmp.utils.getWindowSize
4646

47+
/**
48+
* A popup with a list of items.
49+
*
50+
* @param show The show state of the [ListPopup].
51+
* @param popupModifier The modifier to be applied to the [ListPopup].
52+
* @param popupPositionProvider The [PopupPositionProvider] of the [ListPopup].
53+
* @param alignment The alignment of the [ListPopup].
54+
* @param onDismissRequest The callback when the [ListPopup] is dismissed.
55+
* @param content The [Composable] content of the [ListPopup].
56+
*/
4757
@Composable
4858
fun ListPopup(
4959
show: MutableState<Boolean>,
@@ -101,12 +111,14 @@ fun ListPopup(
101111

102112
DisposableEffect(popupPositionProvider, alignment) {
103113
val popupMargins = popupPositionProvider.getMargins()
104-
popupMargin = with(density) { IntRect(
105-
left = popupMargins.calculateLeftPadding(layoutDirection).roundToPx(),
106-
top = popupMargins.calculateTopPadding().roundToPx(),
107-
right = popupMargins.calculateRightPadding(layoutDirection).roundToPx(),
108-
bottom = popupMargins.calculateBottomPadding().roundToPx()
109-
) }
114+
popupMargin = with(density) {
115+
IntRect(
116+
left = popupMargins.calculateLeftPadding(layoutDirection).roundToPx(),
117+
top = popupMargins.calculateTopPadding().roundToPx(),
118+
right = popupMargins.calculateRightPadding(layoutDirection).roundToPx(),
119+
bottom = popupMargins.calculateBottomPadding().roundToPx()
120+
)
121+
}
110122
if (popupContentSize != IntSize.Zero) {
111123
offset = popupPositionProvider.calculatePosition(
112124
parentBounds,
@@ -198,7 +210,8 @@ fun ListPopup(
198210
PopupPositionProvider.Align.Right,
199211
PopupPositionProvider.Align.TopRight,
200212
PopupPositionProvider.Align.BottomRight,
201-
))
213+
)
214+
)
202215
parentBounds.right - popupMargin.right - 64.dp.roundToPx()
203216
else
204217
parentBounds.left + popupMargin.left + 64.dp.roundToPx()
@@ -282,6 +295,7 @@ object ListPopupDefaults {
282295
y = offsetY.coerceIn(windowBounds.top + popupMargin.top, windowBounds.bottom - popupContentSize.height - popupMargin.bottom)
283296
)
284297
}
298+
285299
override fun getMargins(): PaddingValues {
286300
return PaddingValues(horizontal = 0.dp, vertical = 8.dp)
287301
}
@@ -302,18 +316,22 @@ object ListPopupDefaults {
302316
offsetX = anchorBounds.left + popupMargin.left
303317
offsetY = anchorBounds.bottom + popupMargin.top
304318
}
319+
305320
PopupPositionProvider.Align.TopRight -> {
306321
offsetX = anchorBounds.right - popupContentSize.width - popupMargin.right
307322
offsetY = anchorBounds.bottom + popupMargin.top
308323
}
324+
309325
PopupPositionProvider.Align.BottomLeft -> {
310326
offsetX = anchorBounds.left + popupMargin.left
311327
offsetY = anchorBounds.top - popupContentSize.height - popupMargin.bottom
312328
}
329+
313330
PopupPositionProvider.Align.BottomRight -> {
314331
offsetX = anchorBounds.right - popupContentSize.width - popupMargin.right
315332
offsetY = anchorBounds.top - popupContentSize.height - popupMargin.bottom
316333
}
334+
317335
else -> {
318336
// Fallback
319337
offsetX = if (alignment == PopupPositionProvider.Align.Right) {

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,11 @@ import top.yukonga.miuix.kmp.utils.MiuixPopupUtil.Companion.dismissPopup
5656
* @param items The options of the [SuperDropdown].
5757
* @param selectedIndex The index of the selected option.
5858
* @param modifier The modifier to be applied to the [SuperDropdown].
59-
* @param popupModifier The modifier to be applied to the popup of the [SuperDropdown].
6059
* @param titleColor The color of the title.
6160
* @param summary The summary of the [SuperDropdown].
6261
* @param summaryColor The color of the summary.
6362
* @param mode The dropdown show mode of the [SuperDropdown].
64-
* @param horizontalPadding The horizontal padding of the [SuperDropdown].
6563
* @param insideMargin The margin inside the [SuperDropdown].
66-
* @param defaultWindowInsetsPadding Whether to apply default window insets padding to the [SuperDropdown].
6764
* @param enabled Whether the [SuperDropdown] is enabled.
6865
* @param showValue Whether to show the selected value of the [SuperDropdown].
6966
* @param onSelectedIndexChange The callback when the selected index of the [SuperDropdown] is changed.
@@ -74,14 +71,11 @@ fun SuperDropdown(
7471
items: List<String>,
7572
selectedIndex: Int,
7673
modifier: Modifier = Modifier,
77-
popupModifier: Modifier = Modifier,
7874
titleColor: BasicComponentColors = BasicComponentDefaults.titleColor(),
7975
summary: String? = null,
8076
summaryColor: BasicComponentColors = BasicComponentDefaults.summaryColor(),
8177
mode: DropDownMode = DropDownMode.Normal,
82-
horizontalPadding: Dp = 0.dp,
8378
insideMargin: PaddingValues = BasicComponentDefaults.InsideMargin,
84-
defaultWindowInsetsPadding: Boolean = true,
8579
enabled: Boolean = true,
8680
showValue: Boolean = true,
8781
onSelectedIndexChange: ((Int) -> Unit)?,

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import androidx.compose.ui.platform.LocalHapticFeedback
3939
import androidx.compose.ui.text.font.FontWeight
4040
import androidx.compose.ui.text.style.TextAlign
4141
import androidx.compose.ui.text.style.TextOverflow
42-
import androidx.compose.ui.unit.Dp
4342
import androidx.compose.ui.unit.DpSize
4443
import androidx.compose.ui.unit.dp
4544
import kotlinx.coroutines.launch
@@ -65,15 +64,12 @@ import top.yukonga.miuix.kmp.utils.MiuixPopupUtil.Companion.dismissPopup
6564
* @param items The list of [SpinnerEntry] to be shown in the [SuperSpinner].
6665
* @param selectedIndex The index of the selected item in the [SuperSpinner].
6766
* @param modifier The [Modifier] to be applied to the [SuperSpinner].
68-
* @param popupModifier The [Modifier] to be applied to the popup of the [SuperSpinner].
6967
* @param titleColor The color of the title of the [SuperSpinner].
7068
* @param summary The summary of the [SuperSpinner].
7169
* @param summaryColor The color of the summary of the [SuperSpinner].
7270
* @param mode The mode of the [SuperSpinner].
73-
* @param horizontalPadding The horizontal padding of the [SuperSpinner].
7471
* @param leftAction The action to be shown at the left side of the [SuperSpinner].
7572
* @param insideMargin The [PaddingValues] to be applied inside the [SuperSpinner].
76-
* @param defaultWindowInsetsPadding Whether to apply the default window insets padding to the [SuperSpinner].
7773
* @param enabled Whether the [SuperSpinner] is enabled.
7874
* @param showValue Whether to show the value of the [SuperSpinner].
7975
* @param onSelectedIndexChange The callback to be invoked when the selected index of the [SuperSpinner] is changed.
@@ -84,15 +80,12 @@ fun SuperSpinner(
8480
items: List<SpinnerEntry>,
8581
selectedIndex: Int,
8682
modifier: Modifier = Modifier,
87-
popupModifier: Modifier = Modifier,
8883
titleColor: BasicComponentColors = BasicComponentDefaults.titleColor(),
8984
summary: String? = null,
9085
summaryColor: BasicComponentColors = BasicComponentDefaults.summaryColor(),
9186
mode: SpinnerMode = SpinnerMode.Normal,
92-
horizontalPadding: Dp = 0.dp,
9387
leftAction: @Composable (() -> Unit)? = null,
9488
insideMargin: PaddingValues = BasicComponentDefaults.InsideMargin,
95-
defaultWindowInsetsPadding: Boolean = true,
9689
enabled: Boolean = true,
9790
showValue: Boolean = true,
9891
onSelectedIndexChange: ((Int) -> Unit)?,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ class MiuixPopupUtil {
7171
/**
7272
* Show a popup.
7373
*
74-
* @param transformOrigin The pivot point in terms of fraction of the overall size, used for scale transformations. By default it's [TransformOrigin.Center].
74+
* @param transformOrigin The pivot point in terms of fraction of the overall size,
75+
* used for scale transformations. By default it's [TransformOrigin.Center].
7576
* @param content The [Composable] content of the popup.
7677
*/
7778
@Composable

0 commit comments

Comments
 (0)