SwiftKickMobile / SwiftMessages

A very flexible message bar for UIKit and SwiftUI.
MIT License
7.24k stars 742 forks source link

UIAlertController pops up but SwiftMessage layer absorbs all touches (only on v8.0.0) #401

Closed andrewpluu closed 3 years ago

andrewpluu commented 3 years ago

I use SwiftMessages to pop up a custom UIView that has a couple of buttons. One of the buttons (delete) pops up a UIAlertController that confirms whether or not the item should be deleted.

In v 7.0.1 the UIAlertController works as expected, and the buttons on my UIAlertController alert work, allowing me to delete my item.

In 8.0.0 however, the SwiftMessage view maintains control of touch input and therefore the UIAlertController buttons cannot be pressed, even though the UIAlertController is showing at the forefront.

I tried to change the presentation context and created a separate SwiftMessages instance in an attempt to fix the problem but unfortunately, nothing worked other than downgrading the library.

I downgraded back to 7.0.1 and the functionality works as intended again, without changing any lines of my code.

Is this a bug in 8.0.0?

wtmoose commented 3 years ago

Can you attach a screenshot and show some code?

andrewpluu commented 3 years ago

Code in the view controller to pop up the SwiftMessage:

    let customView = CustomView()
    var config = SwiftMessages.defaultConfig
    config.interactiveHide = true
    config.dimMode = .blur(style: .regular, alpha: 0.8, interactive: true)
    config.duration = .forever
    config.presentationStyle = .center
    SwiftMessages.show(config: config, view: customView)

Code in my CustomView:

@objc func buttonPressed() {
        let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)

        alert.addAction(UIAlertAction(title: "Overwrite", style: .destructive, handler: { action in
            SwiftMessages.hideAll()
        }))
        alert.addAction(UIAlertAction(title: "Rename", style: .cancel, handler: nil))
        self.window?.rootViewController?.present(alert, animated: true)
    }

Screenshot: The buttons on the UIAlertViewController don't work, but i can swipe away the SwiftMessage.

Screen Shot 2020-07-22 at 2 17 55 PM
wtmoose commented 3 years ago

This was a side effect of the original fix for #360. I refined the hit test logic and it no longer breaks your use case. Can you give the head of master a try and let me know?

andrewpluu commented 3 years ago

Works perfectly, appreciate the super-fast fix!