Skip to content

Instantly share code, notes, and snippets.

@psinetron
Created November 17, 2025 10:16
Show Gist options
  • Select an option

  • Save psinetron/3f44d0844cbd29a38e1c8783901556df to your computer and use it in GitHub Desktop.

Select an option

Save psinetron/3f44d0844cbd29a38e1c8783901556df to your computer and use it in GitHub Desktop.
TextFieldWithEmoji RU
@Composable
fun TextFieldWithCustomEmoji(
value: String,
onValueChange: (String) -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
readOnly: Boolean = false,
textStyle: TextStyle = LocalTextStyle.current,
label: @Composable (() -> Unit)? = null,
placeholder: @Composable (() -> Unit)? = null,
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
isError: Boolean = false,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
singleLine: Boolean = false,
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
minLines: Int = 1,
colors: TextFieldColors = TextFieldDefaults.colors(),
) {
BasicTextField(
value = value,
onValueChange = onValueChange,
modifier = modifier,
enabled = enabled,
readOnly = readOnly,
textStyle = textStyle.copy(color = Color.Transparent), // Делаем весь текст прозрачным
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
singleLine = singleLine,
maxLines = maxLines,
minLines = minLines,
visualTransformation = VisualTransformation.None,
cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),
decorationBox = { innerTextField ->
TextFieldDefaults.DecorationBox(
value = value,
innerTextField = {
Box {
// Прозрачное поле для ввода и курсора
innerTextField()
// А поверх обычный Text, который умеет отображать кастомные emoji
DisplayTextWithEmoji(
value = AnnotatedString(value),
textStyle = textStyle
)
}
},
enabled = enabled,
singleLine = singleLine,
visualTransformation = VisualTransformation.None,
interactionSource = remember { androidx.compose.foundation.interaction.MutableInteractionSource() },
isError = isError,
label = label,
placeholder = placeholder,
leadingIcon = leadingIcon,
trailingIcon = trailingIcon,
colors = colors,
contentPadding = TextFieldDefaults.contentPaddingWithLabel()
)
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment