Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 45b7fe6

Browse files
author
Ignacio Romero Zurbuchen
committed
Stores all key commands in a instance variable, to avoid recreating the array at every character update.
1 parent 4bddda9 commit 45b7fe6

1 file changed

Lines changed: 14 additions & 21 deletions

File tree

Source/SLKTextViewController.m

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ @interface SLKTextViewController ()
6262
// YES if the view controller's view's size is changing by its parent (i.e. when its window rotates or is resized)
6363
@property (nonatomic, getter = isTransitioning) BOOL transitioning;
6464

65+
// The keyboard commands available for external keyboards
66+
@property (nonatomic, strong) NSArray *keyboardCommands;
67+
6568
// Optional classes to be used instead of the default ones.
6669
@property (nonatomic, strong) Class textViewClass;
6770
@property (nonatomic, strong) Class typingIndicatorViewClass;
@@ -2193,14 +2196,17 @@ - (void)slk_updateViewConstraints
21932196

21942197
- (NSArray *)keyCommands
21952198
{
2196-
NSMutableArray *keyboardCommands = [NSMutableArray new];
2199+
if (_keyboardCommands) {
2200+
return _keyboardCommands;
2201+
}
21972202

2198-
[keyboardCommands addObject:[self slk_returnKeyCommand]];
2199-
[keyboardCommands addObject:[self slk_escKeyCommand]];
2200-
[keyboardCommands addObject:[self slk_arrowKeyCommand:UIKeyInputUpArrow]];
2201-
[keyboardCommands addObject:[self slk_arrowKeyCommand:UIKeyInputDownArrow]];
2203+
_keyboardCommands = @[[self slk_returnKeyCommand],
2204+
[self slk_escKeyCommand],
2205+
[self slk_arrowKeyCommand:UIKeyInputUpArrow],
2206+
[self slk_arrowKeyCommand:UIKeyInputDownArrow],
2207+
];
22022208

2203-
return keyboardCommands;
2209+
return _keyboardCommands;
22042210
}
22052211

22062212
- (UIKeyCommand *)slk_returnKeyCommand
@@ -2210,12 +2216,7 @@ - (UIKeyCommand *)slk_returnKeyCommand
22102216
#ifdef __IPHONE_9_0
22112217
if ([UIKeyCommand respondsToSelector:@selector(keyCommandWithInput:modifierFlags:action:discoverabilityTitle:)] ) {
22122218
// Only available since iOS 9
2213-
if (_textInputbar.isEditing) {
2214-
command.discoverabilityTitle = [_textInputbar.editorRightButton titleForState:UIControlStateNormal] ? : NSLocalizedString(@"Commit Editing", nil);
2215-
}
2216-
else if (self.textView.text.length > 0) {
2217-
command.discoverabilityTitle = [self.rightButton titleForState:UIControlStateNormal] ? : NSLocalizedString(@"Send", nil);
2218-
}
2219+
command.discoverabilityTitle = [self.rightButton titleForState:UIControlStateNormal] ? : NSLocalizedString(@"Send/Accept", nil);
22192220
}
22202221
#endif
22212222

@@ -2229,15 +2230,7 @@ - (UIKeyCommand *)slk_escKeyCommand
22292230
#ifdef __IPHONE_9_0
22302231
if ([UIKeyCommand respondsToSelector:@selector(keyCommandWithInput:modifierFlags:action:discoverabilityTitle:)] ) {
22312232
// Only available since iOS 9
2232-
if (self.isAutoCompleting) {
2233-
command.discoverabilityTitle = NSLocalizedString(@"Exit Auto-Completion", nil);
2234-
}
2235-
else if (_textInputbar.isEditing) {
2236-
command.discoverabilityTitle = [_textInputbar.editorRightButton titleForState:UIControlStateNormal] ? : NSLocalizedString(@"Exit Editing", nil);
2237-
}
2238-
else if (!self.isExternalKeyboardDetected && self.keyboardHC.constant != 0) {
2239-
command.discoverabilityTitle = NSLocalizedString(@"Hide Keyboard", nil);
2240-
}
2233+
command.discoverabilityTitle = NSLocalizedString(@"Dismiss", nil);
22412234
}
22422235
#endif
22432236

0 commit comments

Comments
 (0)