From b2536173a0894041f7f81750952fab756d38cd94 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Thu, 3 Jun 2021 14:38:50 +1000 Subject: [PATCH 1/4] fix conversations never scroll down when a new message comes in --- Session/Conversations/ConversationVC.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index f0aeb67fc..0cd306316 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -334,12 +334,10 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat case .insert: // Perform inserts before updates self.messagesTableView.insertRows(at: [ IndexPath(row: Int(update.newIndex), section: 0) ], with: .fade) - let viewItem = update.viewItem - if viewItem?.interaction is TSOutgoingMessage { - shouldScrollToBottom = true - } + shouldScrollToBottom = true case .update: self.messagesTableView.reloadRows(at: [ IndexPath(row: Int(update.oldIndex), section: 0) ], with: .fade) + shouldScrollToBottom = true default: preconditionFailure() } } From 0475274b4d75713fb9121751bbdda6f7da3016ff Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Thu, 3 Jun 2021 15:16:17 +1000 Subject: [PATCH 2/4] only scroll down when we are already at the bottom --- Session/Conversations/ConversationVC.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index 0cd306316..134e4a3cf 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -334,10 +334,10 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat case .insert: // Perform inserts before updates self.messagesTableView.insertRows(at: [ IndexPath(row: Int(update.newIndex), section: 0) ], with: .fade) - shouldScrollToBottom = true + shouldScrollToBottom = (self.scrollButton.alpha == 0) case .update: self.messagesTableView.reloadRows(at: [ IndexPath(row: Int(update.oldIndex), section: 0) ], with: .fade) - shouldScrollToBottom = true + shouldScrollToBottom = (self.scrollButton.alpha == 0) default: preconditionFailure() } } From 55786d6f17cf264841d8900549ce9a8e9e343903 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 4 Jun 2021 10:29:03 +1000 Subject: [PATCH 3/4] fix scroll button --- Session/Conversations/ConversationVC.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index 134e4a3cf..f4bee31f6 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -8,7 +8,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat let thread: TSThread let focusedMessageID: String? // This isn't actually used ATM var unreadViewItems: [ConversationViewItem] = [] - var didConstrainScrollButton = false // Part of a workaround to get the scroll button to show up in the right place + var scrollButtonConstraint: NSLayoutConstraint? // Search var isShowingSearchUI = false var lastSearchedText: String? @@ -170,6 +170,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat messagesTableView.pin(to: view) view.addSubview(scrollButton) scrollButton.pin(.right, to: .right, of: view, withInset: -16) + scrollButtonConstraint = scrollButton.pin(.bottom, to: .bottom, of: view, withInset: -16) // Unread count view view.addSubview(unreadCountView) unreadCountView.addSubview(unreadCountLabel) @@ -295,10 +296,8 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat baselineKeyboardHeight = newHeight self.messagesTableView.keyboardHeight = newHeight } - if !didConstrainScrollButton { - // HACK: Part of a workaround to get the scroll button to show up in the right place - scrollButton.pin(.bottom, to: .bottom, of: view, withInset: -(newHeight + 16)) // + 16 to match the bottom inset of the table view - didConstrainScrollButton = true + if (newHeight >= self.messagesTableView.keyboardHeight) { + scrollButtonConstraint?.constant = -(newHeight + 16) } let newContentOffsetY = max(self.messagesTableView.contentOffset.y + min(lastPageTop, 0) + newHeight - self.messagesTableView.keyboardHeight, 0.0) self.messagesTableView.contentOffset.y = newContentOffsetY @@ -309,6 +308,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat @objc func handleKeyboardWillHideNotification(_ notification: Notification) { self.messagesTableView.contentOffset.y -= (self.messagesTableView.keyboardHeight - self.baselineKeyboardHeight) self.messagesTableView.keyboardHeight = self.baselineKeyboardHeight + scrollButtonConstraint?.constant = -(self.baselineKeyboardHeight + 16) self.scrollButton.alpha = self.getScrollButtonOpacity() self.unreadCountView.alpha = self.scrollButton.alpha } From 4c99b9ed05ce0f4887e258a07fe5b56628778187 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 4 Jun 2021 15:30:24 +1000 Subject: [PATCH 4/4] make shouldScrollToBottom based on the table view's content offset. --- Session/Conversations/ConversationVC.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index f4bee31f6..c10938997 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -334,10 +334,10 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat case .insert: // Perform inserts before updates self.messagesTableView.insertRows(at: [ IndexPath(row: Int(update.newIndex), section: 0) ], with: .fade) - shouldScrollToBottom = (self.scrollButton.alpha == 0) + shouldScrollToBottom = Int(self.lastPageTop - self.messagesTableView.contentOffset.y) <= 0 case .update: self.messagesTableView.reloadRows(at: [ IndexPath(row: Int(update.oldIndex), section: 0) ], with: .fade) - shouldScrollToBottom = (self.scrollButton.alpha == 0) + shouldScrollToBottom = Int(self.lastPageTop - self.messagesTableView.contentOffset.y) <= 0 default: preconditionFailure() } }