diff --git a/ios/src_library/React Native/RNIModalView/RNIModalView.swift b/ios/src_library/React Native/RNIModalView/RNIModalView.swift index a3136faa..655be732 100644 --- a/ios/src_library/React Native/RNIModalView/RNIModalView.swift +++ b/ios/src_library/React Native/RNIModalView/RNIModalView.swift @@ -19,9 +19,6 @@ class RNIModalView: UIView, RNIModalFocusNotifying, RNIModalIdentity, weak var bridge: RCTBridge?; - /// TODO:2023-03-24-14-25-52 - Remove `RNIModalViewFocusDelegate`-related logic - weak var delegate: RNIModalViewPresentDelegate?; - private var modalVC: RNIModalViewController?; private var touchHandler: RCTTouchHandler!; @@ -545,9 +542,6 @@ class RNIModalView: UIView, RNIModalFocusNotifying, RNIModalIdentity, // Reset swipe gesture before it was temporarily disabled self.enableSwipeGesture(); - /// TODO:2023-03-24-14-25-52 - Remove `RNIModalViewFocusDelegate`-related logic - self.delegate?.onPresentModalView(modalView: self); - self.modalFocusDelegate.onModalDidFocusNotification(sender: self); self.onModalShow?( @@ -615,9 +609,6 @@ class RNIModalView: UIView, RNIModalFocusNotifying, RNIModalIdentity, self.enableSwipeGesture(false); presentedVC.dismiss(animated: true){ - /// TODO:2023-03-24-14-25-52 - Remove `RNIModalViewFocusDelegate`-related logic - self.delegate?.onDismissModalView(modalView: self); - self.onModalDismiss?( self.synthesizedBaseEventData.synthesizedDictionary ); @@ -693,10 +684,7 @@ extension RNIModalView: UIAdaptivePresentationControllerDelegate { self.modalFocusDelegate.onModalDidBlurNotification(sender: self); self.modalLevel = -1; - - /// TODO:2023-03-24-14-25-52 - Remove `RNIModalViewFocusDelegate`-related logic - self.delegate?.onDismissModalView(modalView: self); - + self.onModalDidDismiss?( self.synthesizedBaseEventData.synthesizedDictionary ); @@ -727,38 +715,8 @@ extension RNIModalView: UIAdaptivePresentationControllerDelegate { }; }; -// MARK: Extension: RNIModalViewFocusDelegate -// ------------------------------------------ - -/// TODO:2023-03-24-14-25-52 - Remove `RNIModalViewFocusDelegate`-related logic -extension RNIModalView: RNIModalViewFocusDelegate { - - func onModalChangeFocus(modalLevel: Int, modalNativeID: String, isInFocus: Bool) { - guard - /// defer if the receiver of the event is the same as the sender - /// i.e defer if this instance of `RNIModalView` was the one who broadcasted the event - self.modalNativeID != modalNativeID, - /// defer if the modal is not currently presented or if the modalLevel is -1 - self.synthesizedIsModalPresented && self.modalLevel > 0 else { return }; - - if isInFocus && !self.synthesizedIsModalInFocus { - /// a new `RNIModalView` instance is in focus and this modal was prev. in focus so - /// this modal shoud be now 'blurred' - self.onModalBlur?( - self.createModalNativeEventDict() - ); - - } else if !isInFocus && !self.synthesizedIsModalInFocus { - /// a `RNIModalView` instance has lost focus, so the prev modal shoul be focused - /// defer if the receiver's modalLevel isn't 1 value below the sender's modalLevel - guard self.modalLevel + 1 >= modalLevel else { return }; - - self.onModalFocus?( - self.createModalNativeEventDict() - ); - }; - }; -}; +// MARK: Extension: RNIModalRequestable +// ------------------------------------ extension RNIModalView: RNIModalRequestable { @@ -774,25 +732,51 @@ extension RNIModalView: RNIModalRequestable { }; +// MARK: Extension: RNIModalFocusNotifiable +// ---------------------------------------- + extension RNIModalView: RNIModalFocusNotifiable { func onModalWillFocusNotification(sender modal: RNIModal) { - /// `TODO:2023-03-24-09-58-50` - Refactor `RNIModalView` to use `RNIModalManager`. /// No-op - TBA }; func onModalDidFocusNotification(sender modal: RNIModal) { - /// `TODO:2023-03-24-09-58-50` - Refactor `RNIModalView` to use `RNIModalManager`. - /// No-op - TBA + + let eventData = RNIOnModalFocusEventData( + modalData: self.synthesizedBaseEventData, + senderInfo: modal.synthesizedModalData, + isInitial: modal === self + ); + + print( + "\nRNIModalFocusNotifiable - onModalDidFocusNotification - ", + "eventData: \(eventData.synthesizedDictionary)\n" + ); + + self.onModalFocus?( + eventData.synthesizedDictionary + ); }; func onModalWillBlurNotification(sender modal: RNIModal) { - /// `TODO:2023-03-24-09-58-50` - Refactor `RNIModalView` to use `RNIModalManager`. /// No-op - TBA }; func onModalDidBlurNotification(sender modal: RNIModal) { - /// `TODO:2023-03-24-09-58-50` - Refactor `RNIModalView` to use `RNIModalManager`. - /// No-op - TBA + let eventData = RNIOnModalFocusEventData( + modalData: self.synthesizedBaseEventData, + senderInfo: modal.synthesizedModalData, + isInitial: modal === self + ); + + print( + "\nRNIModalFocusNotifiable - onModalDidBlurNotification - ", + "eventData: \(eventData.synthesizedDictionary)\n" + ); + + self.onModalBlur?( + eventData.synthesizedDictionary + ); }; }; diff --git a/ios/src_library/React Native/RNIModalView/RNIModalViewDelegate.swift b/ios/src_library/React Native/RNIModalView/RNIModalViewDelegate.swift deleted file mode 100644 index b5d3f315..00000000 --- a/ios/src_library/React Native/RNIModalView/RNIModalViewDelegate.swift +++ /dev/null @@ -1,33 +0,0 @@ -// -// RNIModalViewDelegate.swift -// nativeUIModulesTest -// -// Created by Dominic Go on 6/17/20. -// Copyright © 2020 Facebook. All rights reserved. -// - -import Foundation - -/// TODO:2023-03-24-14-25-52 - Remove `RNIModalViewFocusDelegate`-related logic -@objc protocol RNIModalViewPresentDelegate: AnyObject { - - func onPresentModalView(modalView: RNIModalView); - - func onDismissModalView(modalView: RNIModalView); - -}; - -/// TODO:2023-03-24-14-25-52 - Remove `RNIModalViewFocusDelegate`-related logic -@objc protocol RNIModalViewFocusDelegate: AnyObject { - - /** - - Parameters: - - modalLevel: the `RNIModalView` sender's current modalLevel - - modalID : the `RNIModalView` sender's modalID - - isInFocus : Whether or not the modal is going in or out of focus - */ - func onModalChangeFocus(modalLevel: Int, modalNativeID: String, isInFocus: Bool); - -}; - - diff --git a/ios/src_library/React Native/RNIModalView/RNIModalViewManager.swift b/ios/src_library/React Native/RNIModalView/RNIModalViewManager.swift index 38073f29..abb9859d 100644 --- a/ios/src_library/React Native/RNIModalView/RNIModalViewManager.swift +++ b/ios/src_library/React Native/RNIModalView/RNIModalViewManager.swift @@ -32,7 +32,7 @@ class RNIModalViewManager: RCTViewManager { // TODO: See `TODO:2023-03-04-15-33-15` - Refactor: Relocate // `delegatesFocus` - var delegatesFocus = MulticastDelegate(); + var delegatesFocus = MulticastDelegate(); // TODO: See TODO:2023-03-04-15-38-02 - Refactor: Relocate // `currentModalLevel` @@ -40,7 +40,6 @@ class RNIModalViewManager: RCTViewManager { override func view() -> UIView! { let view = RNIModalView(bridge: self.bridge); - view.delegate = self; self.delegatesFocus.add(view); return view; @@ -61,45 +60,3 @@ class RNIModalViewManager: RCTViewManager { ]; }; }; - -// --------------------------------- -// MARK: RNIModalViewPresentDelegate -// --------------------------------- - -/// TODO:2023-03-24-14-25-52 - Remove `RNIModalViewFocusDelegate`-related logic -extension RNIModalViewManager: RNIModalViewPresentDelegate { - - func onPresentModalView(modalView: RNIModalView) { - let modalLevel = modalView.modalLevel; - let modalNativeID = modalView.modalNativeID!; - - self.currentModalLevel = modalLevel; - self.presentedModalRefs.setObject(modalView, forKey: modalNativeID as NSString); - - // notify delegates that a new modal is in focus - self.delegatesFocus.invoke { - $0.onModalChangeFocus( - modalLevel: modalLevel, - modalNativeID: modalNativeID, - isInFocus : true - ); - }; - }; - - func onDismissModalView(modalView: RNIModalView) { - let modalLevel = modalView.modalLevelPrev; - let modalID = modalView.modalNativeID! - - self.currentModalLevel = modalLevel; - self.presentedModalRefs.removeObject(forKey: modalID as NSString); - - // notify delegates that a new modal is lost focus - self.delegatesFocus.invoke { - $0.onModalChangeFocus( - modalLevel: modalLevel, - modalNativeID: modalID, - isInFocus : false - ); - }; - }; -}; diff --git a/src/components/ModalView/ModalView.tsx b/src/components/ModalView/ModalView.tsx index e14d7cca..3830a11c 100644 --- a/src/components/ModalView/ModalView.tsx +++ b/src/components/ModalView/ModalView.tsx @@ -341,30 +341,6 @@ export class ModalView extends ); this.setStateIsModalVisible(true); - - // TODO: Patch - Note:2023-03-04-02-58-31 - // * Temp impl. to make focus/blur context to work - // - // * Modal focus/blur native event does not fire on initial - // focus/blur - they only fire in response to another modal - // stealing focus. - // - // * As such, when a modal becomes visible, the focus event - // does not fire; conversely, the blur event also does not - // fire when the modal becomes hidden. - // - // * Fix/Solution: Update focus/blur event to fire on initial - // blur or focus, but there should be a `isInitialFocus`, - // and `isInitialBlur` in the event params as a means to - // distinguish if this is the first time it's going to - // focus/blur. - // - // * I.e. a means of distinguishing whether the focus/blur - // was due to a `setVisibility` request, or due to - // another modal stealing focus. - this.setState({ - isModalInFocus: true, - }); }; private _handleOnModalDismiss: OnModalDismissEvent = (event) => { @@ -385,9 +361,6 @@ export class ModalView extends // reset state values from props enableSwipeGesture: props.enableSwipeGesture, isModalInPresentation: props.isModalInPresentation, - - // TODO: Patch - See Note:2023-03-04-02-58-31 - isModalInFocus: false, }); };