Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions MessageViewController/MessageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ open class MessageViewController: UIViewController, MessageAutocompleteControlle
internal var scrollView: UIScrollView?
internal var keyboardHeight: CGFloat = 0
internal var isMessageViewHidden = false
internal var scrollsToBottomOnKeyboardReveal = false

internal func commonInit() {
messageView.delegate = self
Expand Down Expand Up @@ -182,16 +183,21 @@ open class MessageViewController: UIViewController, MessageAutocompleteControlle

let scrollViewHeight = scrollView.bounds.height
let contentHeight = scrollView.contentSize.height
let inset = scrollView.util_adjustedContentInset
let topInset = scrollView.util_adjustedContentInset.top
let bottomSafeInset = self.view.util_safeAreaInsets.bottom

let newOffset = max(
var newOffset = max(
min(
contentHeight - scrollViewHeight + inset.bottom,
contentHeight - scrollViewHeight,
contentOffset.y + self.keyboardHeight - previousKeyboardHeight - bottomSafeInset
),
-inset.top
-topInset
)

if self.scrollsToBottomOnKeyboardReveal && contentHeight > scrollViewHeight {
newOffset = contentHeight - scrollViewHeight
}

scrollView.contentOffset = CGPoint(x: contentOffset.x, y: newOffset)
}
}
Expand Down