Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions Sources/IONCameraLib/Extensions/UIApplication+Window.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import UIKit

extension UIApplication {
/// The application's main window.
static var firstKeyWindowForConnectedScenes: UIWindow? {
UIApplication
.shared
.connectedScenes
.flatMap { ($0 as? UIWindowScene)?.windows ?? [] }
.last { $0.isKeyWindow }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct IONCAMRImageEditorView: View {
.padding()
}
.onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in
guard isPortrait != UIApplication.shared.windows.first?.windowScene?.interfaceOrientation.isPortrait else { return }
guard isPortrait != UIApplication.firstKeyWindowForConnectedScenes?.windowScene?.interfaceOrientation.isPortrait else { return }
isPortrait.toggle()
croppingOffset = .init(width: 0.0, height: 0.0)
croppingWidthMagnification = 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ final class IONCAMREditorBehaviour: NSObject, IONCAMREditorDelegate {

func editPicture(_ image: UIImage, _ handler: @escaping (UIViewController) -> Void) {
DispatchQueue.main.async {
let isPortrait = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation.isPortrait ?? false
let isPortrait = UIApplication.firstKeyWindowForConnectedScenes?.windowScene?.interfaceOrientation.isPortrait ?? false
let imageEditorView = IONCAMRImageEditorView(delegate: self, image: image, isPortrait: isPortrait)
let viewController = UIHostingController(rootView: imageEditorView)
viewController.modalPresentationStyle = .fullScreen
Expand Down
Loading