From 55786d6f17cf264841d8900549ce9a8e9e343903 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 4 Jun 2021 10:29:03 +1000 Subject: [PATCH] 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 }