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