diff --git a/ios/src_library/React Native/RNIModal/RNIModal.swift b/ios/src_library/React Native/RNIModal/RNIModal.swift index 8cda3ffb..8f08c94a 100644 --- a/ios/src_library/React Native/RNIModal/RNIModal.swift +++ b/ios/src_library/React Native/RNIModal/RNIModal.swift @@ -15,7 +15,7 @@ public typealias RNIModal = & RNIModalState & RNIModalRequestable & RNIModalFocusNotifiable - & RNIModalFocusNotifying + & RNIModalPresentationNotifying & RNIModalPresentation; /// Contains modal-related properties for keeping track of the state of the @@ -78,17 +78,17 @@ public protocol RNIModalFocusNotifiable: AnyObject { }; /// Specifies that the "adoptee/delegate" that conforms to this protocol must -/// notify a delegate of modal "focus/blur"-related events +/// notify a delegate of modal presentation-related events /// -public protocol RNIModalFocusNotifying: AnyObject { +public protocol RNIModalPresentationNotifying: AnyObject { /// Notify the "shared modal manager" if the current modal instance is going /// to be shown or hidden. /// /// That focus notification will then be relayed to the other modal instances. /// - var modalFocusDelegate: RNIModalFocusNotifiable! { get set }; - + var modalPresentationNotificationDelegate: + RNIModalPresentationNotifiable! { get set }; }; /// Properties related to modal presentation. diff --git a/ios/src_library/React Native/RNIModal/RNIModalManager.swift b/ios/src_library/React Native/RNIModal/RNIModalManager.swift index 1d105f9f..c44340f8 100644 --- a/ios/src_library/React Native/RNIModal/RNIModalManager.swift +++ b/ios/src_library/React Native/RNIModal/RNIModalManager.swift @@ -282,7 +282,7 @@ public class RNIModalManager { modal.isModalInFocus = false; - modal.modalFocusDelegate = self; + modal.modalPresentationNotificationDelegate = self; self.modalInstanceDict[modal.synthesizedUUID] = modal; }; @@ -293,19 +293,19 @@ public class RNIModalManager { }; }; -// MARK: RNIModalFocusNotifiable -// ----------------------------- +// MARK: RNIModalPresentationNotifiable +// ------------------------------------ /// The modal instances will notify the manager when they're about to show/hide /// a modal. /// -extension RNIModalManager: RNIModalFocusNotifiable { +extension RNIModalManager: RNIModalPresentationNotifiable { - public func onModalWillFocusNotification(sender: any RNIModal) { + public func notifyOnModalWillShow(sender: any RNIModal) { guard let senderWindow = sender.window else { #if DEBUG print( - "Error - RNIModalManager.onModalWillFocusNotification" + "Error - RNIModalManager.notifyOnModalWillShow" + " - arg sender.modalNativeID: \(sender.modalNativeID)" + " - Unable to send event because sender.window is nil" ); @@ -319,7 +319,7 @@ extension RNIModalManager: RNIModalFocusNotifiable { #if DEBUG let nextModalToFocus = windowData.nextModalToFocus!; print( - "Error - RNIModalManager.onModalWillFocusNotification" + "Error - RNIModalManager.notifyOnModalWillShow" + " - arg sender.modalNativeID: \(sender.modalNativeID)" + " - nextModalToFocus.modalNativeID: \(nextModalToFocus.modalNativeID)" + " - possible multiple invokation" @@ -332,7 +332,7 @@ extension RNIModalManager: RNIModalFocusNotifiable { #if DEBUG if windowData.nextModalToFocus != nil { print( - "Warning - RNIModalManager.onModalWillFocusNotification" + "Warning - RNIModalManager.notifyOnModalWillShow" + " - arg sender.modalNativeID: \(sender.modalNativeID)" + " - nextModalToFocus is not nil" + " - a different modal is about to be focused" @@ -345,7 +345,7 @@ extension RNIModalManager: RNIModalFocusNotifiable { #if DEBUG print( - "Log - RNIModalManager.onModalWillFocusNotification" + "Log - RNIModalManager.notifyOnModalWillShow" + " - arg sender.modalNativeID: \(sender.modalNativeID)" + " - prevModalIndex: \(windowData.modalIndexPrev)" + " - windowData.modalIndexNext: \(windowData.modalIndexNext_)" @@ -367,11 +367,11 @@ extension RNIModalManager: RNIModalFocusNotifiable { }; }; - public func onModalDidFocusNotification(sender: any RNIModal) { + public func notifyOnModalDidShow(sender: any RNIModal) { guard let senderWindow = sender.window else { #if DEBUG print( - "Error - RNIModalManager.onModalDidFocusNotification" + "Error - RNIModalManager.notifyOnModalDidShow" + " - arg sender.modalNativeID: \(sender.modalNativeID)" + " - Unable to send event because sender.window is nil" ); @@ -384,10 +384,10 @@ extension RNIModalManager: RNIModalFocusNotifiable { guard let nextModalToFocus = windowData.nextModalToFocus else { #if DEBUG print( - "Error - RNIModalManager.onModalDidFocusNotification" + "Error - RNIModalManager.notifyOnModalDidShow" + " - arg sender.modalNativeID: \(sender.modalNativeID)" + " - nextModalToFocus: nil" - + " - possible onModalWillFocusNotification not invoked for sender" + + " - possible notifyOnModalWillShow not invoked for sender" ); #endif return; @@ -396,7 +396,7 @@ extension RNIModalManager: RNIModalFocusNotifiable { #if DEBUG if nextModalToFocus !== sender { print( - "Warning - RNIModalManager.onModalDidFocusNotification" + "Warning - RNIModalManager.notifyOnModalDidShow" + " - arg sender.modalNativeID: \(sender.modalNativeID)" + " - nextModalToFocus.modalNativeID: \(nextModalToFocus.modalNativeID)" + " - nextModalToFocus !== sender" @@ -410,7 +410,7 @@ extension RNIModalManager: RNIModalFocusNotifiable { #if DEBUG print( - "Log - RNIModalManager.onModalDidFocusNotification" + "Log - RNIModalManager.notifyOnModalDidShow" + " - arg sender.modalNativeID: \(sender.modalNativeID)" + " - sender.modalIndexPrev: \(sender.modalIndexPrev!)" + " - sender.modalIndex: \(sender.modalIndex!)" @@ -432,11 +432,11 @@ extension RNIModalManager: RNIModalFocusNotifiable { }; }; - public func onModalWillBlurNotification(sender: any RNIModal) { + public func notifyOnModalWillHide(sender: any RNIModal) { guard let senderWindow = sender.window else { #if DEBUG print( - "Error - RNIModalManager.onModalWillBlurNotification" + "Error - RNIModalManager.notifyOnModalWillHide" + " - arg sender.modalNativeID: \(sender.modalNativeID)" + " - Unable to send event because sender.window is nil" ); @@ -450,7 +450,7 @@ extension RNIModalManager: RNIModalFocusNotifiable { #if DEBUG let nextModalToBlur = windowData.nextModalToBlur!; print( - "Error - RNIModalManager.onModalWillBlurNotification" + "Error - RNIModalManager.notifyOnModalWillHide" + " - arg sender.modalNativeID: \(sender.modalNativeID)" + " - nextModalToBlur.modalNativeID: \(nextModalToBlur.modalNativeID)" + " - possible multiple invokation" @@ -463,7 +463,7 @@ extension RNIModalManager: RNIModalFocusNotifiable { #if DEBUG if windowData.nextModalToBlur != nil { print( - "Warning - RNIModalManager.onModalWillBlurNotification" + "Warning - RNIModalManager.notifyOnModalWillHide" + " - arg sender.modalNativeID: \(sender.modalNativeID)" + " - nextModalToBlur is not nil" + " - a different modal is about to blur" @@ -476,7 +476,7 @@ extension RNIModalManager: RNIModalFocusNotifiable { #if DEBUG print( - "Log - RNIModalManager.onModalWillBlurNotification" + "Log - RNIModalManager.notifyOnModalWillHide" + " - arg sender.modalNativeID: \(sender.modalNativeID)" + " - prevModalIndex: \(windowData.modalIndexPrev)" + " - windowData.modalIndexNext: \(windowData.modalIndexNext_)" @@ -497,11 +497,11 @@ extension RNIModalManager: RNIModalFocusNotifiable { }; }; - public func onModalDidBlurNotification(sender: any RNIModal) { + public func notifyOnModalDidHide(sender: any RNIModal) { guard let senderWindow = sender.window else { #if DEBUG print( - "Error - RNIModalManager.onModalDidBlurNotification" + "Error - RNIModalManager.notifyOnModalDidHide" + " - arg sender.modalNativeID: \(sender.modalNativeID)" + " - Unable to send event because sender.window is nil" ); @@ -514,10 +514,10 @@ extension RNIModalManager: RNIModalFocusNotifiable { guard let nextModalToBlur = windowData.nextModalToBlur else { #if DEBUG print( - "Error - RNIModalManager.onModalDidBlurNotification" + "Error - RNIModalManager.notifyOnModalDidHide" + " - arg sender.modalNativeID: \(sender.modalNativeID)" + " - nextModalToBlur: nil" - + " - possible onModalWillBlurNotification not invoked for sender" + + " - possible notifyOnModalWillHide not invoked for sender" ); #endif return; @@ -526,7 +526,7 @@ extension RNIModalManager: RNIModalFocusNotifiable { #if DEBUG if nextModalToBlur !== sender { print( - "Warning - RNIModalManager.onModalDidBlurNotification" + "Warning - RNIModalManager.notifyOnModalDidHide" + " - arg sender.modalNativeID: \(sender.modalNativeID)" + " - nextModalToBlur.modalNativeID: \(nextModalToBlur.modalNativeID)" + " - nextModalToBlur !== sender" @@ -540,7 +540,7 @@ extension RNIModalManager: RNIModalFocusNotifiable { #if DEBUG print( - "Log - RNIModalManager.onModalDidBlurNotification" + "Log - RNIModalManager.notifyOnModalDidHide" + " - arg sender.modalNativeID: \(sender.modalNativeID)" + " - sender.modalIndexPrev: \(sender.modalIndexPrev!)" + " - sender.modalIndex: \(sender.modalIndex!)" diff --git a/ios/src_library/React Native/RNIModal/RNIModalPresentationNotifiable.swift b/ios/src_library/React Native/RNIModal/RNIModalPresentationNotifiable.swift new file mode 100644 index 00000000..285a7026 --- /dev/null +++ b/ios/src_library/React Native/RNIModal/RNIModalPresentationNotifiable.swift @@ -0,0 +1,19 @@ +// +// RNIModalPresentationNotifiable.swift +// react-native-ios-modal +// +// Created by Dominic Go on 4/10/23. +// + +import Foundation + +public protocol RNIModalPresentationNotifiable: AnyObject { + + func notifyOnModalWillShow(sender: any RNIModal); + + func notifyOnModalDidShow(sender: any RNIModal); + + func notifyOnModalWillHide(sender: any RNIModal); + + func notifyOnModalDidHide(sender: any RNIModal); +}; diff --git a/ios/src_library/React Native/RNIModalView/RNIModalView.swift b/ios/src_library/React Native/RNIModalView/RNIModalView.swift index 282552f4..4bb6c97a 100644 --- a/ios/src_library/React Native/RNIModalView/RNIModalView.swift +++ b/ios/src_library/React Native/RNIModalView/RNIModalView.swift @@ -8,8 +8,9 @@ import Foundation -public class RNIModalView: UIView, RNIIdentifiable, RNIModalFocusNotifying, - RNIModalState, RNIModalPresentation { +public class RNIModalView: UIView, RNIIdentifiable, + RNIModalPresentationNotifying, RNIModalState, + RNIModalPresentation { public typealias CompletionHandler = (_ isSuccess: Bool, _ error: RNIModalViewError?) -> Void; @@ -30,10 +31,11 @@ public class RNIModalView: UIView, RNIIdentifiable, RNIModalFocusNotifying, var modalContentWrapper: RNIWrapperView?; public var modalVC: RNIModalViewController?; - // MARK: - Properties - RNIModalFocusNotifying - // ------------------------------------------- + // MARK: - Properties - RNIModalPresentationNotifying + // -------------------------------------------------- - public weak var modalFocusDelegate: RNIModalFocusNotifiable!; + public weak var modalPresentationNotificationDelegate: + RNIModalPresentationNotifiable!; // MARK: - Properties - RNIModalIdentity // ------------------------------------- @@ -673,7 +675,8 @@ extension RNIModalView: UIAdaptivePresentationControllerDelegate { }; public func presentationControllerDidDismiss(_ presentationController: UIPresentationController) { - self.modalFocusDelegate.onModalDidBlurNotification(sender: self); + self.modalPresentationNotificationDelegate + .notifyOnModalDidHide(sender: self); #if DEBUG print( @@ -734,14 +737,16 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable { guard sender.isBeingPresented else { return }; self.modalState.set(state: .PRESENTING_UNKNOWN); - self.modalFocusDelegate.onModalWillFocusNotification(sender: self); + self.modalPresentationNotificationDelegate + .notifyOnModalWillShow(sender: self); }; public func viewDidAppear(sender: UIViewController, animated: Bool) { guard sender.isBeingPresented else { return }; self.modalState.set(state: .PRESENTED_UNKNOWN); - self.modalFocusDelegate.onModalDidFocusNotification(sender: self); + self.modalPresentationNotificationDelegate + .notifyOnModalDidShow(sender: self); if !self.modalState.wasDismissViaGestureCancelled { self.onModalShow?( @@ -754,7 +759,8 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable { guard sender.isBeingDismissed else { return }; self.modalState.set(state: .DISMISSING_UNKNOWN); - self.modalFocusDelegate.onModalWillBlurNotification(sender: self); + self.modalPresentationNotificationDelegate + .notifyOnModalWillHide(sender: self); if self.modalState.state.isDismissingViaGesture { self.onModalWillDismiss?( @@ -767,7 +773,8 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable { guard sender.isBeingDismissed else { return }; self.modalState.set(state: .DISMISSED); - self.modalFocusDelegate.onModalDidBlurNotification(sender: self); + self.modalPresentationNotificationDelegate + .notifyOnModalDidHide(sender: self); if self.modalState.statePrev.isDismissingViaGesture { self.onModalDidDismiss?(