Skip to content

Commit

Permalink
💫 Update: UIViewController._swizzled_present
Browse files Browse the repository at this point in the history
Summary: Update `UIViewController._swizzled_present` to use `RNIModalWrapper`, and integrate w/ `RNIModalManager`.
  • Loading branch information
dominicstop committed Apr 12, 2023
1 parent a6c17d0 commit 6f81967
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import Foundation


extension UIViewController {

static var isSwizzled = false;
Expand All @@ -26,6 +25,29 @@ extension UIViewController {
);
#endif

let presentingModal: (any RNIModal)? = {
if let modalVC = self as? RNIModalViewController {
return modalVC.modalViewRef
};

let matchingModalWrapper = RNIModalManagerShared.getModalInstance(
forPresentingViewController: viewControllerToPresent
) as? RNIModalViewControllerWrapper;

let modalWrapper =
matchingModalWrapper ?? RNIModalViewControllerWrapper();

modalWrapper.presentingViewController = self;
modalWrapper.modalViewController = viewControllerToPresent;

return modalWrapper;
}();

if let presentingModal = presentingModal {
presentingModal.modalPresentationNotificationDelegate
.notifyOnModalWillShow(sender: presentingModal);
};

// call original impl.
self._swizzled_present(viewControllerToPresent, animated: flag) {
#if DEBUG
Expand All @@ -36,6 +58,11 @@ extension UIViewController {
);
#endif

if let presentingModal = presentingModal {
presentingModal.modalPresentationNotificationDelegate
.notifyOnModalDidShow(sender: presentingModal);
};

completion?();
};
};
Expand Down

0 comments on commit 6f81967

Please sign in to comment.