Skip to content

Commit b09f4fd

Browse files
committed
Added arbitrary input to settings
1 parent e839563 commit b09f4fd

File tree

8 files changed

+147
-169
lines changed

8 files changed

+147
-169
lines changed

TOPasscodeViewController/TOPasscodeSettingsViewController.m

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ @interface TOPasscodeSettingsViewController ()
2929
@property (nonatomic, strong) UILabel *titleLabel;
3030
@property (nonatomic, strong) UILabel *errorLabel;
3131
@property (nonatomic, strong) UIButton *optionsButton;
32-
@property (nonatomic, strong) TOPasscodeInputField *numberInputView;
32+
@property (nonatomic, strong) TOPasscodeInputField *inputField;
3333
@property (nonatomic, strong) TOPasscodeSettingsKeypadView *keypadView;
3434
@property (nonatomic, strong) TOPasscodeSettingsWarningLabel *warningLabel;
3535

@@ -89,12 +89,12 @@ - (void)viewDidLoad {
8989
[self.containerView addSubview:self.titleLabel];
9090

9191
// Create number view
92-
self.numberInputView = [[TOPasscodeInputField alloc] init];
93-
self.numberInputView.tintColor = [UIColor blackColor];
94-
self.numberInputView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
95-
self.numberInputView.passcodeCompletedHandler = ^(NSString *passcode) { [weakSelf numberViewDidEnterPasscode:passcode]; };
96-
[self.numberInputView sizeToFit];
97-
[self.containerView addSubview:self.numberInputView];
92+
self.inputField = [[TOPasscodeInputField alloc] init];
93+
self.inputField.tintColor = [UIColor blackColor];
94+
self.inputField.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
95+
self.inputField.passcodeCompletedHandler = ^(NSString *passcode) { [weakSelf numberViewDidEnterPasscode:passcode]; };
96+
[self.inputField sizeToFit];
97+
[self.containerView addSubview:self.inputField];
9898

9999
// Create keypad view
100100
self.keypadView = [[TOPasscodeSettingsKeypadView alloc] initWithFrame:CGRectZero];
@@ -129,20 +129,20 @@ - (void)viewDidLoad {
129129
// Add callbacks for the keypad view
130130
self.keypadView.numberButtonTappedHandler = ^(NSInteger number) {
131131
NSString *numberString = [NSString stringWithFormat:@"%ld", number];
132-
[weakSelf.numberInputView appendPasscodeCharacters:numberString animated:NO];
132+
[weakSelf.inputField appendPasscodeCharacters:numberString animated:NO];
133133
};
134134

135-
self.keypadView.deleteButtonTappedHandler = ^{ [weakSelf.numberInputView deletePasscodeCharactersOfCount:1 animated:NO]; };
135+
self.keypadView.deleteButtonTappedHandler = ^{ [weakSelf.inputField deletePasscodeCharactersOfCount:1 animated:NO]; };
136136

137137
// Set height of the container view (This will never change)
138138
CGRect frame = self.containerView.frame;
139139
frame.size.width = self.view.bounds.size.width;
140-
frame.size.height = CGRectGetHeight(self.titleLabel.frame) + CGRectGetHeight(self.numberInputView.frame)
140+
frame.size.height = CGRectGetHeight(self.titleLabel.frame) + CGRectGetHeight(self.inputField.frame)
141141
+ CGRectGetHeight(self.warningLabel.frame) + (kTOPasscodeSettingsLabelInputSpacing * 2.0f);
142142
self.containerView.frame = CGRectIntegral(frame);
143143

144144
//Work out the vertical offset of the container view assuming the warning label doesn't count
145-
self.verticalMidPoint = CGRectGetHeight(self.titleLabel.frame) + CGRectGetHeight(self.numberInputView.frame)
145+
self.verticalMidPoint = CGRectGetHeight(self.titleLabel.frame) + CGRectGetHeight(self.inputField.frame)
146146
+ kTOPasscodeSettingsLabelInputSpacing;
147147
self.verticalMidPoint *= 0.5f;
148148

@@ -168,7 +168,7 @@ - (void)updateContentForState:(TOPasscodeSettingsViewState)state type:(TOPasscod
168168
self.optionsButton.hidden = !(state == TOPasscodeSettingsViewStateEnterNewPassword);
169169

170170
// Clear the input view
171-
self.numberInputView.passcode = nil;
171+
self.inputField.passcode = nil;
172172

173173
// Update the warning label
174174
self.warningLabel.hidden = !(confirmingPasscode && self.failedPasscodeAttemptCount > 0);
@@ -179,8 +179,12 @@ - (void)updateContentForState:(TOPasscodeSettingsViewState)state type:(TOPasscod
179179
self.warningLabel.frame = frame;
180180

181181
// Change the input view if needed
182-
if (self.passcodeType < TOPasscodeTypeCustomNumeric) {
183-
self.numberInputView.fixedLength = (self.passcodeType == TOPasscodeTypeSixDigits) ? 6 : 4;
182+
if (type < TOPasscodeTypeCustomNumeric) {
183+
self.inputField.style = TOPasscodeInputFieldStyleFixed;
184+
self.inputField.fixedInputView.length = (self.passcodeType == TOPasscodeTypeSixDigits) ? 6 : 4;
185+
}
186+
else {
187+
self.inputField.style = TOPasscodeInputFieldStyleVariable;
184188
}
185189

186190
// Update text depending on state
@@ -200,13 +204,13 @@ - (void)updateContentForState:(TOPasscodeSettingsViewState)state type:(TOPasscod
200204
[self.titleLabel sizeToFit];
201205
frame = self.titleLabel.frame;
202206
frame.origin.x = (CGRectGetWidth(self.containerView.frame) - CGRectGetWidth(frame)) * 0.5f;
203-
self.titleLabel.frame = frame;
207+
self.titleLabel.frame = CGRectIntegral(frame);
204208

205209
// Resize passcode view
206-
[self.numberInputView sizeToFit];
207-
frame = self.numberInputView.frame;
210+
[self.inputField sizeToFit];
211+
frame = self.inputField.frame;
208212
frame.origin.x = (CGRectGetWidth(self.containerView.frame) - CGRectGetWidth(frame)) * 0.5f;
209-
self.numberInputView.frame = frame;
213+
self.inputField.frame = CGRectIntegral(frame);
210214
}
211215

212216
- (void)transitionToState:(TOPasscodeSettingsViewState)state animated:(BOOL)animated
@@ -302,21 +306,21 @@ - (void)viewDidLayoutSubviews
302306
self.titleLabel.frame = CGRectIntegral(frame);
303307

304308
// Set frame of number pad
305-
frame = self.numberInputView.frame;
309+
frame = self.inputField.frame;
306310
frame.origin.x = (CGRectGetWidth(self.view.frame) - CGRectGetWidth(frame)) * 0.5f;
307311
frame.origin.y = (CGRectGetHeight(self.titleLabel.frame) + kTOPasscodeSettingsLabelInputSpacing);
308-
self.numberInputView.frame = CGRectIntegral(frame);
312+
self.inputField.frame = CGRectIntegral(frame);
309313

310314
// Set the frame for the warning view
311315
frame = self.warningLabel.frame;
312316
frame.origin.x = (CGRectGetWidth(self.view.frame) - CGRectGetWidth(frame)) * 0.5f;
313-
frame.origin.y = CGRectGetMaxY(self.numberInputView.frame) + kTOPasscodeSettingsLabelInputSpacing;
317+
frame.origin.y = CGRectGetMaxY(self.inputField.frame) + kTOPasscodeSettingsLabelInputSpacing;
314318
self.warningLabel.frame = CGRectIntegral(frame);
315319

316320
// Set the frame of the error view
317321
frame = self.errorLabel.frame;
318322
frame.size = [self.errorLabel sizeThatFits:CGSizeMake(300.0f, CGFLOAT_MAX)];
319-
frame.origin.y = CGRectGetMaxY(self.numberInputView.frame) + kTOPasscodeSettingsLabelInputSpacing;
323+
frame.origin.y = CGRectGetMaxY(self.inputField.frame) + kTOPasscodeSettingsLabelInputSpacing;
320324
frame.origin.x = (CGRectGetWidth(self.containerView.frame) - CGRectGetWidth(frame)) * 0.5f;
321325
self.errorLabel.frame = CGRectIntegral(frame);
322326
}
@@ -345,7 +349,7 @@ - (void)applyThemeForStyle:(TOPasscodeSettingsViewStyle)style
345349
self.titleLabel.textColor = inputColor;
346350

347351
// Set the number input tint
348-
self.numberInputView.tintColor = inputColor;
352+
self.inputField.tintColor = inputColor;
349353

350354
// Set the tint color of the incorrect warning label
351355
UIColor *warningColor = nil;
@@ -382,7 +386,7 @@ - (void)validateCurrentPasscodeAttemptWithPasscode:(NSString *)passcode
382386
BOOL correct = [self.delegate passcodeSettingsViewController:self didAttemptCurrentPasscode:passcode];
383387
if (!correct) {
384388
self.failedPasscodeAttemptCount++;
385-
[self.numberInputView resetPasscodeAnimated:YES playImpact:YES];
389+
[self.inputField resetPasscodeAnimated:YES playImpact:YES];
386390
}
387391
else {
388392
[self transitionToState:TOPasscodeSettingsViewStateEnterNewPassword animated:YES];

TOPasscodeViewController/TOPasscodeViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ NS_ASSUME_NONNULL_BEGIN
5858
/** Will show a 'Touch ID' button for that the user can tap to initiate Touch ID verification. (Default is NO) */
5959
@property (nonatomic, assign) BOOL allowBiometricValidation;
6060

61-
/** If Touch ID is available, automatically ask for it upon presentation (Default is YES) */
61+
/** If Touch ID is available, automatically ask for it upon presentation (Default is NO) */
6262
@property (nonatomic, assign) BOOL automaticallyPromptForBiometricValidation;
6363

6464
/** Optionally change the color of the title text label. */

TOPasscodeViewController/TOPasscodeViewController.m

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ - (void)setUp
5151
{
5252
self.transitioningDelegate = self;
5353
self.view.backgroundColor = [UIColor clearColor];
54-
self.automaticallyPromptForBiometricValidation = YES;
54+
self.automaticallyPromptForBiometricValidation = NO;
5555

5656
if (TOPasscodeViewStyleIsTranslucent(self.style)) {
5757
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
@@ -178,7 +178,7 @@ - (void)viewDidAppear:(BOOL)animated
178178
[super viewDidAppear:animated];
179179

180180
// Automatically trigger biometric validation if available
181-
if (self.allowBiometricValidation) {
181+
if (self.allowBiometricValidation && self.automaticallyPromptForBiometricValidation) {
182182
[self accessoryButtonTapped:self.biometricButton];
183183
}
184184
}
@@ -370,7 +370,15 @@ - (void)setPasscodeType:(TOPasscodeType)passcodeType
370370
{
371371
if (_passcodeType == passcodeType) { return; }
372372
_passcodeType = passcodeType;
373-
self.passcodeView.numberInputView.fixedLength = _passcodeType == TOPasscodeTypeSixDigits ? 6 : 4;
373+
374+
if (_passcodeType <= TOPasscodeTypeSixDigits) {
375+
self.passcodeView.inputField.style = TOPasscodeInputFieldStyleFixed;
376+
self.passcodeView.inputField.fixedInputView.length = (_passcodeType == TOPasscodeTypeSixDigits) ? 6 : 4;
377+
}
378+
else {
379+
self.passcodeView.inputField.style = TOPasscodeInputFieldStyleVariable;
380+
}
381+
374382
[self.passcodeView setNeedsLayout];
375383
}
376384

TOPasscodeViewController/Views/Main/TOPasscodeView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
3131

3232
/* The default views always shown in this view */
3333
@property (nonatomic, readonly) UILabel *titleLabel;
34-
@property (nonatomic, readonly) TOPasscodeInputField *numberInputView;
34+
@property (nonatomic, readonly) TOPasscodeInputField *inputField;
3535
@property (nonatomic, readonly) TOPasscodeKeypadView *keypadView;
3636

3737
/* Overrides for theming the various elements. */

TOPasscodeViewController/Views/Main/TOPasscodeView.m

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ @interface TOPasscodeView ()
1919

2020
@property (nonatomic, strong, readwrite) UILabel *titleLabel;
2121
@property (nonatomic, strong, readwrite) TOPasscodeKeypadView *keypadView;
22-
@property (nonatomic, strong, readwrite) TOPasscodeInputField *numberInputView;
22+
@property (nonatomic, strong, readwrite) TOPasscodeInputField *inputField;
2323

2424
@end
2525

@@ -100,10 +100,10 @@ - (void)layoutSubviews
100100
y = CGRectGetMaxY(frame) + self.currentLayout.titleLabelBottomSpacing;
101101

102102
// Circle Row View
103-
frame = self.numberInputView.frame;
103+
frame = self.inputField.frame;
104104
frame.origin.y = y;
105105
frame.origin.x = midViewSize.width - (CGRectGetWidth(frame) * 0.5f);
106-
self.numberInputView.frame = frame;
106+
self.inputField.frame = frame;
107107

108108
y = CGRectGetMaxY(frame) + self.currentLayout.circleRowBottomSpacing;
109109

@@ -139,7 +139,7 @@ - (void)sizeToFitWidth:(CGFloat)width
139139
- (void)sizeToFit
140140
{
141141
[self.titleLabel sizeToFit];
142-
[self.numberInputView sizeToFit];
142+
[self.inputField sizeToFit];
143143
[self.keypadView sizeToFit];
144144

145145
CGRect frame = self.frame;
@@ -157,7 +157,7 @@ - (void)sizeToFit
157157
frame.size.height += self.currentLayout.titleLabelBottomSpacing;
158158

159159
// Add height for the circle rows
160-
frame.size.height += self.numberInputView.frame.size.height;
160+
frame.size.height += self.inputField.frame.size.height;
161161
frame.size.height += self.currentLayout.circleRowBottomSpacing;
162162

163163
// Add height for the keypad
@@ -182,19 +182,19 @@ - (void)setUpView
182182
[self addSubview:self.titleLabel];
183183

184184
// Set up circle rows
185-
self.numberInputView = [[TOPasscodeInputField alloc] init];
186-
self.numberInputView.passcodeCompletedHandler = ^(NSString *passcode) {
185+
self.inputField = [[TOPasscodeInputField alloc] init];
186+
self.inputField.passcodeCompletedHandler = ^(NSString *passcode) {
187187
if (weakSelf.passcodeCompletedHandler) {
188188
weakSelf.passcodeCompletedHandler(passcode);
189189
}
190190
};
191-
[self addSubview:self.numberInputView];
191+
[self addSubview:self.inputField];
192192

193193
// Set up pad row
194194
self.keypadView = [[TOPasscodeKeypadView alloc] init];
195195
self.keypadView.buttonTappedHandler = ^(NSInteger button) {
196196
NSString *numberString = [NSString stringWithFormat:@"%ld", button];
197-
[weakSelf.numberInputView appendPasscodeCharacters:numberString animated:NO];
197+
[weakSelf.inputField appendPasscodeCharacters:numberString animated:NO];
198198

199199
if (weakSelf.passcodeDigitEnteredHandler) {
200200
weakSelf.passcodeDigitEnteredHandler();
@@ -209,8 +209,8 @@ - (void)updateSubviewsForContentLayout:(TOPasscodeViewContentLayout *)contentLay
209209
self.titleLabel.font = contentLayout.titleLabelFont;
210210

211211
// Circle Row View
212-
self.numberInputView.fixedCircleDiameter = contentLayout.circleRowDiameter;
213-
self.numberInputView.fixedCircleSpacing = contentLayout.circleRowSpacing;
212+
self.inputField.fixedInputView.circleDiameter = contentLayout.circleRowDiameter;
213+
self.inputField.fixedInputView.circleSpacing = contentLayout.circleRowSpacing;
214214

215215
// Keypad
216216
self.keypadView.buttonNumberFont = contentLayout.circleButtonTitleLabelFont;
@@ -237,11 +237,11 @@ - (void)applyThemeForStyle:(TOPasscodeViewStyle)style
237237
if (isTranslucent) {
238238
UIBlurEffect *blurEffect = [self blurEffectForStyle:style];
239239
UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:blurEffect];
240-
self.numberInputView.effect = vibrancyEffect;
240+
self.inputField.effect = vibrancyEffect;
241241
self.keypadView.vibrancyEffect = vibrancyEffect;
242242
}
243243
else {
244-
self.numberInputView.effect = nil;
244+
self.inputField.effect = nil;
245245
self.keypadView.vibrancyEffect = nil;
246246
}
247247

@@ -252,7 +252,7 @@ - (void)applyThemeForStyle:(TOPasscodeViewStyle)style
252252
if (circleRowColor == nil) {
253253
circleRowColor = defaultTintColor;
254254
}
255-
self.numberInputView.tintColor = defaultTintColor;
255+
self.inputField.tintColor = defaultTintColor;
256256

257257
// Set the tint color of the keypad buttons
258258
UIColor *keypadButtonBackgroundColor = self.keypadButtonBackgroundColor;
@@ -284,12 +284,12 @@ - (void)applyThemeForStyle:(TOPasscodeViewStyle)style
284284
#pragma mark - Passcode Management -
285285
- (void)resetPasscodeAnimated:(BOOL)animated playImpact:(BOOL)impact
286286
{
287-
[self.numberInputView resetPasscodeAnimated:animated playImpact:impact];
287+
[self.inputField resetPasscodeAnimated:animated playImpact:impact];
288288
}
289289

290290
- (void)deleteLastPasscodeCharacterAnimated:(BOOL)animated
291291
{
292-
[self.numberInputView deletePasscodeCharactersOfCount:1 animated:animated];
292+
[self.inputField deletePasscodeCharactersOfCount:1 animated:animated];
293293
}
294294

295295
#pragma mark - Internal Style Management -
@@ -359,20 +359,20 @@ - (void)setContentAlpha:(CGFloat)contentAlpha
359359

360360
self.titleView.alpha = contentAlpha;
361361
self.titleLabel.alpha = contentAlpha;
362-
self.numberInputView.contentAlpha = contentAlpha;
362+
self.inputField.contentAlpha = contentAlpha;
363363
self.keypadView.contentAlpha = contentAlpha;
364364
self.leftButton.alpha = contentAlpha;
365365
self.rightButton.alpha = contentAlpha;
366366
}
367367

368368
- (void)setPasscode:(NSString *)passcode
369369
{
370-
[self.numberInputView setPasscode:passcode];
370+
[self.inputField setPasscode:passcode];
371371
}
372372

373373
- (NSString *)passcode
374374
{
375-
return self.numberInputView.passcode;
375+
return self.inputField.passcode;
376376
}
377377

378378
@end

TOPasscodeViewController/Views/Shared/TOPasscodeInputField.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,27 @@
88

99
#import <UIKit/UIKit.h>
1010

11+
#import "TOPasscodeFixedInputView.h"
12+
#import "TOPasscodeVariableInputView.h"
13+
14+
1115
NS_ASSUME_NONNULL_BEGIN
1216

1317
typedef NS_ENUM(NSInteger, TOPasscodeInputFieldStyle) {
1418
TOPasscodeInputFieldStyleFixed, // The passcode explicitly requires a specific number of characters (Shows hollow circles)
1519
TOPasscodeInputFieldStyleVariable // The passcode can be any arbitrary number of characters (Shows an empty rectangle)
1620
};
1721

18-
@class TOPasscodeFixedInputView;
19-
@class TOPasscodeVariableInputView;
20-
2122
@interface TOPasscodeInputField : UIVisualEffectView <UIKeyInput>
2223

2324
/* The input style of this control */
2425
@property (nonatomic, assign) TOPasscodeInputFieldStyle style;
2526

26-
/* The size of each circle in this view (Default is 16) */
27-
@property (nonatomic, assign) CGFloat fixedCircleDiameter;
28-
29-
/* The spacing between each circle (Default is 25.0f) */
30-
@property (nonatomic, assign) CGFloat fixedCircleSpacing;
27+
/* A row of hollow circles at a preset length. Valid only when `style` is set to `fixed` */
28+
@property (nonatomic, readonly, nullable) TOPasscodeFixedInputView *fixedInputView;
3129

32-
/* The number of circles in this view (Default is 4) */
33-
@property (nonatomic, assign) NSInteger fixedLength;
30+
/* A rounded rectangle representing a password of arbitrary length. Valid only when `style` is set to `variable`. */
31+
@property (nonatomic, readonly, nullable) TOPasscodeVariableInputView *variableInputView;
3432

3533
/* The current passcode entered into this view */
3634
@property (nonatomic, copy, nullable) NSString *passcode;
@@ -41,7 +39,7 @@ typedef NS_ENUM(NSInteger, TOPasscodeInputFieldStyle) {
4139
/* The alpha value of the views in this view (For tranclucent styling) */
4240
@property (nonatomic, assign) CGFloat contentAlpha;
4341

44-
/** Called when the number of digits has been entered */
42+
/** Called when the number of digits has been entered, or the user tapped 'Done' on the keyboard */
4543
@property (nonatomic, copy) void (^passcodeCompletedHandler)(NSString *code);
4644

4745
/* Init with the target length needed for this passcode */

0 commit comments

Comments
 (0)