feat: Implement emoji preloading in background for improved performance
This commit is contained in:
@@ -35,6 +35,7 @@ import coil.request.CachePolicy
|
||||
import coil.request.ImageRequest
|
||||
import com.rosetta.messenger.ui.onboarding.PrimaryBlue
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/**
|
||||
@@ -148,12 +149,23 @@ object EmojiCache {
|
||||
var isLoaded by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
// Предзагрузка при старте приложения (вызывать из Application или MainActivity)
|
||||
fun preload(context: Context) {
|
||||
if (allEmojis != null) return
|
||||
kotlinx.coroutines.CoroutineScope(Dispatchers.IO).launch {
|
||||
loadEmojisInternal(context)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun loadEmojis(context: Context) {
|
||||
if (allEmojis != null) {
|
||||
isLoaded = true
|
||||
return
|
||||
}
|
||||
|
||||
loadEmojisInternal(context)
|
||||
}
|
||||
|
||||
private suspend fun loadEmojisInternal(context: Context) {
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val emojis = context.assets.list("emoji")
|
||||
@@ -341,20 +353,19 @@ fun AppleEmojiPickerPanel(
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
var selectedCategory by remember { mutableStateOf(EMOJI_CATEGORIES[0]) } // "All" по умолчанию
|
||||
var selectedCategory by remember { mutableStateOf(EMOJI_CATEGORIES[0]) }
|
||||
val gridState = rememberLazyGridState()
|
||||
var shouldLoad by remember { mutableStateOf(false) }
|
||||
|
||||
// Отложенная загрузка эмодзи (чтобы не блокировать UI при открытии)
|
||||
// Загружаем эмодзи если еще не загружены (без задержки если уже в кеше)
|
||||
LaunchedEffect(Unit) {
|
||||
kotlinx.coroutines.delay(100) // Задержка 100ms для плавности
|
||||
shouldLoad = true
|
||||
EmojiCache.loadEmojis(context)
|
||||
if (!EmojiCache.isLoaded) {
|
||||
EmojiCache.loadEmojis(context)
|
||||
}
|
||||
}
|
||||
|
||||
// Текущие эмодзи для выбранной категории
|
||||
val currentEmojis = remember(selectedCategory.key, EmojiCache.isLoaded, shouldLoad) {
|
||||
if (shouldLoad && EmojiCache.isLoaded) {
|
||||
val currentEmojis = remember(selectedCategory.key, EmojiCache.isLoaded) {
|
||||
if (EmojiCache.isLoaded) {
|
||||
EmojiCache.getEmojisForCategory(selectedCategory.key)
|
||||
} else {
|
||||
emptyList()
|
||||
@@ -403,7 +414,7 @@ fun AppleEmojiPickerPanel(
|
||||
)
|
||||
|
||||
// Сетка эмодзи
|
||||
if (!shouldLoad || !EmojiCache.isLoaded) {
|
||||
if (!EmojiCache.isLoaded) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
|
||||
Reference in New Issue
Block a user