-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98fdbdf
commit 5adabb1
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// UIWindow+ModalHelpers.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 9/27/24. | ||
// | ||
|
||
import UIKit | ||
import DGSwiftUtilities | ||
|
||
|
||
extension UIWindow { | ||
|
||
public var rootPresentingViewController: UIViewController? { | ||
self.rootViewController?.presentingViewController?.rootPresentingViewController; | ||
}; | ||
|
||
public var allPresentedViewControllers: [UIViewController] { | ||
guard let rootVC = self.rootViewController, | ||
let currentPresentedVC = rootVC.presentedViewController | ||
else { | ||
return []; | ||
}; | ||
|
||
return currentPresentedVC.recursivelyGetAllPresentedViewControllers; | ||
}; | ||
|
||
/// The current highest modal level in the window | ||
/// | ||
/// return value of `nil` means that there is no modal presented, and a | ||
/// return value of `0` is the first presented modal, and so on... | ||
/// | ||
public var currentModalLevel: Int? { | ||
let presentedControllersCount = allPresentedViewControllers.count; | ||
|
||
guard presentedControllersCount > 0 else { | ||
return nil; | ||
}; | ||
|
||
return presentedControllersCount - 1; | ||
}; | ||
}; |