Skip to content

Commit

Permalink
💫 Update: RNIModalManager
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Apr 27, 2023
1 parent a470010 commit 0c8bf4c
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion ios/src_library/React Native/RNIModal/RNIModalManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public class RNIModalManager {
// MARK: - Static Functions
// ------------------------

static func getPresentedModals(forWindow window: UIWindow) -> [any RNIModal] {
static func getPresentedModals(
forWindow window: UIWindow
) -> [any RNIModal] {

let vcItems = RNIUtilities.getPresentedViewControllers(for: window);

return vcItems.compactMap {
Expand Down Expand Up @@ -73,6 +76,56 @@ public class RNIModalManager {
);
};

static func getPresentedModal(
forPresentingViewController presentingVC: UIViewController
) -> (any RNIModal)? {

let presentedVC = presentingVC.presentedViewController;

/// A - `presentedVC` is a `RNIModalViewController`.
///
if let presentedModalVC = presentedVC as? RNIModalViewController {
return presentedModalVC.modalViewRef;
};

/// B - `presentedVC` is a `RNIModalViewController` (and was presented by a
/// `RNIModalView`).
///
if let presentingModalVC = presentedVC as? RNIModalViewController,
let presentingModal = presentingModalVC.modalViewRef,
let presentedModalVC = presentingModal.modalVC {

return presentedModalVC.modalViewRef;
};

/// C - `presentedVC` has a corresponding `RNIModalViewControllerWrapper`
/// instance associated to it.
///
if let presentedVC = presentedVC,
let presentedModalWrapper = RNIModalViewControllerWrapperRegistry.get(
forViewController: presentedVC
) {

return presentedModalWrapper;
};

/// D - `presentingVC` has a `RNIModalViewControllerWrapper` instance
/// associated to it.
///
if let presentingModalWrapper = RNIModalViewControllerWrapperRegistry.get(
forViewController: presentingVC
),
let presentedVC = presentingModalWrapper.modalViewController,
let presentedModalWrapper = RNIModalViewControllerWrapperRegistry.get(
forViewController: presentedVC
) {

return presentedModalWrapper;
};

return nil;
};

// MARK: - Properties
// ------------------

Expand Down

0 comments on commit 0c8bf4c

Please sign in to comment.