Updated on 2026-08-14
This commit is contained in:
parent
0ad7cc6739
commit
355e0bf0ef
1 changed files with 19 additions and 2 deletions
|
|
@ -57,7 +57,7 @@ fun SimpleTextField(
|
|||
handleColor = TangemTheme.colors.text.accent,
|
||||
backgroundColor = TangemTheme.colors.text.accent.copy(alpha = 0.3f),
|
||||
)
|
||||
|
||||
val textFieldValue = textFieldValueState.copy(text = value)
|
||||
var lastTextValue by remember(proxyValue, isValuePasted) {
|
||||
textFieldValueState = textFieldValueState.copy(
|
||||
text = proxyValue,
|
||||
|
|
@ -70,6 +70,13 @@ fun SimpleTextField(
|
|||
mutableStateOf(proxyValue)
|
||||
}
|
||||
|
||||
val isSelectionChanged by rememberSelectionChanged(textFieldValue, textFieldValueState)
|
||||
LaunchedEffect(key1 = isSelectionChanged) {
|
||||
if (isSelectionChanged) {
|
||||
textFieldValueState = textFieldValue
|
||||
}
|
||||
}
|
||||
|
||||
// resets paste value cursor trigger
|
||||
LaunchedEffect(key1 = isValuePasted) {
|
||||
if (isValuePasted) {
|
||||
|
|
@ -79,7 +86,7 @@ fun SimpleTextField(
|
|||
|
||||
CompositionLocalProvider(LocalTextSelectionColors provides customTextSelectionColors) {
|
||||
BasicTextField(
|
||||
value = textFieldValueState,
|
||||
value = textFieldValue,
|
||||
onValueChange = { newTextFieldValueState ->
|
||||
textFieldValueState = newTextFieldValueState
|
||||
|
||||
|
|
@ -131,4 +138,14 @@ private fun SimpleTextPlaceholder(
|
|||
}
|
||||
textValue()
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun rememberSelectionChanged(textFieldValue: TextFieldValue, textFieldValueState: TextFieldValue) = remember {
|
||||
derivedStateOf {
|
||||
val isSelectionChanged = textFieldValue.selection != textFieldValueState.selection ||
|
||||
textFieldValue.composition != textFieldValueState.composition
|
||||
val isTextNotChanged = textFieldValue.text == textFieldValueState.text
|
||||
isSelectionChanged && isTextNotChanged
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue