Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: revert highlight mentions while typing (WPB-1895) #3727

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fun CodeTextField(
maxHorizontalSpacing = maxHorizontalSpacing,
horizontalAlignment = horizontalAlignment,
modifier = modifier,
innerBasicTextField = { decorator, textFieldModifier, _ ->
innerBasicTextField = { decorator, textFieldModifier ->
BasicTextField(
state = textState,
textStyle = textStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ internal fun CodeTextFieldLayout(
}
}
},
textFieldModifier = Modifier,
decorationBox = {}
textFieldModifier = Modifier
)
val bottomText = when {
state is WireTextFieldState.Error && state.errorText != null -> state.errorText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fun WirePasswordTextField(
modifier = modifier.then(autoFillModifier(autoFillType, textState::setTextAndPlaceCursorAtEnd)),
testTag = testTag,
onTap = onTap,
innerBasicTextField = { decorator, textFieldModifier, _ ->
innerBasicTextField = { decorator, textFieldModifier ->
BasicSecureTextField(
state = textState,
textStyle = textStyle.copy(color = colors.textColor(state = state).value, textDirection = TextDirection.ContentOrLtr),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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.KeyboardActionHandler
Expand All @@ -43,8 +42,6 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -56,13 +53,10 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.style.TextDirection
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.wire.android.ui.common.colorsScheme
import com.wire.android.ui.home.conversations.model.UIMention
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireDimensions
import com.wire.android.ui.theme.wireTypography
Expand Down Expand Up @@ -140,7 +134,7 @@ internal fun WireTextField(
),
onTap = onTap,
testTag = testTag,
innerBasicTextField = { decorator, textFieldModifier, _ ->
innerBasicTextField = { decorator, textFieldModifier ->
BasicTextField(
state = textState,
textStyle = textStyle.copy(
Expand Down Expand Up @@ -169,97 +163,6 @@ internal fun WireTextField(
)
}

@Composable
internal fun WireTextField(
textFieldValue: State<TextFieldValue>,
onValueChange: (TextFieldValue) -> Unit,
modifier: Modifier = Modifier,
mentions: List<UIMention> = emptyList(),
placeholderText: String? = null,
labelText: String? = null,
labelMandatoryIcon: Boolean = false,
descriptionText: String? = null,
semanticDescription: String? = null,
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
state: WireTextFieldState = WireTextFieldState.Default,
keyboardOptions: KeyboardOptions = KeyboardOptions.DefaultText,
keyboardActions: KeyboardActions = KeyboardActions.Default,
singleLine: Boolean = false,
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
minLines: Int = 1,
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 = { },
onTap: ((Offset) -> Unit)? = null,
testTag: String = String.EMPTY
) {
WireTextFieldLayout(
modifier = modifier,
shouldShowPlaceholder = textFieldValue.value.text.isEmpty(),
placeholderText = placeholderText,
labelText = labelText,
labelMandatoryIcon = labelMandatoryIcon,
descriptionText = descriptionText,
semanticDescription = semanticDescription,
leadingIcon = leadingIcon,
trailingIcon = trailingIcon,
state = state,
interactionSource = interactionSource,
placeholderTextStyle = placeholderTextStyle,
placeholderAlignment = placeholderAlignment,
inputMinHeight = inputMinHeight,
shape = shape,
colors = colors,
onTap = onTap,
testTag = testTag,
innerBasicTextField = { _, textFieldModifier, decoratorBox ->
BasicTextField(
value = textFieldValue.value,
onValueChange = onValueChange,
textStyle = textStyle.copy(
color = colors.textColor(state = state).value,
textDirection = TextDirection.ContentOrLtr
),
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
readOnly = state is WireTextFieldState.ReadOnly,
enabled = state !is WireTextFieldState.Disabled,
singleLine = singleLine,
maxLines = maxLines,
minLines = minLines,
cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),
interactionSource = interactionSource,
modifier = textFieldModifier,
decorationBox = decoratorBox,
onTextLayout = onTextLayout(
textFieldValue,
onSelectedLineIndexChanged,
onLineBottomYCoordinateChanged
),
visualTransformation = MentionVisualTransformation(colorsScheme().primary, mentions),
)
}
)
}

private fun onTextLayout(
textFieldValue: State<TextFieldValue>,
onSelectedLineIndexChanged: (Int) -> Unit = { },
onLineBottomYCoordinateChanged: (Float) -> Unit = { },
): (TextLayoutResult) -> Unit = {
val lineOfText = it.getLineForOffset(textFieldValue.value.selection.end)
val bottomYCoordinate = it.getLineBottom(lineOfText)
onSelectedLineIndexChanged(lineOfText)
onLineBottomYCoordinateChanged(bottomYCoordinate)
}

private fun onTextLayout(
state: TextFieldState,
onSelectedLineIndexChanged: (Int) -> Unit = { },
Expand Down Expand Up @@ -300,16 +203,6 @@ private fun KeyboardOptions.Companion.defaultEmail(imeAction: ImeAction): Keyboa
)
}

@PreviewMultipleThemes
@Composable
fun PreviewWireTextFieldWithTextFieldValue() = WireTheme {
WireTextField(
modifier = Modifier.padding(16.dp),
textFieldValue = remember { mutableStateOf(TextFieldValue("text")) },
onValueChange = {}
)
}

@PreviewMultipleThemes
@Composable
fun PreviewWireTextField() = WireTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,6 @@ internal fun WireTextFieldLayout(
onTap = onTap,
)
},
decorationBox = { innerTextField ->
InnerTextLayout(
innerTextField = innerTextField,
shouldShowPlaceholder = shouldShowPlaceholder,
leadingIcon = leadingIcon,
trailingIcon = trailingIcon,
placeholderText = placeholderText,
style = state,
placeholderTextStyle = placeholderTextStyle,
placeholderAlignment = placeholderAlignment,
inputMinHeight = inputMinHeight,
colors = colors,
onTap = onTap,
)
},
textFieldModifier = Modifier
.fillMaxWidth()
.background(color = colors.backgroundColor(state).value, shape = shape)
Expand Down Expand Up @@ -233,9 +218,5 @@ private fun Alignment.Horizontal.toAlignment(): Alignment = Alignment { size, sp

fun interface InnerBasicTextFieldBuilder {
@Composable
fun Build(
decorator: TextFieldDecorator,
textFieldModifier: Modifier,
decorationBox: @Composable (innerTextField: @Composable () -> Unit) -> Unit
)
fun Build(decorator: TextFieldDecorator, textFieldModifier: Modifier)
}

This file was deleted.

This file was deleted.

Loading
Loading