fix scroll button

This commit is contained in:
ryanzhao 2021-06-04 10:29:03 +10:00
parent 0475274b4d
commit 55786d6f17
1 changed files with 5 additions and 5 deletions

View File

@ -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
}