feat: extract visibleViewController in UIApplication extension and use it
This commit is contained in:
parent
82c96a957f
commit
3f91faf859
|
@ -98,27 +98,6 @@ public class InAppBrowserManager: ChannelDelegate {
|
||||||
presentViewController(webViewController: webViewController)
|
presentViewController(webViewController: webViewController)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private func visibleViewController() -> UIViewController? {
|
|
||||||
guard let rootViewController = UIApplication.shared.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
|
|
||||||
}
|
|
||||||
|
|
||||||
public func presentViewController(webViewController: InAppBrowserWebViewController) {
|
public func presentViewController(webViewController: InAppBrowserWebViewController) {
|
||||||
let storyboard = UIStoryboard(name: InAppBrowserManager.WEBVIEW_STORYBOARD, bundle: Bundle(for: InAppWebViewFlutterPlugin.self))
|
let storyboard = UIStoryboard(name: InAppBrowserManager.WEBVIEW_STORYBOARD, bundle: Bundle(for: InAppWebViewFlutterPlugin.self))
|
||||||
let navController = storyboard.instantiateViewController(withIdentifier: InAppBrowserManager.NAV_STORYBOARD_CONTROLLER_ID) as! InAppBrowserNavigationController
|
let navController = storyboard.instantiateViewController(withIdentifier: InAppBrowserManager.NAV_STORYBOARD_CONTROLLER_ID) as! InAppBrowserNavigationController
|
||||||
|
@ -131,7 +110,7 @@ public class InAppBrowserManager: ChannelDelegate {
|
||||||
animated = false
|
animated = false
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let visibleViewController = visibleViewController() else {
|
guard let visibleViewController = UIApplication.shared.visibleViewController else {
|
||||||
assertionFailure("Failure inet the visibleViewController!")
|
assertionFailure("Failure inet the visibleViewController!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class ChromeSafariBrowserManager: ChannelDelegate {
|
||||||
|
|
||||||
if #available(iOS 9.0, *), let plugin = plugin {
|
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
|
// flutterViewController could be casted to FlutterViewController if needed
|
||||||
|
|
||||||
let safariSettings = SafariBrowserSettings()
|
let safariSettings = SafariBrowserSettings()
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
//
|
||||||
|
// UIApplication+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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue