Skip to content

Commit 709adbc

Browse files
authored
Merge pull request #1250 from kif-framework/dostrander/check-control-tapgesture
Update tappable to check if UIControl is enabled
2 parents fe05c6c + fabaa36 commit 709adbc

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

Sources/KIF/Additions/UIView-KIFAdditions.m

+29-1
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,35 @@ - (BOOL)isProbablyTappable
765765
// Is this view currently on screen?
766766
- (BOOL)isTappable;
767767
{
768-
return [self isTappableInRect:self.bounds];
768+
return ([self hasTapGestureRecognizerAndIsControlEnabled] ||
769+
[self isTappableInRect:self.bounds]);
770+
}
771+
772+
- (BOOL)hasTapGestureRecognizerAndIsControlEnabled
773+
{
774+
__block BOOL hasTapGestureRecognizer = NO;
775+
776+
[self.gestureRecognizers enumerateObjectsUsingBlock:^(id obj,
777+
NSUInteger idx,
778+
BOOL *stop) {
779+
if ([obj isKindOfClass:[UITapGestureRecognizer class]]) {
780+
hasTapGestureRecognizer = YES;
781+
782+
if (stop != NULL) {
783+
*stop = YES;
784+
}
785+
}
786+
}];
787+
788+
// In iOS 15 UIButton's still have tap gesture recognizers when disabled.
789+
// This prevents a control that is disabled, but still has the system gesture
790+
// recognizers to say it's tappable.
791+
if ([self isKindOfClass:[UIControl class]]) {
792+
UIControl *control = (UIControl *)self;
793+
return hasTapGestureRecognizer && control.isEnabled;
794+
}
795+
796+
return hasTapGestureRecognizer;
769797
}
770798

771799
- (BOOL)isTappableInRect:(CGRect)rect;

0 commit comments

Comments
 (0)