From 1e998302dd57f08cd4da08bcd2a07a816cc39584 Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Mon, 20 Nov 2023 01:11:46 +0800 Subject: [PATCH] fix: request focus when decoration box hold pressed event in TextField --- .../com/highcapable/flexiui/component/TextField.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/component/TextField.kt b/flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/component/TextField.kt index 258f9a4..4de146a 100644 --- a/flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/component/TextField.kt +++ b/flexiui-core/src/commonMain/kotlin/com/highcapable/flexiui/component/TextField.kt @@ -33,6 +33,7 @@ import androidx.compose.foundation.hoverable import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.collectIsFocusedAsState import androidx.compose.foundation.interaction.collectIsHoveredAsState +import androidx.compose.foundation.interaction.collectIsPressedAsState import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Row @@ -312,6 +313,9 @@ fun PasswordTextField( contentAlignment = Alignment.Center ) { val animatedSize by animateDpAsState(if (value.text.isNotEmpty()) DefaultDecorIconSize else 0.dp) + val cInteractionSource = remember { MutableInteractionSource() } + val pressed by cInteractionSource.collectIsPressedAsState() + if (pressed) focusRequester.requestFocus() if (value.text.isEmpty() && animatedSize == 0.dp) passwordVisible = defaultPasswordVisible IconToggleButton( modifier = Modifier.size(animatedSize).pointerHoverState(TextFieldPointerState.NORMAL), @@ -321,7 +325,8 @@ fun PasswordTextField( passwordVisible = it focusRequester.requestFocus() }, - enabled = enabled + enabled = enabled, + interactionSource = cInteractionSource ) { Icon(imageVector = if (passwordVisible) Icons.ViewerOpen else Icons.ViewerClose) } } }, @@ -423,6 +428,9 @@ fun BackspaceTextField( contentAlignment = Alignment.Center ) { val animatedSize by animateDpAsState(if (value.text.isNotEmpty()) DefaultDecorIconSize else 0.dp) + val cInteractionSource = remember { MutableInteractionSource() } + val pressed by cInteractionSource.collectIsPressedAsState() + if (pressed) focusRequester.requestFocus() IconButton( onClick = { val cursorPosition = value.selection.start @@ -435,7 +443,8 @@ fun BackspaceTextField( }, modifier = Modifier.width(animatedSize).pointerHoverState(TextFieldPointerState.NORMAL), style = IconButton.style.copy(padding = DefaultDecorIconPadding), - enabled = enabled + enabled = enabled, + interactionSource = cInteractionSource ) { Icon(imageVector = Icons.Backspace) } } },