Skip to content

Instantly share code, notes, and snippets.

View psinetron's full-sized avatar

Fail psinetron

View GitHub Profile
@psinetron
psinetron / TextFieldWithCustomEmoji.kt
Created November 24, 2025 18:05
TextFieldWithCustomEmoji EN
@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,
@psinetron
psinetron / Emoji.kt
Created November 24, 2025 15:38
Main Emoji EN
/**
* An object containing information about the emoji being processed.
*/
data class Emoji(val emoji: String, @DrawableRes val resource: Int)
/**
* A list of emojis we can customize
*/
val EMOJIS: List<Emoji> = listOf(
@psinetron
psinetron / EmojiExtensions.kt
Created November 17, 2025 10:44
EmojiExtensions RU
internal const val ZERO_WIDTH_SEPARATOR = "\u2063"
internal const val MARKER = 'M'
private const val MARKER_LENGTH = MARKER.toString().length + ZERO_WIDTH_SEPARATOR.length
internal fun TextFieldValue.toTextFieldValueWithEmojiMarkers(emojiRanges: List<EmojiRange>): TextFieldValue {
val annotatedString = buildAnnotatedString {
var lastIndex = 0
// Сортируем диапазоны по началу
@psinetron
psinetron / AnnotatedStringsFail.kt
Created November 17, 2025 10:39
AnnotatedStringsFail RU
val message = TextFieldValue(annotatedString = AnnotatedString("some string with tags")) //<-- Строка с тегами
BasicTextField(
value = message,
onValueChange = { newValue: TextFieldValue ->
newValue.annotatedString // <-- Вот тут вы получите строку без тегов
}
)
@psinetron
psinetron / DisplayTextWithEmoji.kt
Created November 17, 2025 10:18
DisplayTextWithEmoji v1
@Composable
private fun DisplayTextWithEmoji(
value: AnnotatedString,
textStyle: TextStyle,
) {
val textMeasurer = rememberTextMeasurer()
val density = LocalDensity.current
val emojiRanges = EMOJIS.findEmojisInText(value.text)
@psinetron
psinetron / TextFieldWithCustomEmoji.kt
Created November 17, 2025 10:16
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,
@psinetron
psinetron / TextWithCustomEmoji.kt
Created November 17, 2025 08:50
TextWithCustomEmoji
@Composable
fun TextWithCustomEmoji(
text: String,
modifier: Modifier = Modifier,
emojis: List<Emoji> = EMOJIS
) {
val emojiRanges = emojis.findEmojisInText(text)
val annotatedString = buildAnnotatedString {
@psinetron
psinetron / Emoji.kt
Created November 17, 2025 08:48
Main emoji RU
/**
* Объект, который содержит информацию об обрабатываемом emoji
*/
data class Emoji(val emoji: String, @DrawableRes val resource: Int)
/**
* Список emoji, которые мы умеем кастомизировать
*/
val EMOJIS: List<Emoji> = listOf(
//Это объяви в самом верху активити
long seconds = 5000; // 5 секунд
Handler handler = new Handler();
//Это в onResume
handler.postDelayed(new Runnable() {
@Override
public void run() {
pb.setVisibility(View.VISIBLE);
handler.postDelayed(this,seconds)