Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIGestureRecognizer swizzling fix for iOS 18. #2034

Open
wants to merge 1 commit into
base: earlgrey2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions AppFramework/Additions/UIGestureRecognizer+GREYApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:));
Expand All @@ -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);
}
Expand Down