diff --git a/CHANGELOG.md b/CHANGELOG.md index ae5824612..b0a7f3082 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ See [MIGRATION_GUIDE.md](https://github.com/MessageKit/MessageKit/blob/main/Docu MessageSizeCalculator.messageContainerSize(for message: MessageType, at indexPath: IndexPath) -> CGSize ``` - Updated InputBarAccessoryView to v6.1.0 [#1716](https://github.com/MessageKit/MessageKit/pull/1716) by [@martinpucik](https://github.com/martinpucik) +- Observe inputBar frame change to update collectionView bottom inset instead of keyboard show/hide notifications [#1726](https://github.com/MessageKit/MessageKit/pull/1726) by [@martinpucik](https://github.com/martinpucik) ### Fixed diff --git a/Sources/Controllers/MessagesViewController+Keyboard.swift b/Sources/Controllers/MessagesViewController+Keyboard.swift index dc7ce43b2..52150f128 100644 --- a/Sources/Controllers/MessagesViewController+Keyboard.swift +++ b/Sources/Controllers/MessagesViewController+Keyboard.swift @@ -35,10 +35,12 @@ internal extension MessagesViewController { keyboardManager.bind(inputAccessoryView: inputContainerView) keyboardManager.bind(to: messagesCollectionView) - /// Observe didBeginEditing to scroll down the content + /// Observe didBeginEditing to scroll content to last item if necessary NotificationCenter.default .publisher(for: UITextView.textDidBeginEditingNotification) .subscribe(on: DispatchQueue.global()) + /// Wait for inputBar frame change animation to end + .delay(for: .milliseconds(200), scheduler: DispatchQueue.main) .receive(on: DispatchQueue.main) .sink { [weak self] notification in self?.handleTextViewDidBeginEditing(notification) @@ -65,19 +67,10 @@ internal extension MessagesViewController { } .store(in: &disposeBag) - Publishers.MergeMany( - NotificationCenter.default.publisher(for: UIResponder.keyboardWillHideNotification), - NotificationCenter.default.publisher(for: UIResponder.keyboardWillShowNotification) - ) - .subscribe(on: DispatchQueue.global()) - .receive(on: DispatchQueue.main) - .sink(receiveValue: { [weak self] _ in - self?.updateMessageCollectionViewBottomInset() - }) - .store(in: &disposeBag) - - /// Observe frame change of the input bar container to not cover collectioView with inputBar + /// Observe frame change of the input bar container to update collectioView bottom inset inputContainerView.publisher(for: \.center) + .receive(on: DispatchQueue.main) + .removeDuplicates() .sink(receiveValue: { [weak self] _ in self?.updateMessageCollectionViewBottomInset() }) @@ -88,8 +81,6 @@ internal extension MessagesViewController { /// Updates bottom messagesCollectionView inset based on the position of inputContainerView func updateMessageCollectionViewBottomInset() { - /// This is important to skip notifications from child modal controllers in iOS >= 13.0 - guard self.presentedViewController == nil else { return } let collectionViewHeight = messagesCollectionView.frame.height let newBottomInset = collectionViewHeight - (inputContainerView.frame.minY - additionalBottomInset) - automaticallyAddedBottomInset let normalizedNewBottomInset = max(0, newBottomInset)