@@ -14,19 +14,21 @@ import androidx.compose.foundation.layout.asPaddingValues
1414import androidx.compose.foundation.layout.captionBar
1515import androidx.compose.foundation.layout.displayCutout
1616import androidx.compose.foundation.layout.fillMaxSize
17+ import androidx.compose.foundation.layout.heightIn
1718import androidx.compose.foundation.layout.navigationBars
1819import androidx.compose.foundation.layout.offset
1920import androidx.compose.foundation.layout.only
2021import androidx.compose.foundation.layout.padding
2122import androidx.compose.foundation.layout.size
2223import androidx.compose.foundation.layout.statusBars
2324import androidx.compose.foundation.layout.width
25+ import androidx.compose.foundation.layout.widthIn
2426import androidx.compose.foundation.layout.windowInsetsPadding
2527import androidx.compose.foundation.lazy.LazyColumn
2628import androidx.compose.runtime.Composable
29+ import androidx.compose.runtime.DisposableEffect
2730import androidx.compose.runtime.LaunchedEffect
2831import androidx.compose.runtime.MutableState
29- import androidx.compose.runtime.State
3032import androidx.compose.runtime.getValue
3133import androidx.compose.runtime.mutableStateListOf
3234import androidx.compose.runtime.mutableStateOf
@@ -110,14 +112,20 @@ fun SuperDropdown(
110112 val isDropdownExpanded = remember { mutableStateOf(false ) }
111113 val hapticFeedback = LocalHapticFeedback .current
112114 val actionColor = if (enabled) MiuixTheme .colorScheme.onSurfaceVariantActions else MiuixTheme .colorScheme.disabledOnSecondaryVariant
113- val targetColor = if (isDropdownExpanded.value) MiuixTheme .colorScheme.onBackground.copy(alpha = 0.15f ) else Color .Transparent
114- val touchTint by animateColorAsState(targetValue = targetColor, animationSpec = spring(stiffness = 2000f ))
115+ val targetColor = if (isDropdownExpanded.value) MiuixTheme .colorScheme.selectedTint else Color .Transparent
116+ val selectedTint by animateColorAsState(targetValue = targetColor, animationSpec = spring(stiffness = 2000f ))
115117 var alignLeft by rememberSaveable { mutableStateOf(true ) }
116118 var dropdownOffsetXPx by remember { mutableStateOf(0 ) }
117119 var dropdownOffsetYPx by remember { mutableStateOf(0 ) }
118120 var componentHeightPx by remember { mutableStateOf(0 ) }
119121 var componentWidthPx by remember { mutableStateOf(0 ) }
120122
123+ DisposableEffect (Unit ) {
124+ onDispose {
125+ dismissPopup(isDropdownExpanded)
126+ }
127+ }
128+
121129 BasicComponent (
122130 modifier = modifier
123131 .pointerInput(Unit ) {
@@ -140,7 +148,7 @@ fun SuperDropdown(
140148 componentWidthPx = coordinates.size.width
141149 }
142150 }
143- .background(touchTint ),
151+ .background(selectedTint ),
144152 insideMargin = insideMargin,
145153 title = title,
146154 titleColor = titleColor,
@@ -196,6 +204,9 @@ fun SuperDropdown(
196204 val captionBarPx by rememberUpdatedState(
197205 with (density) { WindowInsets .captionBar.asPaddingValues().calculateBottomPadding().toPx() }.roundToInt()
198206 )
207+ val dropdownMaxHeight by rememberUpdatedState(with (density) {
208+ (windowHeightPx - statusBarPx - navigationBarPx - captionBarPx ).toDp()
209+ })
199210 val insideWidthPx by rememberUpdatedState(with (density) { insideMargin.width.toPx() }.roundToInt())
200211 val insideHeightPx by rememberUpdatedState(with (density) { insideMargin.height.toPx() }.roundToInt())
201212 val displayCutoutLeftSize = rememberUpdatedState(with (density) {
@@ -243,14 +254,15 @@ fun SuperDropdown(
243254 captionBarPx
244255 )
245256 }
257+ .heightIn(50 .dp, dropdownMaxHeight)
246258 .align(AbsoluteAlignment .TopLeft )
247259 .graphicsLayer(
248260 shadowElevation = 40f ,
249- shape = SmoothRoundedCornerShape (18 .dp),
250- ambientShadowColor = MiuixTheme .colorScheme.onBackground .copy(alpha = 0.2f ),
251- spotShadowColor = MiuixTheme .colorScheme.onBackground .copy(alpha = 0.6f )
261+ shape = SmoothRoundedCornerShape (16 .dp),
262+ ambientShadowColor = Color . Black .copy(alpha = 0.2f ),
263+ spotShadowColor = Color . Black .copy(alpha = 0.6f )
252264 )
253- .clip(SmoothRoundedCornerShape (18 .dp))
265+ .clip(SmoothRoundedCornerShape (16 .dp))
254266 .background(MiuixTheme .colorScheme.surface)
255267 ) {
256268 item {
@@ -295,8 +307,15 @@ fun DropdownImpl(
295307 onSelectedIndexChange : (Int ) -> Unit ,
296308 textWidthDp : Dp ?
297309) {
298- val additionalTopPadding = if (index == 0 ) 24 .dp else 14 .dp
299- val additionalBottomPadding = if (index == optionSize - 1 ) 24 .dp else 14 .dp
310+ val additionalTopPadding: Dp
311+ val additionalBottomPadding: Dp
312+ if (optionSize == 1 ) {
313+ additionalTopPadding = 16 .dp
314+ additionalBottomPadding = 16 .dp
315+ } else {
316+ additionalTopPadding = if (index == 0 ) 22.5f .dp else 14.5f .dp
317+ additionalBottomPadding = if (index == optionSize - 1 ) 22.5f .dp else 14.5f .dp
318+ }
300319 val textColor = if (isSelected) {
301320 MiuixTheme .colorScheme.onTertiaryContainer
302321 } else {
@@ -320,18 +339,19 @@ fun DropdownImpl(
320339 onSelectedIndexChange(index)
321340 }
322341 .background(backgroundColor)
323- .padding(horizontal = 24 .dp)
342+ .widthIn(200 .dp, 288 .dp)
343+ .padding(horizontal = 20 .dp)
324344 .padding(top = additionalTopPadding, bottom = additionalBottomPadding)
325345 ) {
326346 Text (
327347 modifier = Modifier .width(textWidthDp ? : 50 .dp),
328348 text = text,
329- fontSize = 15 .sp,
349+ fontSize = 16 .sp,
330350 fontWeight = FontWeight .Medium ,
331351 color = textColor,
332352 )
333353 Image (
334- modifier = Modifier .padding(start = 50 .dp).size(20 .dp),
354+ modifier = Modifier .padding(start = 12 .dp).size(20 .dp),
335355 imageVector = MiuixIcons .Check ,
336356 colorFilter = BlendModeColorFilter (selectColor, BlendMode .SrcIn ),
337357 contentDescription = null ,
@@ -370,7 +390,7 @@ fun calculateOffsetYPx(
370390 dropdownOffsetPx - dropdownHeightPx + insideHeightPx / 2
371391 } else if (windowHeightPx - statusBarPx - captionBarPx - navigationBarPx <= dropdownHeightPx) {
372392 // Special handling when the height of the popup is maxsize (== windowHeightPx)
373- 0
393+ statusBarPx
374394 } else if (windowHeightPx - dropdownOffsetPx < dropdownHeightPx / 2 + captionBarPx + navigationBarPx + insideHeightPx + componentHeightPx / 2 ) {
375395 windowHeightPx - dropdownHeightPx - insideHeightPx - captionBarPx - navigationBarPx
376396 } else {
0 commit comments