Skip to content

Commit 08a382c

Browse files
author
Fae Laren
committed
Add "allowCancel" to TOPasscodeViewController
Adds a new "allowCancel" property on TOPasscodeViewController that turns off the default cancel button when set to NO, for use when the user can't proceed in the app at all without entering a passcode.
1 parent 46349f6 commit 08a382c

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎TOPasscodeViewController/TOPasscodeViewController.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ NS_ASSUME_NONNULL_BEGIN
8282
/** Will show a 'Touch ID' or 'Face ID' (depending on `biometricType`) button if the user is allowed to log in that way. (Default is NO) */
8383
@property (nonatomic, assign) BOOL allowBiometricValidation;
8484

85+
/** Will show a default 'Cancel' button if rightAccessoryButton is not set. (Default is YES) */
86+
@property (nonatomic, assign) BOOL allowCancel;
87+
8588
/** Set the type of biometrics for this device to update the title of the biometrics button properly. */
8689
@property (nonatomic, assign) TOPasscodeBiometryType biometryType;
8790

‎TOPasscodeViewController/TOPasscodeViewController.m‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ - (void)setUp
8080
{
8181
self.transitioningDelegate = self;
8282
self.automaticallyPromptForBiometricValidation = NO;
83+
self.allowCancel = YES;
8384

8485
if (TOPasscodeViewStyleIsTranslucent(self.style)) {
8586
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
@@ -176,6 +177,9 @@ - (void)setUpAccessoryButtons
176177
[self.cancelButton setTitle:NSLocalizedString(@"Cancel", @"Cancel") forState:UIControlStateNormal];
177178
self.cancelButton.titleLabel.font = buttonFont;
178179
[self.cancelButton addTarget:self action:@selector(accessoryButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
180+
// If cancelling is disabled, we hide the cancel button but we still create it, because it can
181+
// transition to backspace after user input.
182+
self.cancelButton.hidden = !self.allowCancel;
179183
if (isPad) {
180184
self.passcodeView.rightButton = self.cancelButton;
181185
}
@@ -443,9 +447,17 @@ - (void)accessoryButtonTapped:(id)sender
443447

444448
- (void)keypadButtonTapped
445449
{
446-
NSString *title = self.passcodeView.passcode.length > 0 ? NSLocalizedString(@"Delete", @"Delete") : NSLocalizedString(@"Cancel", @"Cancel");
450+
NSString *title = nil;
451+
if (self.passcodeView.passcode.length > 0) {
452+
title = NSLocalizedString(@"Delete", @"Delete");
453+
} else if (self.allowCancel) {
454+
title = NSLocalizedString(@"Cancel", @"Cancel");
455+
}
447456
[UIView performWithoutAnimation:^{
448-
[self.cancelButton setTitle:title forState:UIControlStateNormal];
457+
if (title != nil) {
458+
[self.cancelButton setTitle:title forState:UIControlStateNormal];
459+
}
460+
self.cancelButton.hidden = (title == nil);
449461
}];
450462
}
451463

0 commit comments

Comments
 (0)