From 48d7c072a3059bb48ee04644f4e582e1e29f52bf Mon Sep 17 00:00:00 2001 From: Vitor Hugo Schwaab Date: Fri, 24 May 2024 12:47:07 +0200 Subject: [PATCH] fix: swipe to reply activated too early --- .../ui/common/textfield/StateSyncingModifier.kt | 11 ++++------- .../android/ui/common/textfield/WireTextField2.kt | 6 ++---- gradle/libs.versions.toml | 4 ++-- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/ui/common/textfield/StateSyncingModifier.kt b/app/src/main/kotlin/com/wire/android/ui/common/textfield/StateSyncingModifier.kt index afba166ade1..f60684e46a7 100644 --- a/app/src/main/kotlin/com/wire/android/ui/common/textfield/StateSyncingModifier.kt +++ b/app/src/main/kotlin/com/wire/android/ui/common/textfield/StateSyncingModifier.kt @@ -17,8 +17,6 @@ */ package com.wire.android.ui.common.textfield -import androidx.compose.foundation.ExperimentalFoundationApi -import androidx.compose.foundation.text.input.TextFieldCharSequence import androidx.compose.foundation.text.input.TextFieldState import androidx.compose.ui.Modifier import androidx.compose.ui.node.ModifierNodeElement @@ -56,7 +54,6 @@ internal class StateSyncingModifier( override fun InspectorInfo.inspectableProperties() {} } -@OptIn(ExperimentalFoundationApi::class) @PackagePrivate internal class StateSyncingModifierNode( private val state: TextFieldState, @@ -67,12 +64,12 @@ internal class StateSyncingModifierNode( fun update(value: TextFieldValue, onValueChanged: (TextFieldValue) -> Unit) { this.onValueChanged = onValueChanged - if (value.text != state.text.toString() || value.selection != state.text.selection) { + if (value.text != state.text.toString() || value.selection != state.selection) { state.edit { if (value.text != state.text.toString()) { replace(0, length, value.text) } - if (value.selection != state.text.selection) { + if (value.selection != state.selection) { selection = value.selection } } @@ -89,9 +86,9 @@ internal class StateSyncingModifierNode( } private fun observeTextState(fireOnValueChanged: Boolean = true) { - lateinit var text: TextFieldCharSequence + lateinit var text: TextFieldState observeReads { - text = state.text + text = state } if (fireOnValueChanged) { val newValue = TextFieldValue( diff --git a/app/src/main/kotlin/com/wire/android/ui/common/textfield/WireTextField2.kt b/app/src/main/kotlin/com/wire/android/ui/common/textfield/WireTextField2.kt index 25c770f9ca0..e7b44af0e5d 100644 --- a/app/src/main/kotlin/com/wire/android/ui/common/textfield/WireTextField2.kt +++ b/app/src/main/kotlin/com/wire/android/ui/common/textfield/WireTextField2.kt @@ -33,6 +33,7 @@ import androidx.compose.foundation.text.BasicTextField import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.input.InputTransformation +import androidx.compose.foundation.text.input.KeyboardActionHandler import androidx.compose.foundation.text.input.TextFieldLineLimits import androidx.compose.foundation.text.input.maxLength import androidx.compose.foundation.text.input.rememberTextFieldState @@ -68,7 +69,6 @@ import com.wire.android.util.ui.PreviewMultipleThemes * which take TextFieldValue or String with onValueChange callback are the previous generation ones. * This hybrid is created to allow us to still pass TextFieldValue and onValueChange callback but already use the new text input version. */ -@OptIn(ExperimentalFoundationApi::class) @Composable internal fun WireTextField2( value: TextFieldValue, @@ -88,7 +88,6 @@ internal fun WireTextField2( capitalization = KeyboardCapitalization.Sentences, autoCorrect = true ), - keyboardActions: KeyboardActions = KeyboardActions.Default, scrollState: ScrollState = rememberScrollState(), interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, textStyle: TextStyle = MaterialTheme.wireTypography.body01, @@ -116,7 +115,6 @@ internal fun WireTextField2( state = textState, textStyle = textStyle.copy(color = colors.textColor(state = state).value, textDirection = TextDirection.ContentOrLtr), keyboardOptions = keyboardOptions, - keyboardActions = keyboardActions, lineLimits = lineLimits, inputTransformation = InputTransformation.maxLength(maxTextLength), scrollState = scrollState, @@ -159,7 +157,7 @@ internal fun WireTextField2( }, onTextLayout = { it()?.let { - val lineOfText = it.getLineForOffset(textState.text.selection.end) + val lineOfText = it.getLineForOffset(textState.selection.end) val bottomYCoordinate = it.getLineBottom(lineOfText) onSelectedLineIndexChanged(lineOfText) onLineBottomYCoordinateChanged(bottomYCoordinate) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 32ae97c1b02..3f2dd503b88 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -45,8 +45,8 @@ androidx-startup = "1.1.1" # Compose composeBom = "2024.04.01" -compose-foundation = "1.7.0-alpha05" # remove when composeBom contains new stable version of BasicTextField2 -compose-material-android = "1.7.0-alpha05" # remove when composeBom contains new stable version of BasicTextField2 +compose-foundation = "1.7.0-beta01" # remove when composeBom contains new stable version of BasicTextField2 +compose-material-android = "1.7.0-beta01" # remove when composeBom contains new stable version of BasicTextField2 compose-activity = "1.8.2" compose-compiler = "1.5.11" compose-constraint = "1.0.1"