diff --git a/Natives/UIKit+hook.m b/Natives/UIKit+hook.m index d87482ec..e21845e3 100644 --- a/Natives/UIKit+hook.m +++ b/Natives/UIKit+hook.m @@ -8,6 +8,7 @@ void swizzle(Class class, SEL originalAction, SEL swizzledAction) { __attribute__((constructor)) void hookConstructor(void) { swizzle(UIDevice.class, @selector(userInterfaceIdiom), @selector(hook_userInterfaceIdiom)); + swizzle(UIResponder.class, @selector(becomeFirstResponder), @selector(hook_becomeFirstResponder)); swizzle(UIToolbar.class, @selector(sizeThatFits:), @selector(hook_sizeThatFits:)); swizzle(UIView.class, @selector(didMoveToSuperview), @selector(hook_didMoveToSuperview)); swizzle(UIView.class, @selector(setFrame:), @selector(hook_setFrame:)); @@ -36,6 +37,24 @@ __attribute__((constructor)) void hookConstructor(void) { @end +@implementation UIResponder(hook) + +- (BOOL)hook_becomeFirstResponder { + // Workaround a weird bug: UIKit tries to present an accessibility UITextField + // for some reason, which could cause crash due to mismatched parent view controller + // UIViewControllerHierarchyInconsistency + + @try { + return [self hook_becomeFirstResponder]; + } @catch (NSException *e) { + NSLog(@"-[UITextInputUIResponderAccessibility becomeFirstResponder]: %@", e); + } + + return NO; +} + +@end + @implementation UITraitCollection(hook) - (UIUserInterfaceSizeClass)verticalSizeClass {