MessageKit- SwiftUI Input Bar Placement on top of screen

177 views Asked by At

My application is in SwiftUI. I am implementing Message Kit as a chat feature, however, the input bar placement for the SwiftUI example in MessageKit awkwardly snaps to the top of the screen when the keyboard appears.

Current SwiftUI Behavior: Current SwiftUI Behavior

Expected Behavior(UIKit): Expected Behavior(with UIKit)

How can I fix the Inputbar placement for SwiftUI implementation or implement the expected Behavior within a SwiftUI app? Thanks

My code:

 func makeUIViewController(context: Context) -> MessagesViewController {
    let messagesVC = MessageSwiftUIVC()

    messagesVC.messagesCollectionView.messagesDisplayDelegate = context.coordinator
    messagesVC.messagesCollectionView.messagesLayoutDelegate = context.coordinator
    messagesVC.messagesCollectionView.messagesDataSource = context.coordinator
    messagesVC.scrollsToLastItemOnKeyboardBeginsEditing = true // default false
    messagesVC.maintainPositionOnInputBarHeightChanged = true // default false
    messagesVC.showMessageTimestampOnSwipeLeft = true // default false

    return messagesVC
  }


extension MessagesView.Coordinator: InputBarAccessoryViewDelegate {
    func inputBar(_ inputBar: InputBarAccessoryView, didPressSendButtonWith text: String) {
      let message = Message(sender: currentUser, messageId: "1", sentDate: Date(), kind: .text("Hello, World!"))

    messages.wrappedValue.append(message)
    inputBar.inputTextView.text = ""

  }
}
0

There are 0 answers