11package top.yukonga.miuix.kmp.extra
22
3+ import androidx.compose.animation.animateColorAsState
4+ import androidx.compose.animation.core.spring
35import androidx.compose.foundation.Image
46import androidx.compose.foundation.background
57import androidx.compose.foundation.clickable
@@ -24,6 +26,7 @@ import androidx.compose.foundation.lazy.LazyColumn
2426import androidx.compose.runtime.Composable
2527import androidx.compose.runtime.LaunchedEffect
2628import androidx.compose.runtime.MutableState
29+ import androidx.compose.runtime.State
2730import androidx.compose.runtime.getValue
2831import androidx.compose.runtime.mutableStateListOf
2932import androidx.compose.runtime.mutableStateOf
@@ -107,16 +110,13 @@ fun SuperDropdown(
107110 val isDropdownExpanded = remember { mutableStateOf(false ) }
108111 val hapticFeedback = LocalHapticFeedback .current
109112 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 ))
110115 var alignLeft by rememberSaveable { mutableStateOf(true ) }
111116 var dropdownOffsetXPx by remember { mutableStateOf(0 ) }
112117 var dropdownOffsetYPx by remember { mutableStateOf(0 ) }
113118 var componentHeightPx by remember { mutableStateOf(0 ) }
114119 var componentWidthPx by remember { mutableStateOf(0 ) }
115- val touchTint = remember { mutableStateOf(Color .Transparent ) }
116-
117- isDropdownExpanded.value.let {
118- touchTint.value = if (it) MiuixTheme .colorScheme.touchTint else Color .Transparent
119- }
120120
121121 BasicComponent (
122122 modifier = modifier
@@ -140,7 +140,7 @@ fun SuperDropdown(
140140 componentWidthPx = coordinates.size.width
141141 }
142142 }
143- .background(touchTint.value ),
143+ .background(touchTint),
144144 insideMargin = insideMargin,
145145 title = title,
146146 titleColor = titleColor,
@@ -196,7 +196,7 @@ fun SuperDropdown(
196196 val captionBarPx by rememberUpdatedState(
197197 with (density) { WindowInsets .captionBar.asPaddingValues().calculateBottomPadding().toPx() }.roundToInt()
198198 )
199- val insideWidthPx by rememberUpdatedState(with (density){ insideMargin.width.toPx() }.roundToInt())
199+ val insideWidthPx by rememberUpdatedState(with (density) { insideMargin.width.toPx() }.roundToInt())
200200 val insideHeightPx by rememberUpdatedState(with (density) { insideMargin.height.toPx() }.roundToInt())
201201 val displayCutoutLeftSize = rememberUpdatedState(with (density) {
202202 WindowInsets .displayCutout.asPaddingValues(density).calculateLeftPadding(LayoutDirection .Ltr ).toPx()
@@ -245,8 +245,10 @@ fun SuperDropdown(
245245 }
246246 .align(AbsoluteAlignment .TopLeft )
247247 .graphicsLayer(
248- shadowElevation = 18f ,
249- shape = SmoothRoundedCornerShape (18 .dp)
248+ 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 )
250252 )
251253 .clip(SmoothRoundedCornerShape (18 .dp))
252254 .background(MiuixTheme .colorScheme.surface)
@@ -365,8 +367,8 @@ fun calculateOffsetYPx(
365367 dropdownOffsetPx + componentHeightPx - insideHeightPx / 2
366368 } else if (dropdownOffsetPx - statusBarPx > dropdownHeightPx) {
367369 // Show above
368- dropdownOffsetPx - dropdownHeightPx + insideHeightPx / 2
369- } else if (windowHeightPx - statusBarPx - captionBarPx - navigationBarPx <= dropdownHeightPx) {
370+ dropdownOffsetPx - dropdownHeightPx + insideHeightPx / 2
371+ } else if (windowHeightPx - statusBarPx - captionBarPx - navigationBarPx <= dropdownHeightPx) {
370372 // Special handling when the height of the popup is maxsize (== windowHeightPx)
371373 0
372374 } else if (windowHeightPx - dropdownOffsetPx < dropdownHeightPx / 2 + captionBarPx + navigationBarPx + insideHeightPx + componentHeightPx / 2 ) {
0 commit comments