mirror of
https://github.com/BetterAndroid/FlexiUI.git
synced 2025-09-08 11:34:18 +08:00
fix: focusable not work in DropdownList for Android
This commit is contained in:
@@ -70,6 +70,8 @@ import androidx.compose.ui.UiComposable
|
|||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.focus.FocusDirection
|
import androidx.compose.ui.focus.FocusDirection
|
||||||
import androidx.compose.ui.focus.FocusManager
|
import androidx.compose.ui.focus.FocusManager
|
||||||
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
|
import androidx.compose.ui.focus.focusRequester
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.Shape
|
import androidx.compose.ui.graphics.Shape
|
||||||
import androidx.compose.ui.graphics.SolidColor
|
import androidx.compose.ui.graphics.SolidColor
|
||||||
@@ -163,6 +165,7 @@ fun DropdownList(
|
|||||||
) {
|
) {
|
||||||
val focused by interactionSource.collectIsFocusedAsState()
|
val focused by interactionSource.collectIsFocusedAsState()
|
||||||
val hovered by interactionSource.collectIsHoveredAsState()
|
val hovered by interactionSource.collectIsHoveredAsState()
|
||||||
|
val focusRequester = remember { FocusRequester() }
|
||||||
var menuHeightPx by remember { mutableStateOf(0) }
|
var menuHeightPx by remember { mutableStateOf(0) }
|
||||||
val startPadding = style.startPadding.orElse() ?: style.padding
|
val startPadding = style.startPadding.orElse() ?: style.padding
|
||||||
val endPadding = style.endPadding.orElse() ?: style.padding
|
val endPadding = style.endPadding.orElse() ?: style.padding
|
||||||
@@ -185,12 +188,16 @@ fun DropdownList(
|
|||||||
style = style,
|
style = style,
|
||||||
border = border,
|
border = border,
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
|
focusRequester = focusRequester,
|
||||||
interactionSource = interactionSource,
|
interactionSource = interactionSource,
|
||||||
modifier = modifier.rippleClickable(
|
modifier = modifier.rippleClickable(
|
||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
role = Role.DropdownList,
|
role = Role.DropdownList,
|
||||||
interactionSource = interactionSource
|
interactionSource = interactionSource
|
||||||
) { onExpandedChange(!expanded) }
|
) {
|
||||||
|
focusRequester.requestFocus()
|
||||||
|
onExpandedChange(!expanded)
|
||||||
|
}
|
||||||
),
|
),
|
||||||
menuHeightPx = { menuHeightPx = it }
|
menuHeightPx = { menuHeightPx = it }
|
||||||
) {
|
) {
|
||||||
@@ -366,9 +373,11 @@ private fun Modifier.dropdownList(
|
|||||||
style: DropdownListStyle,
|
style: DropdownListStyle,
|
||||||
border: BorderStroke,
|
border: BorderStroke,
|
||||||
enabled: Boolean,
|
enabled: Boolean,
|
||||||
|
focusRequester: FocusRequester,
|
||||||
interactionSource: MutableInteractionSource,
|
interactionSource: MutableInteractionSource,
|
||||||
modifier: Modifier
|
modifier: Modifier
|
||||||
) = status(enabled)
|
) = status(enabled)
|
||||||
|
.focusRequester(focusRequester)
|
||||||
.focusable(enabled, interactionSource)
|
.focusable(enabled, interactionSource)
|
||||||
.hoverable(interactionSource, enabled)
|
.hoverable(interactionSource, enabled)
|
||||||
.clip(style.shape)
|
.clip(style.shape)
|
||||||
|
Reference in New Issue
Block a user