Merge branch 'AlexT84-fix_ios_multiple_flutter_presenting_error'

This commit is contained in:
Lorenzo Pichilli 2023-11-10 11:44:20 +01:00
commit 614374c6c9
3 changed files with 39 additions and 14 deletions

View File

@ -105,23 +105,17 @@ public class InAppBrowserManager: ChannelDelegate {
navController.pushViewController(webViewController, animated: false)
webViewController.prepareNavigationControllerBeforeViewWillAppear()
let frame: CGRect = UIScreen.main.bounds
let tmpWindow = UIWindow(frame: frame)
let tmpController = UIViewController()
let baseWindowLevel = UIApplication.shared.keyWindow?.windowLevel
tmpWindow.rootViewController = tmpController
tmpWindow.windowLevel = UIWindow.Level(baseWindowLevel!.rawValue + 1.0)
tmpWindow.makeKeyAndVisible()
navController.tmpWindow = tmpWindow
var animated = true
if let browserSettings = webViewController.browserSettings, browserSettings.hidden {
tmpWindow.isHidden = true
UIApplication.shared.delegate?.window??.makeKeyAndVisible()
animated = false
}
tmpWindow.rootViewController!.present(navController, animated: animated, completion: nil)
guard let visibleViewController = UIApplication.shared.visibleViewController else {
assertionFailure("Failure init the visibleViewController!")
return
}
visibleViewController.present(navController, animated: animated)
}
public func openWithSystemBrowser(url: String, result: @escaping FlutterResult) {

View File

@ -90,7 +90,7 @@ public class ChromeSafariBrowserManager: ChannelDelegate {
if #available(iOS 9.0, *), let plugin = plugin {
if let flutterViewController = UIApplication.shared.delegate?.window.unsafelyUnwrapped?.rootViewController {
if let flutterViewController = UIApplication.shared.visibleViewController {
// flutterViewController could be casted to FlutterViewController if needed
let safariSettings = SafariBrowserSettings()

View File

@ -0,0 +1,31 @@
//
// VisibleViewController.swift
// flutter_inappwebview
//
// Created by Alexandru Terente on 02.08.2023.
//
import UIKit
extension UIApplication {
var visibleViewController: UIViewController? {
guard let rootViewController = keyWindow?.rootViewController else {
return nil
}
return getVisibleViewController(rootViewController)
}
private func getVisibleViewController(_ rootViewController: UIViewController) -> UIViewController? {
if let presentedViewController = rootViewController.presentedViewController {
return getVisibleViewController(presentedViewController)
}
if let navigationController = rootViewController as? UINavigationController {
return navigationController.visibleViewController
}
if let tabBarController = rootViewController as? UITabBarController {
return tabBarController.selectedViewController
}
return rootViewController
}
}