@@ -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