Skip to content

Commit 9cc3624

Browse files
committed
Added logic for keyboard-based passcode view
1 parent b9677a6 commit 9cc3624

17 files changed

+304
-61
lines changed

TOPasscodeViewController/Models/TOPasscodeViewContentLayout.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@
2626
@property (nonatomic, assign) CGFloat circleRowSpacing; // The spacing between each circle
2727
@property (nonatomic, assign) CGFloat circleRowBottomSpacing; // Space between the view used to indicate input
2828

29+
/* Text Field Configuration */
30+
@property (nonatomic, assign) CGFloat textFieldBorderThickness; // The thickness of the border stroke
31+
@property (nonatomic, assign) CGFloat textFieldBorderRadius; // The corner radius of the border
32+
@property (nonatomic, assign) CGFloat textFieldCircleDiameter; // The size of the circles in the password field
33+
@property (nonatomic, assign) CGFloat textFieldCircleSpacing; // The amount of spacing between each circle
34+
@property (nonatomic, assign) CGSize textFieldBorderPadding; // The amount of padding between the circles and the border
35+
@property (nonatomic, assign) NSInteger textFieldNumericCharacterLength; // The amount of circles to have in this field when set to numeric
36+
@property (nonatomic, assign) NSInteger textFieldAlphanumericCharacterLength; // The amount of circles to have in this field when set to alphanumeric
37+
@property (nonatomic, assign) CGFloat submitButtonFontSize; // The font size of the 'OK' button
38+
@property (nonatomic, assign) CGFloat submitButtonSpacing; // The spacing of the 'OK' button from the input
39+
2940
/* Circle Button Shape and Layout */
3041
@property (nonatomic, assign) CGFloat circleButtonDiameter; // The size of each PIN button
3142
@property (nonatomic, assign) CGSize circleButtonSpacing; // The vertical/horizontal spacing between buttons

TOPasscodeViewController/Models/TOPasscodeViewContentLayout.m

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ + (TOPasscodeViewContentLayout *)defaultScreenContentLayout
2929
contentLayout.circleRowSpacing = 30.0f;
3030
contentLayout.circleRowBottomSpacing = 61.0f;
3131

32+
/* Text Field Input Configuration */
33+
contentLayout.textFieldBorderThickness = 1.5f;
34+
contentLayout.textFieldBorderRadius = 5.0f;
35+
contentLayout.textFieldCircleDiameter = 10.0f;
36+
contentLayout.textFieldCircleSpacing = 6.0f;
37+
contentLayout.textFieldBorderPadding = (CGSize){10, 10};
38+
contentLayout.textFieldNumericCharacterLength = 10;
39+
contentLayout.textFieldAlphanumericCharacterLength = 15;
40+
contentLayout.submitButtonFontSize = 17.0f;
41+
contentLayout.submitButtonSpacing = 4.0f;
42+
3243
/* Circle Button Shape and Layout */
3344
contentLayout.circleButtonDiameter = 81.0f;
3445
contentLayout.circleButtonSpacing = (CGSize){25.0f, 20.0f};
@@ -67,6 +78,15 @@ + (TOPasscodeViewContentLayout *)mediumScreenContentLayout
6778
contentLayout.circleButtonSpacing = (CGSize){28.0f, 15.0f};
6879
contentLayout.circleButtonStrokeWidth = 1.5f;
6980

81+
/* Text Field Input Configuration */
82+
contentLayout.textFieldBorderThickness = 1.5f;
83+
contentLayout.textFieldBorderRadius = 5.0f;
84+
contentLayout.textFieldCircleDiameter = 9.0f;
85+
contentLayout.textFieldCircleSpacing = 5.0f;
86+
contentLayout.textFieldBorderPadding = (CGSize){10, 10};
87+
contentLayout.textFieldNumericCharacterLength = 10;
88+
contentLayout.textFieldAlphanumericCharacterLength = 15;
89+
7090
/* Circle Button Label */
7191
contentLayout.circleButtonTitleLabelFont = [UIFont systemFontOfSize:36.5f weight:UIFontWeightThin];
7292
contentLayout.circleButtonLetteringLabelFont = [UIFont monospacedDigitSystemFontOfSize:8.5f weight:UIFontWeightThin];
@@ -95,6 +115,19 @@ + (TOPasscodeViewContentLayout *)smallScreenContentLayout
95115
contentLayout.circleRowSpacing = 22.0f;
96116
contentLayout.circleRowBottomSpacing = 44.0f;
97117

118+
/* Text Field Input Configuration */
119+
contentLayout.textFieldBorderThickness = 1.5f;
120+
contentLayout.textFieldBorderRadius = 5.0f;
121+
contentLayout.textFieldCircleDiameter = 8.0f;
122+
contentLayout.textFieldCircleSpacing = 4.0f;
123+
contentLayout.textFieldBorderPadding = (CGSize){8, 8};
124+
contentLayout.textFieldNumericCharacterLength = 10;
125+
contentLayout.textFieldAlphanumericCharacterLength = 15;
126+
127+
/* Submit Button */
128+
contentLayout.submitButtonFontSize = 15.0f;
129+
contentLayout.submitButtonSpacing = 3.0f;
130+
98131
/* Circle Button Shape and Layout */
99132
contentLayout.circleButtonDiameter = 64.0f;
100133
contentLayout.circleButtonSpacing = (CGSize){22.0f, 10.5f};

TOPasscodeViewController/TOPasscodeSettingsViewController.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,23 @@ - (void)updateContentForState:(TOPasscodeSettingsViewState)state type:(TOPasscod
212212
case TOPasscodeSettingsViewStateEnterCurrentPassword:
213213
self.titleLabel.text = NSLocalizedString(@"Enter your passcode", @"");
214214
self.navigationItem.rightBarButtonItem = variableSizePasscode ? self.nextBarButtonItem : nil;
215+
self.inputField.returnKeyType = UIReturnKeyContinue;
215216
break;
216217
case TOPasscodeSettingsViewStateEnterNewPassword:
217218
self.titleLabel.text = NSLocalizedString(@"Enter a new passcode", @"");
218219
self.navigationItem.rightBarButtonItem = variableSizePasscode ? self.nextBarButtonItem : nil;
220+
self.inputField.returnKeyType = UIReturnKeyContinue;
219221
break;
220222
case TOPasscodeSettingsViewStateConfirmNewPassword:
221223
self.titleLabel.text = NSLocalizedString(@"Confirm new passcode", @"");
222224
self.navigationItem.rightBarButtonItem = variableSizePasscode ? self.doneBarButtonItem : nil;
225+
self.inputField.returnKeyType = UIReturnKeyDone;
223226
break;
224227
}
225228

229+
// Reload the 'Done' button
230+
[self.inputField reloadInputViews];
231+
226232
// Resize text label to fit new text
227233
[self.titleLabel sizeToFit];
228234
frame = self.titleLabel.frame;

TOPasscodeViewController/TOPasscodeViewController.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ NS_ASSUME_NONNULL_BEGIN
5353
@property (nonatomic, assign) TOPasscodeViewStyle style;
5454

5555
/** The type of passcode that is expected to be entered. */
56-
@property (nonatomic, assign) TOPasscodeType passcodeType;
56+
@property (nonatomic, readonly) TOPasscodeType passcodeType;
5757

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;
@@ -100,8 +100,15 @@ NS_ASSUME_NONNULL_BEGIN
100100
/** The right accessory button. Setting this will override the 'Cancel' button. */
101101
@property (nonatomic, strong, nullable) UIButton *rightAccessoryButton;
102102

103+
/** Whether all of the content views are hidden or not, but the background translucent view remains.
104+
Useful for obscuring the content while the app is suspended. */
105+
@property (nonatomic, assign) BOOL contentHidden;
106+
103107
/** Create a new instance of this view controller with the preset style. */
104-
- (instancetype)initWithStyle:(TOPasscodeViewStyle)style;
108+
- (instancetype)initWithStyle:(TOPasscodeViewStyle)style passcodeType:(TOPasscodeType)type;
109+
110+
/** Hide all of the content views with a crossfade animation */
111+
- (void)setContentHidden:(BOOL)hidden animated:(BOOL)animated;
105112

106113
@end
107114

TOPasscodeViewController/TOPasscodeViewController.m

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ @interface TOPasscodeViewController () <UIViewControllerTransitioningDelegate>
1919
@property (nonatomic, strong, readwrite) TOPasscodeView *passcodeView;
2020
@property (nonatomic, strong, readwrite) UIButton *biometricButton;
2121
@property (nonatomic, strong, readwrite) UIButton *cancelButton;
22+
@property (nonatomic, assign, readwrite) TOPasscodeType passcodeType;
2223

2324
@end
2425

2526
@implementation TOPasscodeViewController
2627

2728
#pragma mark - Instance Creation -
2829

29-
- (instancetype)initWithStyle:(TOPasscodeViewStyle)style
30+
- (instancetype)initWithStyle:(TOPasscodeViewStyle)style passcodeType:(TOPasscodeType)type
3031
{
3132
if (self = [super initWithNibName:nil bundle:nil]) {
3233
_style = style;
34+
_passcodeType = type;
3335
[self setUp];
3436
}
3537

@@ -347,7 +349,7 @@ - (TOPasscodeView *)passcodeView
347349
{
348350
if (_passcodeView) { return _passcodeView; }
349351

350-
_passcodeView = [[TOPasscodeView alloc] initWithStyle:self.style];
352+
_passcodeView = [[TOPasscodeView alloc] initWithStyle:self.style passcodeType:self.passcodeType];
351353
_passcodeView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin |
352354
UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
353355
[_passcodeView sizeToFit];
@@ -366,22 +368,6 @@ - (TOPasscodeView *)passcodeView
366368
return _passcodeView;
367369
}
368370

369-
- (void)setPasscodeType:(TOPasscodeType)passcodeType
370-
{
371-
if (_passcodeType == passcodeType) { return; }
372-
_passcodeType = passcodeType;
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-
382-
[self.passcodeView setNeedsLayout];
383-
}
384-
385371
- (void)setStyle:(TOPasscodeViewStyle)style
386372
{
387373
if (style == _style) { return; }

TOPasscodeViewController/Views/Main/TOPasscodeCircleButton.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ - (void)setBackgroundImage:(UIImage *)backgroundImage
132132
self.circleView.circleImage = backgroundImage;
133133
CGRect frame = self.frame;
134134
frame.size = backgroundImage.size;
135-
self.frame = frame;
135+
self.frame = CGRectIntegral(frame);
136136
}
137137

138138
- (UIImage *)backgroundImage { return self.circleView.circleImage; }

TOPasscodeViewController/Views/Main/TOPasscodeKeypadView.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ - (void)sizeToFit
9191
CGRect frame = self.frame;
9292
frame.size.width = ((self.buttonDiameter + padding) * 3) + (self.buttonSpacing.width * 2);
9393
frame.size.height = ((self.buttonDiameter + padding) * 4) + (self.buttonSpacing.height * 3);
94-
self.frame = frame;
94+
self.frame = CGRectIntegral(frame);
9595
}
9696

9797
- (void)layoutSubviews

TOPasscodeViewController/Views/Main/TOPasscodeView.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ NS_ASSUME_NONNULL_BEGIN
2121
/* The visual style of the view */
2222
@property (nonatomic, assign) TOPasscodeViewStyle style;
2323

24+
/* The type of passcode being managed by it */
25+
@property (nonatomic, readonly) TOPasscodeType passcodeType;
26+
2427
/* The text in the title view (Default is 'Enter Passcode') */
2528
@property (nonatomic, copy) NSString *titleText;
2629

@@ -64,7 +67,7 @@ NS_ASSUME_NONNULL_BEGIN
6467
@property (nonatomic, copy, nullable) void (^passcodeCompletedHandler)(NSString *passcode);
6568

6669
/* Create a new instance with one of the style types */
67-
- (instancetype)initWithStyle:(TOPasscodeViewStyle)style;
70+
- (instancetype)initWithStyle:(TOPasscodeViewStyle)style passcodeType:(TOPasscodeType)type;
6871

6972
/* Resize the view and all subviews for the optimum size to fit a super view of the suplied width. */
7073
- (void)sizeToFitWidth:(CGFloat)width;

0 commit comments

Comments
 (0)