Skip to content

Commit

Permalink
update: [SuperDropdown] Change background instead of focus state when…
Browse files Browse the repository at this point in the history
… "selected".
  • Loading branch information
HowieHChen committed Oct 18, 2024
1 parent 2495c0b commit 3d14b30
Showing 1 changed file with 10 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.interaction.FocusInteraction
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
Expand All @@ -23,7 +21,6 @@ import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.ripple
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
Expand Down Expand Up @@ -115,17 +112,10 @@ fun SuperDropdown(
var dropdownOffsetYPx by remember { mutableStateOf(0) }
var componentHeightPx by remember { mutableStateOf(0) }
var componentWidthPx by remember { mutableStateOf(0) }
val interactionSource = remember { MutableInteractionSource() }
val focus = remember { mutableStateOf<FocusInteraction.Focus?>(null) }
val touchTint = remember { mutableStateOf(Color.Transparent) }

LaunchedEffect(isDropdownExpanded.value) {
if (isDropdownExpanded.value) {
focus.value = FocusInteraction.Focus().also {
interactionSource.emit(it)
}
} else {
focus.value?.let { interactionSource.emit(FocusInteraction.Unfocus(it)) }
}
isDropdownExpanded.value.let {
touchTint.value = if (it) MiuixTheme.colorScheme.touchTint else Color.Transparent
}

BasicComponent(
Expand All @@ -150,15 +140,7 @@ fun SuperDropdown(
componentWidthPx = coordinates.size.width
}
}
.clickable(
interactionSource = interactionSource,
indication = ripple()
) {
if (enabled) {
isDropdownExpanded.value = enabled
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
}
},
.background(touchTint.value),
insideMargin = insideMargin,
title = title,
titleColor = titleColor,
Expand All @@ -181,6 +163,12 @@ fun SuperDropdown(
contentDescription = null
)
},
onClick = {
if (enabled) {
isDropdownExpanded.value = enabled
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
}
},
enabled = enabled
)
if (isDropdownExpanded.value) {
Expand Down

0 comments on commit 3d14b30

Please sign in to comment.