From fabaa3684199b02ce9a78c03015880947b280f63 Mon Sep 17 00:00:00 2001 From: dostrander Date: Wed, 1 Dec 2021 14:23:22 -0500 Subject: [PATCH] Update tappable to check if UIControl is enabled --- Sources/KIF/Additions/UIView-KIFAdditions.m | 30 ++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/Sources/KIF/Additions/UIView-KIFAdditions.m b/Sources/KIF/Additions/UIView-KIFAdditions.m index 46c9c004..f1e7874a 100644 --- a/Sources/KIF/Additions/UIView-KIFAdditions.m +++ b/Sources/KIF/Additions/UIView-KIFAdditions.m @@ -767,7 +767,35 @@ - (BOOL)isProbablyTappable // Is this view currently on screen? - (BOOL)isTappable; { - return [self isTappableInRect:self.bounds]; + return ([self hasTapGestureRecognizerAndIsControlEnabled] || + [self isTappableInRect:self.bounds]); +} + +- (BOOL)hasTapGestureRecognizerAndIsControlEnabled +{ + __block BOOL hasTapGestureRecognizer = NO; + + [self.gestureRecognizers enumerateObjectsUsingBlock:^(id obj, + NSUInteger idx, + BOOL *stop) { + if ([obj isKindOfClass:[UITapGestureRecognizer class]]) { + hasTapGestureRecognizer = YES; + + if (stop != NULL) { + *stop = YES; + } + } + }]; + + // In iOS 15 UIButton's still have tap gesture recognizers when disabled. + // This prevents a control that is disabled, but still has the system gesture + // recognizers to say it's tappable. + if ([self isKindOfClass:[UIControl class]]) { + UIControl *control = (UIControl *)self; + return hasTapGestureRecognizer && control.isEnabled; + } + + return hasTapGestureRecognizer; } - (BOOL)isTappableInRect:(CGRect)rect;