Fix alerts presented by the user indicator controller not being inter… (#2056)

* Fix alerts presented by the user indicator controller not being interactive

* Add back attribution
This commit is contained in:
Stefan Ceriu
2023-11-10 12:57:19 +02:00
committed by GitHub
parent 3f8c246be2
commit fc14364016
2 changed files with 14 additions and 6 deletions

View File

@@ -25,6 +25,7 @@ protocol WindowManagerDelegate: AnyObject {
@MainActor
/// A window manager that supports switching between a main app window with an overlay and
/// an alternate window to switch contexts whilst also preserving the main view hierarchy.
/// Heavily inspired by https://www.fivestars.blog/articles/swiftui-windows/
class WindowManager {
weak var delegate: WindowManagerDelegate?
@@ -40,13 +41,9 @@ class WindowManager {
mainWindow = windowScene.keyWindow
mainWindow.tintColor = .compound.textActionPrimary
overlayWindow = UIWindow(windowScene: windowScene)
overlayWindow = PassthroughWindow(windowScene: windowScene)
overlayWindow.tintColor = .compound.textActionPrimary
overlayWindow.backgroundColor = .clear
// We don't support user interaction on our indicators so disable interaction, to pass
// touches through to the main window. If this changes, there's another solution here:
// https://www.fivestars.blog/articles/swiftui-windows/
overlayWindow.isUserInteractionEnabled = false
overlayWindow.isHidden = false
alternateWindow = UIWindow(windowScene: windowScene)
@@ -74,3 +71,14 @@ class WindowManager {
mainWindow.endEditing(true)
}
}
private class PassthroughWindow: UIWindow {
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
guard let hitView = super.hitTest(point, with: event) else {
return nil
}
// If the returned view is the `UIHostingController`'s view, ignore.
return rootViewController?.view == hitView ? nil : hitView
}
}

View File

@@ -1,4 +1,4 @@
// Generated using Sourcery 2.1.1 https://github.com/krzysztofzablocki/Sourcery
// Generated using Sourcery 2.1.2 https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
// swiftlint:disable all