SystemNotification icon indicating copy to clipboard operation
SystemNotification copied to clipboard

SystemNotification in UIKit app preventing touch events

Open martindufort opened this issue 1 year ago • 6 comments

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 avatar May 27 '24 15:05 martindufort

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)

martindufort avatar May 27 '24 17:05 martindufort

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?

danielsaidi avatar May 28 '24 09:05 danielsaidi

Will try but my first guess is no.

martindufort avatar May 28 '24 18:05 martindufort

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

danielsaidi avatar Jun 07 '24 07:06 danielsaidi

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

martindufort avatar Jun 08 '24 12:06 martindufort

This issue was closed with PR #18.

martindufort avatar Aug 27 '24 13:08 martindufort