Skip to content

Commit

Permalink
⭐️ Impl: UIWindow+ModalHelpers
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Sep 27, 2024
1 parent 98fdbdf commit 5adabb1
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions ios/Temp/UIWindow+ModalHelpers.swift
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;
};
};

0 comments on commit 5adabb1

Please sign in to comment.