Skip to content

Commit

Permalink
chore: revert highlight mentions while typing
Browse files Browse the repository at this point in the history
  • Loading branch information
ohassine committed Dec 11, 2024
1 parent e6d8091 commit 072b7d4
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 923 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,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 +169,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 +209,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

0 comments on commit 072b7d4

Please sign in to comment.