-
Notifications
You must be signed in to change notification settings - Fork 918
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
Adding support for accessibility custom actions #1295
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
14ddfba
adding support for custom actions
RoyalPineapple 928b63b
handling attributedstrings
RoyalPineapple f293bbe
fixing includes
RoyalPineapple 8572f3e
private
RoyalPineapple 028f998
returning action handler result directly
RoyalPineapple 595e39f
respondsToSelector check
RoyalPineapple 2fc2336
refactoring custom action category
RoyalPineapple 0db322e
now raising excepton if custom action target doesnt implement the sel…
RoyalPineapple 5bf657b
refactoring and adding autorelease pool
RoyalPineapple 3a9a6ec
allowing testing of actions that are expected to fail
RoyalPineapple 4675a70
adding tests
RoyalPineapple 69d1753
spelling
RoyalPineapple File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// CustomActionTests_ViewTestActor.m | ||
// KIF Tests | ||
// | ||
// Created by Alex Odawa on 09/07/2024. | ||
// | ||
|
||
#import <KIF/KIF.h> | ||
|
||
@interface CustomActionTests_ViewTestActor : KIFTestCase | ||
@end | ||
|
||
|
||
@implementation CustomActionTests_ViewTestActor | ||
|
||
- (void)beforeEach | ||
{ | ||
[[viewTester usingLabel:@"Tapping"] tap]; | ||
} | ||
|
||
- (void)afterEach | ||
{ | ||
[[[viewTester usingLabel:@"Test Suite"] usingTraits:UIAccessibilityTraitButton] tap]; | ||
} | ||
|
||
- (void)testCustomActions | ||
{ | ||
if (@available(iOS 13.0, *)) { | ||
[[viewTester usingLabel:@"theStepper"] activateCustomActionWithName:@"Action With block handler"]; | ||
} | ||
|
||
for (NSString *name in @[@"Action without argument", @"Action with argument"]) { | ||
[[viewTester usingLabel:@"theStepper"] activateCustomActionWithName:name]; | ||
} | ||
|
||
[[viewTester usingLabel:@"theStepper"] activateCustomActionWithName:@"Action that fails" expectedResult:NO]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
Sources/KIF/Additions/UIAccessibilityCustomAction+KIFAdditions.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// UIAccessibilityCustomAction+KIFAdditions.h | ||
// KIF | ||
// | ||
// Created by Alex Odawa on 09/07/2024. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface NSObject (KIFCustomActionAdditions) | ||
|
||
- (UIAccessibilityCustomAction *)KIF_customActionWithName:(NSString *)name; | ||
|
||
@end | ||
|
||
@interface UIAccessibilityCustomAction (KIFAdditions) | ||
|
||
- (BOOL)KIF_activate; | ||
|
||
@end | ||
|
85 changes: 85 additions & 0 deletions
85
Sources/KIF/Additions/UIAccessibilityCustomAction+KIFAdditions.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// | ||
// UIAccessibilityCustomAction+KIFAdditions.m | ||
// KIF Tests | ||
// | ||
// Created by Alex Odawa on 09/07/2024. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "UIAccessibilityCustomAction+KIFAdditions.h" | ||
|
||
|
||
|
||
@interface UIAccessibilityCustomAction (KIFPrivate) | ||
|
||
- (NSString *)KIF_normalizedName; | ||
|
||
@end | ||
|
||
@implementation UIAccessibilityCustomAction (KIFAdditions) | ||
|
||
- (BOOL)KIF_activate; | ||
{ | ||
if (@available(iOS 13.0, *)) { | ||
if (self.actionHandler) { | ||
return self.actionHandler(self); | ||
} | ||
} | ||
|
||
if ([self.target respondsToSelector:self.selector]) { | ||
NSMethodSignature *signature = [self.target methodSignatureForSelector:self.selector]; | ||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; | ||
invocation.selector = self.selector; | ||
invocation.target = self.target; | ||
|
||
/* | ||
https://developer.apple.com/documentation/uikit/uiaccessibilitycustomaction/1620499-init | ||
The method signature must take one of the following forms: | ||
- (BOOL)myPerformActionMethod | ||
- (BOOL)myPerformActionMethod:(UIAccessibilityCustomAction *)action | ||
*/ | ||
if (signature.numberOfArguments == 3) { | ||
id arg = self; | ||
[invocation setArgument: &arg atIndex:2]; | ||
} | ||
|
||
[invocation invoke]; | ||
BOOL returnValue = NO; | ||
[invocation getReturnValue:&returnValue]; | ||
return returnValue; | ||
} | ||
NSString *targetStr = [self.target description]; | ||
NSString *selectorStr = NSStringFromSelector(self.selector); | ||
[[NSException exceptionWithName:@"KIFUIAccessibilityCustomActionActivationException" | ||
reason:@"UIAccessibilityCustomAction Target does not respond to provided Selector." | ||
userInfo:@{@"Target" : targetStr, @"Selector" : selectorStr}] | ||
raise]; | ||
|
||
return NO; | ||
} | ||
|
||
- (NSString *)KIF_normalizedName; | ||
{ | ||
NSString *name = [self name]; | ||
if ([name isKindOfClass:[NSAttributedString class]]) { | ||
name = [(NSAttributedString *)name string]; | ||
} | ||
return name; | ||
} | ||
|
||
@end | ||
|
||
|
||
@implementation NSObject (KIFCustomActionAdditions) | ||
|
||
- (UIAccessibilityCustomAction *)KIF_customActionWithName:(NSString *)name; | ||
{ | ||
for (UIAccessibilityCustomAction *action in [self.accessibilityCustomActions copy]) { | ||
if ([name isEqualToString: [action KIF_normalizedName]]) { | ||
return action; | ||
} | ||
} | ||
return nil; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make more sense to raise if we attempted to perform an action on an element that says it supports it, but hasn't implemented the selector? I'd kind of expect this to crash or raise an error in some way that is distinct from the selector returning false from the action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh, nice idea