placeholders looking good and sync page sizes with android

This commit is contained in:
Diogo
2024-11-06 15:25:10 +00:00
parent 9b6365ca88
commit 9155a2f02a
4 changed files with 11 additions and 9 deletions
+2 -2
View File
@@ -318,8 +318,8 @@ private func apiChatsResponse(_ r: ChatResponse) throws -> [ChatData] {
throw r
}
let loadItemsPerPage = 50
let preloadItem = 8
let loadItemsPerPage = 100
let preloadItem = 25
let idealChatListSize = 500
func apiGetChat(type: ChatType, id: Int64, search: String = "") async throws -> (Chat, Int?) {
@@ -62,8 +62,6 @@ struct ChatItemView: View {
CIVoiceView(chat: chat, chatItem: ci, recordingFile: ci.file, duration: duration, allowMenu: $allowMenu)
} else if ci.content.msgContent == nil {
ChatItemContentView(chat: chat, chatItem: chatItem, msgContentView: { Text(ci.text) }) // msgContent is unreachable branch in this case
} else if ci.isPlaceholder {
EmptyView()
} else {
framedItemView()
}
+5 -1
View File
@@ -220,7 +220,11 @@ struct ReverseList<Content: View>: UIViewControllerRepresentable {
var snapshot = NSDiffableDataSourceSnapshot<Section, ChatItem>()
if let gap = gap {
var itemsCopy = items
let blanks = (0..<gap.size).map { index in ChatItem.placeholder(index + 1) }
let blanks = (0..<gap.size).map { index in
// Using existing text instead of random rumble or empty text does make long scroll look natural.
let sourceItem = items[index % items.count]
return ChatItem.placeholder(idx: index + 1, text: sourceItem.text, chatDir: sourceItem.chatDir)
}
itemsCopy.insert(contentsOf: blanks, at: gap.index)
renderedItems = itemsCopy
} else {
+4 -4
View File
@@ -2665,13 +2665,13 @@ public struct ChatItem: Identifiable, Decodable, Hashable {
return item
}
public static func placeholder(_ idx: Int) -> ChatItem {
public static func placeholder(idx: Int, text: String, chatDir: CIDirection) -> ChatItem {
var item = ChatItem(
chatDir: CIDirection.directSnd,
chatDir: chatDir,
meta: CIMeta(
itemId: Int64(idx * -10),
itemTs: .now,
itemText: "",
itemText: text,
itemStatus: .rcvRead,
createdAt: .now,
updatedAt: .now,
@@ -2681,7 +2681,7 @@ public struct ChatItem: Identifiable, Decodable, Hashable {
deletable: false,
editable: false
),
content: .sndMsgContent(msgContent: .text("")),
content: .sndMsgContent(msgContent: .text(text)),
quotedItem: nil,
file: nil
)