Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InputBar position wrong when MessagesView used in a sheet and keyboard shows up. #1779

Open
jo32 opened this issue Feb 24, 2023 · 4 comments
Labels

Comments

@jo32
Copy link

jo32 commented Feb 24, 2023

Describe the bug
InputBar position wrong when MessagesView used in a sheet and keyboard shows up.

To Reproduce
Steps/code to reproduce the behavior:

edit the file as code provided below:

SwiftUIExampleView.swift

//
//  ChatView.swift
//  ChatExample
//
//  Created by Kino Roy on 2020-07-18.
//  Copyright © 2020 MessageKit. All rights reserved.
//

import MessageKit
import SwiftUI

// MARK: - SwiftUIExampleView

struct SwiftUIExampleView: View {
  // MARK: Internal

  @State var messages: [MessageType] = SampleData.shared.getMessages(count: 20)
@State var show = true
    
  var body: some View {
      Text("Hello")
          .sheet(isPresented: $show) {
              MessagesView(messages: $messages).onAppear {
                self.connectToMessageSocket()
              }.onDisappear {
                self.cleanupSocket()
              }
              .navigationBarTitle("SwiftUI Example", displayMode: .inline)
          }
  }

  // MARK: Private

  private func connectToMessageSocket() {
    MockSocket.shared.connect(with: [SampleData.shared.nathan, SampleData.shared.wu]).onNewMessage { message in
      self.messages.append(message)
    }
  }

  private func cleanupSocket() {
    MockSocket.shared.disconnect()
  }
}

// MARK: - SwiftUIExampleView_Previews

struct SwiftUIExampleView_Previews: PreviewProvider {
  static var previews: some View {
    SwiftUIExampleView()
  }
}

Expected behavior
inputbar should be in correct position.

Screenshots
image

Environment

  • What version of MessageKit are you using?
  • latest
  • What version of iOS are you running on?
  • 16.2
  • What version of Swift are you running on?
  • V5
  • What device(s) are you testing on? Are these simulators?
  • iPhone 14 Pro Max and iPhone 14 Pro on Simulator.
  • Is the issue you're experiencing reproducible in the example app?
  • no
@jo32 jo32 added the bug? label Feb 24, 2023
@kasimok
Copy link

kasimok commented Mar 2, 2023

+1

@thanksloving
Copy link

I have the same problem. It just happened when I use swiftui.

@King0fSpace
Copy link

Same issue. Tried setting the input view's 'messageInputBar' position in 'keyboardWillShow' and it looks great but the 'Send' button is no longer tappable when keyboard is up. Send button works again but keyboard is dismissed. Looked through view hierachy in debug mode but nothing is blocking the Send button when keyboard is up. This one's a head scratcher

@King0fSpace
Copy link

Quick and dirty fix that works on iPhones:

In KeyboardManager.swift:

Inside callbacks[.willShow] change self?.constraints?.bottom?.constant = -keyboardHeight - (additionalBottomSpace?() ?? 0) to self?.constraints?.bottom?.constant = 0

Inside callbacks[.willChangeFrame] change self?.constraints?.bottom?.constant = -keyboardHeight - (additionalBottomSpace?() ?? 0) to self?.constraints?.bottom?.constant = 0

Change var yCoordinateDirectlyAboveKeyboard = -frame.height to var yCoordinateDirectlyAboveKeyboard = 0.0

That should remove the extra gap between the input accessory view and keyboard when the keyboard is presented and being dismissed with a downward gesture. apologies for the bad formatting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants