danielsaidi / SystemNotification

SystemNotification is a Swift SDK that helps you mimic the native iOS system notification in SwiftUI.
MIT License
425 stars 14 forks source link

SystemNotification in UIKit app preventing touch events #16

Open martindufort opened 1 month ago

martindufort commented 1 month ago

I'm trying to integrate SystemNotification to a UIKit-only app using addAsOverlay. Here's the setup code:

        // Setup system notification
        self.systemNotificationContext = SystemNotificationContext()
        self.systemNotification = SystemNotificationUIKitOverlay(context: self.systemNotificationContext)
        self.systemNotification.addAsOverlay(to: self.view)

In our app, we are showing a modal pageSheet view where users can enter data and when completed a new item added notification would be shown.

However as soon as I add the SystemNotification as an overlay, all touch events are not reaching the actual buttons underneath the overlay.

Removing the setup code above restores the touch events.
Anything I should look for?

martindufort commented 1 month ago

OK, so after some reseeach, looks like the UIHostingViewController is capturing all touch events from going underneath the overlay.

I've added this code which seems to resolve my issue. Not sure what the impact is on events handled by the SystemNotification however

SystemNotificationUIKitOverlay.swift:36

    func addAsOverlay(to view: UIView) {
        let overlay = UIHostingController(rootView: self)
    // Disable user interaction for overlay
        overlay.view.isUserInteractionEnabled = false
        view.addSubview(overlay.view)
danielsaidi commented 1 month ago

Hi @martindufort

Oh, I haven't looked at the UIKit support stuff for a long time.

Does it work to swipe away the notification if you add that line?

martindufort commented 1 month ago

Will try but my first guess is no.

danielsaidi commented 4 weeks ago

@martindufort Since I rarely touch UIKit these days, feel free to make any adjustments that work for you and I'll happily merge it 😀

martindufort commented 3 weeks ago

Will do and add a version for AppKit as well. 😉