Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions Sources/SnapshotTesting/Common/View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,14 @@

private func getKeyWindow() -> UIWindow? {
var window: UIWindow?
if #available(iOS 13.0, *) {
if #available(iOS 13.0, *),
let keyWindow = UIApplication.sharedIfAvailable?.connectedScenes
.compactMap({ $0 as? UIWindowScene })
.flatMap({ $0.windows })
.first(where: { $0.isKeyWindow })
{
window = keyWindow
} else if #available(iOS 13.0, *) {
window = UIApplication.sharedIfAvailable?.windows.first { $0.isKeyWindow }
} else {
window = UIApplication.sharedIfAvailable?.keyWindow
Expand All @@ -1090,7 +1097,19 @@
init(config: ViewImageConfig, viewController: UIViewController) {
let size = config.size ?? viewController.view.bounds.size
self.config = config
super.init(frame: .init(origin: .zero, size: size))

// Attach to current window scene to ensure consistent safe area behavior
if #available(iOS 13.0, *),
let scene = UIApplication.sharedIfAvailable?.connectedScenes.first(where: {
$0.activationState == .foregroundActive || $0.activationState == .foregroundInactive
}),
let windowScene = scene as? UIWindowScene
{
super.init(windowScene: windowScene)
self.frame = .init(origin: .zero, size: size)
} else {
super.init(frame: .init(origin: .zero, size: size))
}

// NB: Safe area renders inaccurately for UI{Navigation,TabBar}Controller.
// Fixes welcome!
Expand Down