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 0c8bf4c commit 34e998b
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions ios/src_library/React Native/RNIModal/RNIModalManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,28 @@ public class RNIModalManager {
};

static func getPresentedModal(
forPresentingViewController presentingVC: UIViewController
forPresentingViewController presentingVC: UIViewController,
presentedViewController presentedVC: UIViewController? = nil
) -> (any RNIModal)? {

let presentedVC = presentingVC.presentedViewController;
let presentedVC = 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,
/// B - `presentingVC` is a `RNIModalViewController`.
if let presentingModalVC = presentingVC as? RNIModalViewController,
let presentingModal = presentingModalVC.modalViewRef,
let presentedModalVC = presentingModal.modalVC {

return presentedModalVC.modalViewRef;
let presentedModalVC = presentingModal.modalVC,
let presentedModal = presentedModalVC.modalViewRef {

return presentedModal;
};

/// C - `presentedVC` has a corresponding `RNIModalViewControllerWrapper`
/// instance associated to it.
///
if let presentedVC = presentedVC,
let presentedModalWrapper = RNIModalViewControllerWrapperRegistry.get(
forViewController: presentedVC
Expand All @@ -111,7 +109,6 @@ public class RNIModalManager {

/// D - `presentingVC` has a `RNIModalViewControllerWrapper` instance
/// associated to it.
///
if let presentingModalWrapper = RNIModalViewControllerWrapperRegistry.get(
forViewController: presentingVC
),
Expand All @@ -123,6 +120,16 @@ public class RNIModalManager {
return presentedModalWrapper;
};

let topmostVC = RNIUtilities.getTopmostPresentedViewController(
for: presentingVC.view.window
);

if let topmostModalVC = topmostVC as? RNIModalViewController,
let topmostModal = topmostModalVC.modalViewRef {

return topmostModal;
};

return nil;
};

Expand Down Expand Up @@ -314,7 +321,9 @@ extension RNIModalManager: RNIModalPresentationNotifiable {
};

let windowData = RNIModalWindowMapShared.get(forWindow: senderWindow);
guard let nextModalToFocus = windowData.nextModalToFocus else {
let nextModalToFocus = windowData.nextModalToFocus

if nextModalToFocus == nil {
#if DEBUG
print(
"Error - RNIModalManager.notifyOnModalDidShow"
Expand All @@ -323,15 +332,14 @@ extension RNIModalManager: RNIModalPresentationNotifiable {
+ " - possible notifyOnModalWillShow not invoked for sender"
);
#endif
return;
};

#if DEBUG
if nextModalToFocus !== sender {
print(
"Warning - RNIModalManager.notifyOnModalDidShow"
+ " - arg sender.modalNativeID: \(sender.modalNativeID)"
+ " - nextModalToFocus.modalNativeID: \(nextModalToFocus.modalNativeID)"
+ " - nextModalToFocus.modalNativeID: \(nextModalToFocus?.modalNativeID ?? "N/A")"
+ " - nextModalToFocus !== sender"
+ " - a different modal is about to focused"
);
Expand Down

0 comments on commit 34e998b

Please sign in to comment.