fix contact list to be lazy

This commit is contained in:
Evgeny @ SimpleX Chat
2026-05-19 07:25:10 +00:00
parent 6a72def713
commit b6f37f06b3
2 changed files with 33 additions and 54 deletions
@@ -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
@@ -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 {