Skip to content

Commit

Permalink
Merge pull request #1250 from kif-framework/dostrander/check-control-…
Browse files Browse the repository at this point in the history
…tapgesture

Update tappable to check if UIControl is enabled
  • Loading branch information
dostrander authored Dec 13, 2021
2 parents fe05c6c + fabaa36 commit 709adbc
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion Sources/KIF/Additions/UIView-KIFAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,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;
Expand Down

0 comments on commit 709adbc

Please sign in to comment.