fix: dynamically get the visible view controller to fix issue with presenting the webView in multiple flutter app.
This commit is contained in:
parent
b00b3781ef
commit
82c96a957f
|
@ -98,6 +98,27 @@ 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
|
||||||
|
@ -105,23 +126,17 @@ public class InAppBrowserManager: ChannelDelegate {
|
||||||
navController.pushViewController(webViewController, animated: false)
|
navController.pushViewController(webViewController, animated: false)
|
||||||
webViewController.prepareNavigationControllerBeforeViewWillAppear()
|
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
|
var animated = true
|
||||||
if let browserSettings = webViewController.browserSettings, browserSettings.hidden {
|
if let browserSettings = webViewController.browserSettings, browserSettings.hidden {
|
||||||
tmpWindow.isHidden = true
|
|
||||||
UIApplication.shared.delegate?.window??.makeKeyAndVisible()
|
|
||||||
animated = false
|
animated = false
|
||||||
}
|
}
|
||||||
tmpWindow.rootViewController!.present(navController, animated: animated, completion: nil)
|
|
||||||
|
guard let visibleViewController = visibleViewController() else {
|
||||||
|
assertionFailure("Failure inet the visibleViewController!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
visibleViewController.present(navController, animated: animated)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func openWithSystemBrowser(url: String, result: @escaping FlutterResult) {
|
public func openWithSystemBrowser(url: String, result: @escaping FlutterResult) {
|
||||||
|
|
Loading…
Reference in New Issue