feat: Enhance performance and usability in chat components and emoji handling

This commit is contained in:
2026-02-08 08:18:49 +05:00
parent 11a8ff7644
commit 8b8c883a63
7 changed files with 206 additions and 95 deletions

View File

@@ -126,12 +126,15 @@ class AppleEmojiEditTextView @JvmOverloads constructor(
fun setTextWithEmojis(newText: String) {
if (newText == text.toString()) return
isUpdating = true
val cursorPos = selectionStart
setText(newText)
// Восстанавливаем позицию курсора в конец текста
val newCursorPos = if (cursorPos >= 0) newText.length else cursorPos
setSelection(newCursorPos.coerceIn(0, newText.length))
isUpdating = false
try {
val cursorPos = selectionStart
setText(newText)
// Восстанавливаем позицию курсора в конец текста
val newCursorPos = if (cursorPos >= 0) newText.length else cursorPos
setSelection(newCursorPos.coerceIn(0, newText.length))
} finally {
isUpdating = false
}
replaceEmojisWithImages(editableText)
}
@@ -297,6 +300,10 @@ fun AppleEmojiTextField(
}
},
update = { view ->
// Always update the callback to prevent stale lambda references
// after recomposition (e.g., after sending a photo)
view.onTextChange = onValueChange
if (view.text.toString() != value) {
view.setTextWithEmojis(value)
}

View File

@@ -32,7 +32,7 @@ object OptimizedEmojiCache {
private set
private const val PRELOAD_COUNT = 200 // Предзагружаем первые 200 эмодзи
private val scope = CoroutineScope(Dispatchers.Default + SupervisorJob())
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
/**
* Предзагрузка при старте приложения