From 34e998b649fc5b10d9ce5dbad284dcd7ffc7802e Mon Sep 17 00:00:00 2001 From: Dominic Go <18517029+dominicstop@users.noreply.github.com> Date: Fri, 28 Apr 2023 04:55:19 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=AB=20Update:=20`RNIModalManager`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RNIModal/RNIModalManager.swift | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/ios/src_library/React Native/RNIModal/RNIModalManager.swift b/ios/src_library/React Native/RNIModal/RNIModalManager.swift index 32465fb2..6d3f29a5 100644 --- a/ios/src_library/React Native/RNIModal/RNIModalManager.swift +++ b/ios/src_library/React Native/RNIModal/RNIModalManager.swift @@ -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 @@ -111,7 +109,6 @@ public class RNIModalManager { /// D - `presentingVC` has a `RNIModalViewControllerWrapper` instance /// associated to it. - /// if let presentingModalWrapper = RNIModalViewControllerWrapperRegistry.get( forViewController: presentingVC ), @@ -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; }; @@ -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" @@ -323,7 +332,6 @@ extension RNIModalManager: RNIModalPresentationNotifiable { + " - possible notifyOnModalWillShow not invoked for sender" ); #endif - return; }; #if DEBUG @@ -331,7 +339,7 @@ extension RNIModalManager: RNIModalPresentationNotifiable { 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" );