Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class HeadlessInAppWebView: Disposable {
} else {
view.frame = CGRect(x: 0.0, y: 0.0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
}
if let keyWindow = UIApplication.shared.keyWindow {
// Use the shared extension for getting key window
if let keyWindow = UIApplication.shared.keyWindowCompat {
/// Note: The WKWebView behaves very unreliable when rendering offscreen
/// on a device. This is especially true with JavaScript, which simply
/// won't be executed sometimes.
Expand All @@ -48,7 +49,6 @@ public class HeadlessInAppWebView: Disposable {
}
}
}

public func setSize(size: Size2D) {
if let view = flutterWebView?.view() {
let width = size.width == -1.0 ? UIScreen.main.bounds.width : CGFloat(size.width)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,30 @@
import UIKit

extension UIApplication {

/// Get the key window across all iOS versions
var keyWindowCompat: UIWindow? {
if #available(iOS 13.0, *) {
let windowScene = connectedScenes
.compactMap { $0 as? UIWindowScene }
.first(where: { $0.activationState == .foregroundActive })

if #available(iOS 15.0, *) {
if let keyWindow = windowScene?.keyWindow {
return keyWindow
}
}

return windowScene?.windows.first(where: { $0.isKeyWindow })
?? windowScene?.windows.first
} else {
return windows.first(where: { $0.isKeyWindow })
?? windows.first
}
}

var visibleViewController: UIViewController? {
guard let rootViewController = keyWindow?.rootViewController else {
guard let rootViewController = keyWindowCompat?.rootViewController else {
return nil
}
return getVisibleViewController(rootViewController)
Expand Down