@@ -41,6 +41,7 @@ import androidx.compose.ui.graphics.BlendModeColorFilter
4141import androidx.compose.ui.graphics.Color
4242import androidx.compose.ui.graphics.graphicsLayer
4343import androidx.compose.ui.hapticfeedback.HapticFeedbackType
44+ import androidx.compose.ui.input.pointer.PointerEventType
4445import androidx.compose.ui.input.pointer.pointerInput
4546import androidx.compose.ui.layout.onGloballyPositioned
4647import androidx.compose.ui.layout.positionInWindow
@@ -106,36 +107,23 @@ fun SuperDropdown(
106107 enabled : Boolean = true
107108) {
108109 val isDropdownExpanded = remember { mutableStateOf(false ) }
109-
110- if (! dropdownStates.contains(isDropdownExpanded)) dropdownStates.add(isDropdownExpanded)
111- LaunchedEffect (isDropdownExpanded.value) {
112- if (isDropdownExpanded.value) {
113- dropdownStates.forEach { state -> if (state != isDropdownExpanded) state.value = false }
114- }
115- }
116-
117110 val hapticFeedback = LocalHapticFeedback .current
111+ val actionColor = if (enabled) MiuixTheme .colorScheme.onSurfaceVariantActions else MiuixTheme .colorScheme.disabledOnSecondaryVariant
118112 var alignLeft by rememberSaveable { mutableStateOf(true ) }
119113 var dropdownOffsetPx by remember { mutableStateOf(0 ) }
120114 var componentHeightPx by remember { mutableStateOf(0 ) }
121115 var componentWidthPx by remember { mutableStateOf(0 ) }
122116
123- BackHandler (enabled = isDropdownExpanded.value) {
124- dismissPopup(isDropdownExpanded)
125- }
126-
127117 BasicComponent (
128- onClick = {
129- isDropdownExpanded.value = enabled
130- hapticFeedback.performHapticFeedback(HapticFeedbackType .LongPress )
131- },
132118 modifier = modifier
133119 .pointerInput(Unit ) {
134120 awaitPointerEventScope {
135- while (true ) {
121+ while (enabled ) {
136122 val event = awaitPointerEvent()
137- val position = event.changes.first().position
138- alignLeft = position.x < (size.width / 2 )
123+ if (event.type != PointerEventType .Move ) {
124+ val eventChange = event.changes.first()
125+ alignLeft = eventChange.position.x < (size.width / 2 )
126+ }
139127 }
140128 }
141129 }
@@ -157,24 +145,33 @@ fun SuperDropdown(
157145 modifier = Modifier .padding(end = 6 .dp),
158146 text = items[selectedIndex],
159147 fontSize = 15 .sp,
160- color = if (enabled) MiuixTheme .colorScheme.onSurfaceVariantActions else MiuixTheme .colorScheme.disabledOnSecondaryVariant ,
148+ color = actionColor ,
161149 textAlign = TextAlign .End ,
162150 )
163151 Image (
164152 modifier = Modifier
165153 .size(15 .dp)
166154 .align(Alignment .CenterVertically ),
167155 imageVector = MiuixIcons .ArrowUpDown ,
168- colorFilter = BlendModeColorFilter (
169- if (enabled) MiuixTheme .colorScheme.onSurfaceVariantActions else MiuixTheme .colorScheme.disabledOnSecondaryVariant,
170- BlendMode .SrcIn
171- ),
156+ colorFilter = BlendModeColorFilter (actionColor, BlendMode .SrcIn ),
172157 contentDescription = null
173158 )
174159 },
160+ onClick = {
161+ if (enabled) {
162+ isDropdownExpanded.value = enabled
163+ hapticFeedback.performHapticFeedback(HapticFeedbackType .LongPress )
164+ }
165+ },
175166 enabled = enabled
176167 )
177168 if (isDropdownExpanded.value) {
169+ if (! dropdownStates.contains(isDropdownExpanded)) dropdownStates.add(isDropdownExpanded)
170+ LaunchedEffect (isDropdownExpanded.value) {
171+ if (isDropdownExpanded.value) {
172+ dropdownStates.forEach { state -> if (state != isDropdownExpanded) state.value = false }
173+ }
174+ }
178175 val density = LocalDensity .current
179176 var offsetPx by remember { mutableStateOf(0 ) }
180177 val textMeasurer = rememberTextMeasurer()
@@ -194,16 +191,17 @@ fun SuperDropdown(
194191 )
195192 val insideHeightPx by rememberUpdatedState(with (density) { insideMargin.height.toPx() }.roundToInt())
196193 val displayCutoutSize =
197- WindowInsets .displayCutout.asPaddingValues(density).calculateLeftPadding(LayoutDirection .Ltr ) +
198- WindowInsets .displayCutout.asPaddingValues(density) .calculateRightPadding(LayoutDirection .Ltr )
194+ WindowInsets .displayCutout.asPaddingValues(density).calculateLeftPadding(LayoutDirection .Ltr ) + WindowInsets .displayCutout.asPaddingValues(density)
195+ .calculateRightPadding(LayoutDirection .Ltr )
199196 val popupPadding by rememberUpdatedState {
200197 derivedStateOf {
201198 max(
202- horizontalPadding + (windowWeightPx.dp - componentWidthPx.dp) / 2 / density.density -
203- if (defaultWindowInsetsPadding) displayCutoutSize / 2 else 0 .dp, 0 .dp
199+ horizontalPadding + (windowWeightPx.dp - componentWidthPx.dp) / 2 / density.density
200+ - if (defaultWindowInsetsPadding) displayCutoutSize / 2 else 0 .dp, 0 .dp
204201 )
205202 }
206203 }
204+ BackHandler (enabled = isDropdownExpanded.value) { dismissPopup(isDropdownExpanded) }
207205 showPopup(
208206 content = {
209207 Box (
0 commit comments