From 9040902efdbfc470e5bccdc4a51d64aff4b1dd3b Mon Sep 17 00:00:00 2001 From: Mobile DevX Robot Date: Thu, 13 Jun 2024 13:29:26 -0700 Subject: [PATCH] UIGestureRecognizer swizzling fix for iOS 18. PiperOrigin-RevId: 643104022 --- .../Additions/UIGestureRecognizer+GREYApp.m | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/AppFramework/Additions/UIGestureRecognizer+GREYApp.m b/AppFramework/Additions/UIGestureRecognizer+GREYApp.m index fae90fc40..2221a798b 100644 --- a/AppFramework/Additions/UIGestureRecognizer+GREYApp.m +++ b/AppFramework/Additions/UIGestureRecognizer+GREYApp.m @@ -36,11 +36,6 @@ + (void)load { gDisabledGestureRecognizers = nil; GREYSwizzler *swizzler = [[GREYSwizzler alloc] init]; BOOL swizzled = [swizzler swizzleClass:self - replaceInstanceMethod:NSSelectorFromString(@"_setDirty") - withMethod:@selector(greyswizzled_setDirty)]; - GREYFatalAssertWithMessage(swizzled, @"Failed to swizzle UIGestureRecognizer _setDirty"); - - swizzled = [swizzler swizzleClass:self replaceInstanceMethod:NSSelectorFromString(@"_resetGestureRecognizer") withMethod:@selector(greyswizzled_resetGestureRecognizer)]; GREYFatalAssertWithMessage(swizzled, @@ -59,21 +54,6 @@ + (void)load { #pragma mark - Swizzled Implementation -- (void)greyswizzled_setDirty { - INVOKE_ORIGINAL_IMP(void, @selector(greyswizzled_setDirty)); - BOOL isAKeyboardPinchGestureOnIPad = - ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad && - [self isKindOfClass:gKeyboardPinchGestureRecognizerClass]); - if (!isAKeyboardPinchGestureOnIPad && self.state != UIGestureRecognizerStateFailed) { - GREYAppStateTrackerObject *object = - TRACK_STATE_FOR_OBJECT(kGREYPendingGestureRecognition, self); - object.objectDescription = - [NSString stringWithFormat:@"%@\n Delegate: %@\n", object.objectDescription, self.delegate]; - objc_setAssociatedObject(self, @selector(greyswizzled_setState:), object, - OBJC_ASSOCIATION_RETAIN_NONATOMIC); - } -} - - (void)greyswizzled_resetGestureRecognizer { GREYAppStateTrackerObject *object = objc_getAssociatedObject(self, @selector(greyswizzled_setState:)); @@ -90,6 +70,18 @@ - (void)greyswizzled_setState:(UIGestureRecognizerState)state { objc_getAssociatedObject(self, @selector(greyswizzled_setState:)); UNTRACK_STATE_FOR_OBJECT(kGREYPendingGestureRecognition, object); objc_setAssociatedObject(self, @selector(greyswizzled_setState:), nil, OBJC_ASSOCIATION_ASSIGN); + } else { + BOOL isAKeyboardPinchGestureOnIPad = + ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad && + [self isKindOfClass:gKeyboardPinchGestureRecognizerClass]); + if (!isAKeyboardPinchGestureOnIPad && self.state != UIGestureRecognizerStateFailed) { + GREYAppStateTrackerObject *object = + TRACK_STATE_FOR_OBJECT(kGREYPendingGestureRecognition, self); + object.objectDescription = [NSString + stringWithFormat:@"%@\n Delegate: %@\n", object.objectDescription, self.delegate]; + objc_setAssociatedObject(self, @selector(greyswizzled_setState:), object, + OBJC_ASSOCIATION_RETAIN_NONATOMIC); + } } INVOKE_ORIGINAL_IMP1(void, @selector(greyswizzled_setState:), state); }