Skip to content

Commit

Permalink
fix: swipe to reply activated too early
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorhugods committed May 24, 2024
1 parent ab3d4c4 commit 82be5b3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -56,7 +54,6 @@ internal class StateSyncingModifier(
override fun InspectorInfo.inspectableProperties() {}
}

@OptIn(ExperimentalFoundationApi::class)
@PackagePrivate
internal class StateSyncingModifierNode(
private val state: TextFieldState,
Expand All @@ -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
}
}
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package com.wire.android.ui.common.textfield

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.background
import androidx.compose.foundation.border
Expand All @@ -30,7 +29,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
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.TextFieldLineLimits
Expand Down Expand Up @@ -68,7 +66,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,
Expand All @@ -88,7 +85,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,
Expand Down Expand Up @@ -116,7 +112,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,
Expand Down Expand Up @@ -159,7 +154,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)
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 82be5b3

Please sign in to comment.