feat: Enhance performance and usability in chat components and emoji handling
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
/**
|
||||
* Предзагрузка при старте приложения
|
||||
|
||||
Reference in New Issue
Block a user