diff --git a/ElementX/Sources/Application/Windowing/WindowManager.swift b/ElementX/Sources/Application/Windowing/WindowManager.swift index db75d69ac..7eb77e462 100644 --- a/ElementX/Sources/Application/Windowing/WindowManager.swift +++ b/ElementX/Sources/Application/Windowing/WindowManager.swift @@ -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 + } +} diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index 5983abca2..9a62c6ce7 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -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