Skip to content

Commit

Permalink
fix: swipe to reply activated too early (#3034)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorhugods authored May 24, 2024
1 parent ab3d4c4 commit b06b525
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 27 deletions.
11 changes: 0 additions & 11 deletions app/lint-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8240,17 +8240,6 @@
column="27"/>
</issue>

<issue
id="ComposeParameterOrder"
message=" Parameters in a composable function should be ordered following this pattern: params without defaults, modifiers, params with defaults and optionally, a trailing function that might not have a default param.&#xA; Current params are: [value: TextFieldValue, onValueChange: (TextFieldValue) -> Unit, placeholderText: String? = null, labelText: String? = null, labelMandatoryIcon: Boolean = false, descriptionText: String? = null, leadingIcon: @Composable (() -> Unit)? = null, trailingIcon: @Composable (() -> Unit)? = null, readOnly: Boolean = false, state: WireTextFieldState = WireTextFieldState.Default, maxLines: Int = 1, singleLine: Boolean = true, maxTextLength: Int = 8000, keyboardOptions: KeyboardOptions = KeyboardOptions(&#xA; capitalization = KeyboardCapitalization.Sentences,&#xA; autoCorrect = true&#xA;), keyboardActions: KeyboardActions = KeyboardActions.Default, scrollState: ScrollState = rememberScrollState(), interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, textStyle: TextStyle = MaterialTheme.wireTypography.body01, placeholderTextStyle: TextStyle = MaterialTheme.wireTypography.body01, placeholderAlignment: Alignment.Horizontal = Alignment.Start, inputMinHeight: Dp = MaterialTheme.wireDimensions.textFieldMinHeight, shape: Shape = RoundedCornerShape(MaterialTheme.wireDimensions.textFieldCornerSize), colors: WireTextFieldColors = wireTextFieldColors(), modifier: Modifier = Modifier, onSelectedLineIndexChanged: (Int) -> Unit = { }, onLineBottomYCoordinateChanged: (Float) -> Unit = { }, shouldDetectTaps: Boolean = false, testTag: String = String.EMPTY, onTap: (Offset) -> Unit = { }] but should be [value: TextFieldValue, onValueChange: (TextFieldValue) -> Unit, modifier: Modifier = Modifier, placeholderText: String? = null, labelText: String? = null, labelMandatoryIcon: Boolean = false, descriptionText: String? = null, leadingIcon: @Composable (() -> Unit)? = null, trailingIcon: @Composable (() -> Unit)? = null, readOnly: Boolean = false, state: WireTextFieldState = WireTextFieldState.Default, maxLines: Int = 1, singleLine: Boolean = true, maxTextLength: Int = 8000, keyboardOptions: KeyboardOptions = KeyboardOptions(&#xA; capitalization = KeyboardCapitalization.Sentences,&#xA; autoCorrect = true&#xA;), keyboardActions: KeyboardActions = KeyboardActions.Default, scrollState: ScrollState = rememberScrollState(), interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, textStyle: TextStyle = MaterialTheme.wireTypography.body01, placeholderTextStyle: TextStyle = MaterialTheme.wireTypography.body01, placeholderAlignment: Alignment.Horizontal = Alignment.Start, inputMinHeight: Dp = MaterialTheme.wireDimensions.textFieldMinHeight, shape: Shape = RoundedCornerShape(MaterialTheme.wireDimensions.textFieldCornerSize), colors: WireTextFieldColors = wireTextFieldColors(), onSelectedLineIndexChanged: (Int) -> Unit = { }, onLineBottomYCoordinateChanged: (Float) -> Unit = { }, shouldDetectTaps: Boolean = false, testTag: String = String.EMPTY, onTap: (Offset) -> Unit = { }].&#xA; See https://slackhq.github.io/compose-lints/rules/#ordering-composable-parameters-properly for more information."
errorLine1="internal fun WireTextField2("
errorLine2=" ^">
<location
file="src/main/kotlin/com/wire/android/ui/common/textfield/WireTextField2.kt"
line="73"
column="28"/>
</issue>

<issue
id="ComposePreviewNaming"
message="Preview annotations with 2 preview annotations should end with the `Previews` suffix.&#xA;See https://slackhq.github.io/compose-lints/rules/#naming-multipreview-annotations-properly for more information."
Expand Down
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,11 +66,11 @@ 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,
onValueChange: (TextFieldValue) -> Unit,
modifier: Modifier = Modifier,
placeholderText: String? = null,
labelText: String? = null,
labelMandatoryIcon: Boolean = false,
Expand All @@ -88,7 +86,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 All @@ -97,7 +94,6 @@ internal fun WireTextField2(
inputMinHeight: Dp = MaterialTheme.wireDimensions.textFieldMinHeight,
shape: Shape = RoundedCornerShape(MaterialTheme.wireDimensions.textFieldCornerSize),
colors: WireTextFieldColors = wireTextFieldColors(),
modifier: Modifier = Modifier,
onSelectedLineIndexChanged: (Int) -> Unit = { },
onLineBottomYCoordinateChanged: (Float) -> Unit = { },
shouldDetectTaps: Boolean = false,
Expand All @@ -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 b06b525

Please sign in to comment.