nathantannar4 / InputBarAccessoryView

A simple and easily customizable InputAccessoryView for making powerful input bars with autocomplete and attachments
MIT License
1.15k stars 229 forks source link

InputBarAccessoryView suddenly shows up where it shouldn't after using the power button or taking a screenshot #219

Closed Janneman84 closed 1 year ago

Janneman84 commented 2 years ago

I'm using MessageKit. When my chat VC presents a VC as a pagesheet the InputBarAccessoryView goes away, which is good. However if you then power off the device then turn it back on the InputBarAccessoryView is suddenly on screen. Alternatively, when you take a screenshot and then touch the thumbnail in the corner the InputBarAccessoryView shows up too.

You can easily recreate this yourself. I added a little bit of code to the MessageKit example app. Add the following to ChatViewController.swift's viewDidLoad():

DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
    let vc = UIViewController.init()
    vc.view.backgroundColor = .red
    vc.modalPresentationStyle = .pageSheet //or use .formSheet, .overFullScreen, .overCurrentContext
    self.present(vc, animated: true)
}

All it does is showing a plain red VC shortly after the chat is on screen.

Then:

Notice the issue only occurs if the text field is activated before presenting the VC (step 3)

ezgif com-gif-maker

fukemy commented 2 years ago

did u check with real device?

Janneman84 commented 2 years ago

Yes it occurs on a real device just as well. As I said, it works in simulator too.

Also the technique I described in the last bullet only works on a real device.

Janneman84 commented 2 years ago

Would somebody like to give this a try? The issue occurs also in the example app of this repo. To trigger it add the following to READMEPreviewViewController.swift:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    inputBar.inputTextView.becomeFirstResponder()
    DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
        let vc = UIViewController.init()
        vc.view.backgroundColor = .red
        self.present(vc, animated: true)
    }
}

Then start the app and pick README Preview (top one). You'll see the keyboard pop up and then a red VC pops up as a page sheet. You'll see that the InputAccessoryView is not visible now. Now turn off the device with the power button, then turn it back on and unlock the device. You'll see that the InputAccessoryView is now visible on top of the red VC, which is wrong.

fukemy commented 2 years ago

Hi, did u tried to close keyboard before present new VC?

Janneman84 commented 2 years ago

Closing the keyboard first prevents this issue yes, that's how I avoid it now.

But it's not ideal so it'd be nice if this issue would be addressed.

fukemy commented 2 years ago

it's seem the owner avoid your problem, i have same problem, all the time open newVC, or sheet,... i always check if keyboard isFirstResponder then dismiss it before do other action

Janneman84 commented 2 years ago

Most users of this package are not aware of this issue and don't have the habit you have. They all potentially end up with users facing this issue, literary getting stuck in apps in some cases. I was fortunate enough to find out about it myself so I could deal with it.

Just that there is a way to prevent the issue doesn't take away the fact that this still is a bug.

nathantannar4 commented 1 year ago

InputBarAccessoryView doesn't observe view controller presentation/dismissal. Its appearance on screen is purely based on UIKit's handling for a UIViewController's inputAccessoryView. This is dependent on the UIViewController being the "first responder".

This issue could potentially be an enhancement in MessageKit, since the MessagesViewController would be able to auto resign first responder.