Messagekit: [Example] Subview Example - messageInputBar not following keyboard when dragging down

Created on 30 Sep 2020  路  4Comments  路  Source: MessageKit/MessageKit

Describe the bug
When dragging keyboard down to dismiss messageInputBar is staying fixed until keyboardWillChangeFrame notification is sent

To Reproduce
as above - Example -> Subview Example -> drag keyboard down

Expected behavior
View follows keyboard

Screenshots
IMG_2337

Environment

  • What version of MessageKit are you using? 3.4.1
  • What version of iOS are you running on? 14.0
  • What version of Swift are you running on? 5
  • What device(s) are you testing on? Are these simulators? 11 Pro Max
  • Is the issue you're experiencing reproducible in the example app? Yes
bug? stale

Most helpful comment

MessageKit subview example is not correct, because there is a one missing line.
if you want to interactively dismiss the keyboard, you need to bind the keyboard manager to the message collection view, as shown below.

import Foundation
import UIKit
import InputBarAccessoryView

final class MessageSubviewViewController: BasicExampleViewController {

    private let keyboardManager = KeyboardManager()
    private let subviewInputBar = InputBarAccessoryView()

    // MARK: - View Life Cycle

    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(subviewInputBar)

        // Binding the inputBar will set the needed callback actions to position the inputBar on top of the keyboard
        keyboardManager.bind(inputAccessoryView: subviewInputBar)

        // Binding to the messagesCollectionView will enable interactive dismissal
        keyboardManager.bind(to: messagesCollectionView)
    }
    override func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String) {
        processInputBar(subviewInputBar)
    }
}

All 4 comments

Message for PPL googling in the future:

Example project for InputBarAccessoryView also has "Subview" examples

I had to modify it slightly and it's working like a charm:

KeyboardManager.swift

    callbacks[.willChangeFrame] = { [weak self] (notification) in
        let keyboardHeight = notification.endFrame.height
        guard
            self?.isKeyboardHidden == false,
            notification.isForCurrentApp else { return }

        if keyboardHeight == 69 { return } // add this line

        UIView.performWithoutAnimation { // change whatever was in this line to this 
            self?.constraints?.bottom?.constant = -keyboardHeight
            self?.inputAccessoryView?.superview?.layoutIfNeeded()
        }
    }

Fix is only for InputBarAccessoryView Example project - it has to be ported to MessageKit I might submit a pull request once I do that. Anyways should be pretty straight forward.

This issue has been marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This issue has been auto-closed because there hasn't been any activity for at least 21 days. However, we really appreciate your contribution, so thank you for that! 馃檹 Also, feel free to open a new issue if you still experience this problem 馃憤.

MessageKit subview example is not correct, because there is a one missing line.
if you want to interactively dismiss the keyboard, you need to bind the keyboard manager to the message collection view, as shown below.

import Foundation
import UIKit
import InputBarAccessoryView

final class MessageSubviewViewController: BasicExampleViewController {

    private let keyboardManager = KeyboardManager()
    private let subviewInputBar = InputBarAccessoryView()

    // MARK: - View Life Cycle

    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(subviewInputBar)

        // Binding the inputBar will set the needed callback actions to position the inputBar on top of the keyboard
        keyboardManager.bind(inputAccessoryView: subviewInputBar)

        // Binding to the messagesCollectionView will enable interactive dismissal
        keyboardManager.bind(to: messagesCollectionView)
    }
    override func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String) {
        processInputBar(subviewInputBar)
    }
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ChandraPrakashJangid picture ChandraPrakashJangid  路  3Comments

omaralbeik picture omaralbeik  路  4Comments

adri4silva picture adri4silva  路  4Comments

mlequeux picture mlequeux  路  3Comments

NiklasWilson picture NiklasWilson  路  4Comments