diff --git a/apps/ios/Shared/Model/ChatModel.swift b/apps/ios/Shared/Model/ChatModel.swift index 4b391b727e..62d0051aa1 100644 --- a/apps/ios/Shared/Model/ChatModel.swift +++ b/apps/ios/Shared/Model/ChatModel.swift @@ -50,9 +50,6 @@ class ItemsModel: ObservableObject { var reversedChatItems: [ChatItem] = [] { willSet { publisher.send() } } - var itemAdded = false { - willSet { publisher.send() } - } // Publishes directly to `objectWillChange` publisher, // this will cause reversedChatItems to be rendered without throttling @@ -456,7 +453,6 @@ final class ChatModel: ObservableObject { ci.meta.itemStatus = status } im.reversedChatItems.insert(ci, at: hasLiveDummy ? 1 : 0) - im.itemAdded = true } return true } @@ -551,7 +547,6 @@ final class ChatModel: ObservableObject { let cItem = ChatItem.liveDummy(chatInfo.chatType) withAnimation { im.reversedChatItems.insert(cItem, at: 0) - im.itemAdded = true } return cItem } @@ -915,7 +910,6 @@ final class ChatModel: ObservableObject { // TODO these thresholds account for the fact that items are still "visible" while // covered by compose area, they should be replaced with the actual height in pixels below the screen. isNearBottom: totalBelow < 15, - isReallyNearBottom: totalBelow < 2, unreadBelow: unreadBelow ) } @@ -942,7 +936,6 @@ struct NTFContactRequest { struct UnreadChatItemCounts: Equatable { var isNearBottom: Bool - var isReallyNearBottom: Bool var unreadBelow: Int } diff --git a/apps/ios/Shared/Views/Chat/ChatView.swift b/apps/ios/Shared/Views/Chat/ChatView.swift index 7f07b94427..a22a56722a 100644 --- a/apps/ios/Shared/Views/Chat/ChatView.swift +++ b/apps/ios/Shared/Views/Chat/ChatView.swift @@ -472,7 +472,6 @@ struct ChatView: View { init() { unreadChatItemCounts = UnreadChatItemCounts( isNearBottom: true, - isReallyNearBottom: true, unreadBelow: 0 ) events diff --git a/apps/ios/Shared/Views/Chat/ReverseList.swift b/apps/ios/Shared/Views/Chat/ReverseList.swift index 7758622c8b..33b1265e4e 100644 --- a/apps/ios/Shared/Views/Chat/ReverseList.swift +++ b/apps/ios/Shared/Views/Chat/ReverseList.swift @@ -163,17 +163,31 @@ struct ReverseList: UIV animated: animated ) } else { - tableView.setContentOffset( - CGPoint(x: .zero, y: -InvertedTableView.inset), - animated: animated - ) + scrollToBottom(animated: animated) } Task { representer.scrollState = .atDestination } } - var itemId: Item.ID? - var retainedItems: [Item]? - var updateInProgress = false + private func scrollToBottom(animated: Bool) { + tableView.setContentOffset( + CGPoint(x: .zero, y: -InvertedTableView.inset), + animated: animated + ) + } + + private var isNearBottom: Bool { + let adjustedOffset = tableView.contentOffset.y + InvertedTableView.inset + return adjustedOffset > 0 && adjustedOffset < 500 + } + + private var isFarFromBottom: Bool { + let adjustedOffset = tableView.contentOffset.y + InvertedTableView.inset + return adjustedOffset > 1000 + } + + private var itemId: Item.ID? + private var retainedItems: [Item]? + private var updateInProgress = false func update(items: [Item]) { if updateInProgress { @@ -190,6 +204,7 @@ struct ReverseList: UIV // Added items animated by sliding from bottom (.top) self._update(items: items, animated: true) { self.updateInProgress = false + if self.isNearBottom { self.scrollToBottom(animated: true) } // Process update, which might have arrived before completion if let items = self.retainedItems { self.update(items: items) } }