Skip to content

Commit 5886557

Browse files
committed
Fixed animation bug and added more input control
1 parent 5af513b commit 5886557

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

TOPasscodeViewController/TOPasscodeSettingsViewController.m

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ - (void)updateContentForState:(TOPasscodeSettingsViewState)state type:(TOPasscod
167167
// Update the visibility of the options button
168168
self.optionsButton.hidden = !(state == TOPasscodeSettingsViewStateEnterNewPassword);
169169

170+
// Clear the input view
171+
self.numberInputView.passcode = nil;
172+
170173
// Update the warning label
171174
self.warningLabel.hidden = !(confirmingPasscode && self.failedPasscodeAttemptCount > 0);
172175
self.warningLabel.numberOfWarnings = self.failedPasscodeAttemptCount;
@@ -175,9 +178,6 @@ - (void)updateContentForState:(TOPasscodeSettingsViewState)state type:(TOPasscod
175178
frame.origin.x = (CGRectGetWidth(self.view.frame) - frame.size.width) * 0.5f;
176179
self.warningLabel.frame = frame;
177180

178-
// Reset the passcode view
179-
[self.numberInputView resetPasscodeAnimated:NO playImpact:NO];
180-
181181
// Change the input view if needed
182182
if (self.passcodeType < TOPasscodeTypeCustomNumeric) {
183183
self.numberInputView.requiredLength = (self.passcodeType == TOPasscodeTypeSixDigits) ? 6 : 4;
@@ -371,8 +371,6 @@ - (void)numberViewDidEnterPasscode:(NSString *)passcode
371371
[self confirmNewPasscode:passcode];
372372
break;
373373
}
374-
375-
[self updateContentForState:self.state type:self.passcodeType];
376374
}
377375

378376
- (void)validateCurrentPasscodeAttemptWithPasscode:(NSString *)passcode
@@ -471,4 +469,11 @@ - (void)setState:(TOPasscodeSettingsViewState)state
471469
[self updateContentForState:_state type:self.passcodeType];
472470
}
473471

472+
- (void)setFailedPasscodeAttemptCount:(NSInteger)failedPasscodeAttemptCount
473+
{
474+
if (_failedPasscodeAttemptCount == failedPasscodeAttemptCount) { return; }
475+
_failedPasscodeAttemptCount = failedPasscodeAttemptCount;
476+
[self updateContentForState:self.state type:self.passcodeType];
477+
}
478+
474479
@end

TOPasscodeViewController/TOPasscodeViewController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ NS_ASSUME_NONNULL_BEGIN
5252
/** The base style of the PIN view controller. Can be configured further. */
5353
@property (nonatomic, assign) TOPasscodeViewStyle style;
5454

55+
/** The type of passcode that is expected to be entered. */
56+
@property (nonatomic, assign) TOPasscodeType passcodeType;
57+
5558
/** Will show a 'Touch ID' button for that the user can tap to initiate Touch ID verification. (Default is NO) */
5659
@property (nonatomic, assign) BOOL allowBiometricValidation;
5760

TOPasscodeViewController/TOPasscodeViewController.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,14 @@ - (TOPasscodeView *)passcodeView
366366
return _passcodeView;
367367
}
368368

369+
- (void)setPasscodeType:(TOPasscodeType)passcodeType
370+
{
371+
if (_passcodeType == passcodeType) { return; }
372+
_passcodeType = passcodeType;
373+
self.passcodeView.numberInputView.requiredLength = _passcodeType == TOPasscodeTypeSixDigits ? 6 : 4;
374+
[self.passcodeView setNeedsLayout];
375+
}
376+
369377
- (void)setStyle:(TOPasscodeViewStyle)style
370378
{
371379
if (style == _style) { return; }

TOPasscodeViewController/Views/TOPasscodeNumberInputView.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ - (instancetype)initWithFrame:(CGRect)frame
5050

5151
#pragma mark - View Layout -
5252

53+
- (void)setFrame:(CGRect)frame
54+
{
55+
[super setFrame:frame];
56+
}
57+
5358
- (void)sizeToFit
5459
{
5560
// Resize the view to encompass the circles

TOPasscodeViewControllerExample/ViewController.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ - (IBAction)showButtonTapped:(id)sender
4444
TOPasscodeViewController *passcodeViewController = [[TOPasscodeViewController alloc] initWithStyle:self.style];
4545
passcodeViewController.delegate = self;
4646
passcodeViewController.allowBiometricValidation = self.biometricsAvailable;
47+
passcodeViewController.passcodeType = (self.passcode.length == 6) ? TOPasscodeTypeSixDigits : TOPasscodeTypeFourDigits;
4748
[self presentViewController:passcodeViewController animated:YES completion:nil];
4849
}
4950

0 commit comments

Comments
 (0)