ChatSecure-iOS icon indicating copy to clipboard operation
ChatSecure-iOS copied to clipboard

Fix safeAreaInsets in JSQMessagesViewController for iPhone X support

Open chrisballinger opened this issue 8 years ago • 2 comments

For an example, see the below picture where the messageInputBar overlaps the new "home button bar" area.

screen shot 2017-10-31 at 4 41 24 pm

chrisballinger avatar Oct 31 '17 23:10 chrisballinger

For reference: https://github.com/MessageKit/MessageKit/blob/9ff1a122c33231d88a4654e1b11b85e1bb0ccf08/Sources/Controllers/MessagesViewController.swift#L130

    /// Sets the constraints of the `MessagesCollectionView`.
    private func setupConstraints() {
        messagesCollectionView.translatesAutoresizingMaskIntoConstraints = false
        
        let top = messagesCollectionView.topAnchor.constraint(equalTo: view.topAnchor, constant: topLayoutGuide.length)
        let bottom = messagesCollectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
        if #available(iOS 11.0, *) {
            let leading = messagesCollectionView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor)
            let trailing = messagesCollectionView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor)
            NSLayoutConstraint.activate([top, bottom, trailing, leading])
        } else {
            let leading = messagesCollectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor)
            let trailing = messagesCollectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
            NSLayoutConstraint.activate([top, bottom, trailing, leading])
        }
    }

chrisballinger avatar Nov 01 '17 00:11 chrisballinger

The previous solution doesn't seem to work with Objective-C.

I've found a different workaround, here are the steps:

  • Open JSQMessagesViewController.xib
  • Select "Messages Collection View"
  • Select "Size Inspector"
  • Change "Content Insets" to "Never"

JonyMateos avatar Oct 26 '20 21:10 JonyMateos