From cd86c6d49055110f3b313fe83811c525fadb4c73 Mon Sep 17 00:00:00 2001 From: Dominic Go <18517029+dominicstop@users.noreply.github.com> Date: Thu, 27 Apr 2023 02:54:32 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=AB=20Update:=20`UIViewController+Swiz?= =?UTF-8?q?zling`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UIViewController+Swizzling.swift | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/ios/src_library/Extensions/UIViewController+Swizzling.swift b/ios/src_library/Extensions/UIViewController+Swizzling.swift index 929ef14f..e8d048c7 100644 --- a/ios/src_library/Extensions/UIViewController+Swizzling.swift +++ b/ios/src_library/Extensions/UIViewController+Swizzling.swift @@ -7,6 +7,27 @@ import Foundation +// TODO: Move to `RNIUtilities` +extension RNIUtilities { + static func swizzleExchangeMethods( + defaultSelector: Selector, + newSelector: Selector, + forClass class: AnyClass + ) { + let defaultInstace = + class_getInstanceMethod(`class`.self, defaultSelector); + + let newInstance = + class_getInstanceMethod(`class`.self, newSelector); + + guard let defaultInstance = defaultInstace, + let newInstance = newInstance + else { return }; + + method_exchangeImplementations(defaultInstance, newInstance); + }; +}; + fileprivate class RNIModalWrapperMap { static let instanceMap = NSMapTable< @@ -200,25 +221,6 @@ extension UIViewController { }; }; - // TODO: Move to `RNIUtilities` - static func swizzleExchangeMethods( - defaultSelector: Selector, - newSelector: Selector, - forClass class: AnyClass - ) { - let defaultInstace = - class_getInstanceMethod(`class`.self, defaultSelector); - - let newInstance = - class_getInstanceMethod(`class`.self, newSelector); - - guard let defaultInstance = defaultInstace, - let newInstance = newInstance - else { return }; - - method_exchangeImplementations(defaultInstance, newInstance); - }; - internal static func swizzleMethods() { guard RNIModalSwizzling.shouldEnableSwizzling else { return }; @@ -229,13 +231,13 @@ extension UIViewController { ); #endif - self.swizzleExchangeMethods( + RNIUtilities.swizzleExchangeMethods( defaultSelector: #selector(Self.present(_:animated:completion:)), newSelector: #selector(Self._swizzled_present(_:animated:completion:)), forClass: UIViewController.self ); - self.swizzleExchangeMethods( + RNIUtilities.swizzleExchangeMethods( defaultSelector: #selector(Self.dismiss(animated:completion:)), newSelector: #selector(Self._swizzled_dismiss(animated:completion:)), forClass: UIViewController.self