From b6f37f06b34458de06ee901a5225edd16aeb7e25 Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Tue, 19 May 2026 07:25:10 +0000 Subject: [PATCH] fix contact list to be lazy --- .../simplex/common/views/helpers/Section.kt | 3 +- .../common/views/newchat/NewChatSheet.kt | 84 +++++++------------ 2 files changed, 33 insertions(+), 54 deletions(-) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/Section.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/Section.kt index c8b0dc70ec..5c2369c8c4 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/Section.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/Section.kt @@ -27,6 +27,7 @@ import chat.simplex.res.MR private val SectionCardShape = RoundedCornerShape(16.dp) val CARD_PADDING = 16.dp +val ICON_TEXT_SPACING = 5.dp val CARD_ITEM_PADDING = CARD_PADDING - 1.dp // Set to true by SectionView around its inner Column. SectionItemView reads it @@ -341,7 +342,7 @@ fun SectionBottomSpacer() { @Composable fun TextIconSpaced(extraPadding: Boolean = false) { - Spacer(Modifier.padding(horizontal = if (extraPadding) 17.dp else 5.dp)) + Spacer(Modifier.padding(horizontal = if (extraPadding) 17.dp else ICON_TEXT_SPACING)) } @Composable diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/newchat/NewChatSheet.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/newchat/NewChatSheet.kt index 7ead6c620d..5ad7b1eef3 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/newchat/NewChatSheet.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/newchat/NewChatSheet.kt @@ -322,36 +322,26 @@ private fun ModalData.NewChatSheetLayout( item { DeletedChatsItem(actionButtonsOriginal.asReversed()) } - item { - when { - filteredContactChats.isNotEmpty() && searchText.value.text.isEmpty() -> { + if (filteredContactChats.isNotEmpty()) { + if (searchText.value.text.isEmpty()) { + item { SectionDividerSpaced() - SectionView(stringResource(MR.strings.contact_list_header_title), headerBottomPadding = DEFAULT_PADDING_HALF) { - filteredContactChats.forEachIndexed { index, chat -> - val nextChatSelected = remember(chat.id, filteredContactChats) { - derivedStateOf { - chatModel.chatId.value != null && filteredContactChats.getOrNull(index + 1)?.id == chatModel.chatId.value - } - } - ContactListNavLinkView(chat, nextChatSelected, showDeletedChatIcon = true) - } - } - Spacer(Modifier.height(DEFAULT_PADDING_HALF)) + SectionView(stringResource(MR.strings.contact_list_header_title), headerBottomPadding = DEFAULT_PADDING_HALF) {} } - filteredContactChats.isNotEmpty() -> { - SectionView { - filteredContactChats.forEachIndexed { index, chat -> - val nextChatSelected = remember(chat.id, filteredContactChats) { - derivedStateOf { - chatModel.chatId.value != null && filteredContactChats.getOrNull(index + 1)?.id == chatModel.chatId.value - } - } - ContactListNavLinkView(chat, nextChatSelected, showDeletedChatIcon = true) - } - } - } - else -> NoFilteredContactsItem() } + itemsIndexed(filteredContactChats) { index, chat -> + val nextChatSelected = remember(chat.id, filteredContactChats) { + derivedStateOf { + chatModel.chatId.value != null && filteredContactChats.getOrNull(index + 1)?.id == chatModel.chatId.value + } + } + ContactListNavLinkView(chat, nextChatSelected, showDeletedChatIcon = true) + } + if (searchText.value.text.isEmpty()) { + item { Spacer(Modifier.height(DEFAULT_PADDING_HALF)) } + } + } else { + item { NoFilteredContactsItem() } } if (appPlatform.isAndroid) { item { @@ -420,35 +410,23 @@ private fun ModalData.NewChatSheetLayout( item { DeletedChatsItem(actionButtonsOriginal) } - item { - when { - filteredContactChats.isNotEmpty() && searchText.value.text.isEmpty() -> { + if (filteredContactChats.isNotEmpty()) { + if (searchText.value.text.isEmpty()) { + item { SectionDividerSpaced() - SectionView(stringResource(MR.strings.contact_list_header_title), headerBottomPadding = DEFAULT_PADDING_HALF) { - filteredContactChats.forEachIndexed { index, chat -> - val nextChatSelected = remember(chat.id, filteredContactChats) { - derivedStateOf { - chatModel.chatId.value != null && filteredContactChats.getOrNull(index + 1)?.id == chatModel.chatId.value - } - } - ContactListNavLinkView(chat, nextChatSelected, showDeletedChatIcon = true) - } - } + SectionView(stringResource(MR.strings.contact_list_header_title), headerBottomPadding = DEFAULT_PADDING_HALF) {} } - filteredContactChats.isNotEmpty() -> { - SectionView { - filteredContactChats.forEachIndexed { index, chat -> - val nextChatSelected = remember(chat.id, filteredContactChats) { - derivedStateOf { - chatModel.chatId.value != null && filteredContactChats.getOrNull(index + 1)?.id == chatModel.chatId.value - } - } - ContactListNavLinkView(chat, nextChatSelected, showDeletedChatIcon = true) - } - } - } - else -> NoFilteredContactsItem() } + itemsIndexed(filteredContactChats) { index, chat -> + val nextChatSelected = remember(chat.id, filteredContactChats) { + derivedStateOf { + chatModel.chatId.value != null && filteredContactChats.getOrNull(index + 1)?.id == chatModel.chatId.value + } + } + ContactListNavLinkView(chat, nextChatSelected, showDeletedChatIcon = true) + } + } else { + item { NoFilteredContactsItem() } } if (appPlatform.isAndroid) { item {