-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathTOPasscodeViewController.m
More file actions
executable file
·689 lines (567 loc) · 23.8 KB
/
TOPasscodeViewController.m
File metadata and controls
executable file
·689 lines (567 loc) · 23.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
//
// TOPasscodeViewController.m
//
// Copyright 2017 Timothy Oliver. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#import "TOPasscodeViewController.h"
#import "TOPasscodeView.h"
#import "TOPasscodeViewControllerAnimatedTransitioning.h"
#import "TOPasscodeKeypadView.h"
#import "TOPasscodeInputField.h"
@interface TOPasscodeViewController () <UIViewControllerTransitioningDelegate>
/* State */
@property (nonatomic, assign, readwrite) TOPasscodeType passcodeType;
@property (nonatomic, assign) CGFloat keyboardHeight;
@property (nonatomic, assign) BOOL passcodeSuccess;
@property (nonatomic, readonly) UIView *leftButton;
@property (nonatomic, readonly) UIView *rightButton;
/* Views */
@property (nonatomic, strong, readwrite) UIVisualEffectView *backgroundEffectView;
@property (nonatomic, strong, readwrite) UIView *backgroundView;
@property (nonatomic, strong, readwrite) TOPasscodeView *passcodeView;
@property (nonatomic, strong, readwrite) UIButton *biometricButton;
@property (nonatomic, strong, readwrite) UIButton *cancelButton;
@end
@implementation TOPasscodeViewController
#pragma mark - Instance Creation -
- (instancetype)initWithStyle:(TOPasscodeViewStyle)style passcodeType:(TOPasscodeType)type
{
if (self = [super initWithNibName:nil bundle:nil]) {
_style = style;
_passcodeType = type;
[self setUp];
}
return self;
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
[self setUp];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
}
#pragma mark - View Setup -
- (void)setUp
{
self.transitioningDelegate = self;
self.automaticallyPromptForBiometricValidation = NO;
self.allowCancel = YES;
if (TOPasscodeViewStyleIsTranslucent(self.style)) {
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
}
else {
self.modalPresentationStyle = UIModalPresentationFullScreen;
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:)
name:UIKeyboardWillChangeFrameNotification object:nil];
}
- (void)setUpBackgroundEffectViewForStyle:(TOPasscodeViewStyle)style
{
BOOL translucent = TOPasscodeViewStyleIsTranslucent(style);
// Return if it already exists when it should
if (translucent && self.backgroundEffectView) { return; }
// Return if it doesn't exist when it shouldn't
if (!translucent && !self.backgroundEffectView) { return; }
// Remove it if we're now opaque
if (!translucent) {
[self.backgroundEffectView removeFromSuperview];
self.backgroundEffectView = nil;
return;
}
// Create it otherwise
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:[self blurEffectStyleForStyle:style]];
self.backgroundEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
self.backgroundEffectView.frame = self.view.bounds;
self.backgroundEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view insertSubview:self.backgroundEffectView atIndex:0];
}
- (void)setUpBackgroundViewForStyle:(TOPasscodeViewStyle)style
{
BOOL translucent = TOPasscodeViewStyleIsTranslucent(style);
if (!translucent && self.backgroundView) { return; }
if (translucent && !self.backgroundView) { return; }
if (translucent) {
[self.backgroundView removeFromSuperview];
self.backgroundView = nil;
return;
}
self.backgroundView = [[UIView alloc] initWithFrame:self.view.bounds];
self.backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view insertSubview:self.backgroundView atIndex:0];
}
- (UIBlurEffectStyle)blurEffectStyleForStyle:(TOPasscodeViewStyle)style
{
switch (self.style) {
case TOPasscodeViewStyleTranslucentDark: return UIBlurEffectStyleDark;
case TOPasscodeViewStyleTranslucentLight: return UIBlurEffectStyleExtraLight;
default: return 0;
}
return 0;
}
- (void)setUpAccessoryButtons
{
UIFont *buttonFont = [UIFont systemFontOfSize:16.0f];
BOOL isPad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
if (!self.leftAccessoryButton && self.allowBiometricValidation && !self.biometricButton) {
self.biometricButton = [UIButton buttonWithType:UIButtonTypeSystem];
[self.biometricButton setTitle:TOPasscodeBiometryTitleForType(self.biometryType) forState:UIControlStateNormal];
[self.biometricButton addTarget:self action:@selector(accessoryButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
if (isPad) {
self.passcodeView.leftButton = self.biometricButton;
}
else {
[self.view addSubview:self.biometricButton];
}
}
else {
if (self.leftAccessoryButton) {
[self.biometricButton removeFromSuperview];
self.biometricButton = nil;
}
}
if (!self.rightAccessoryButton && !self.cancelButton) {
self.cancelButton = [UIButton buttonWithType:UIButtonTypeSystem];
[self.cancelButton setTitle:NSLocalizedString(@"Cancel", @"Cancel") forState:UIControlStateNormal];
self.cancelButton.titleLabel.font = buttonFont;
[self.cancelButton addTarget:self action:@selector(accessoryButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
// If cancelling is disabled, we hide the cancel button but we still create it, because it can
// transition to backspace after user input.
self.cancelButton.hidden = !self.allowCancel;
if (isPad) {
self.passcodeView.rightButton = self.cancelButton;
}
else {
[self.view addSubview:self.cancelButton];
}
}
else {
if (self.rightAccessoryButton) {
[self.cancelButton removeFromSuperview];
self.cancelButton = nil;
}
}
[self updateAccessoryButtonFontsForSize:self.view.bounds.size];
}
#pragma mark - View Management -
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
self.view.layer.allowsGroupOpacity = NO;
[self setUpBackgroundEffectViewForStyle:self.style];
[self setUpBackgroundViewForStyle:self.style];
[self setUpAccessoryButtons];
[self applyThemeForStyle:self.style];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// Automatically trigger biometric validation if available
if (self.allowBiometricValidation && self.automaticallyPromptForBiometricValidation) {
[self accessoryButtonTapped:self.biometricButton];
}
}
- (void)viewDidLayoutSubviews
{
CGSize bounds = self.view.bounds.size;
CGSize maxSize = bounds;
if (@available(iOS 11.0, *)) {
UIEdgeInsets safeAreaInsets = self.view.safeAreaInsets;
if (safeAreaInsets.bottom > 0) {
maxSize.height -= safeAreaInsets.bottom;
}
if (safeAreaInsets.left > 0) {
maxSize.width -= safeAreaInsets.left;
}
if (safeAreaInsets.right > 0) {
maxSize.width -= safeAreaInsets.right;
}
}
// Resize the pin view to scale to the new size
[self.passcodeView sizeToFitSize:maxSize];
// Re-center the pin view
CGRect frame = self.passcodeView.frame;
frame.origin.x = (bounds.width - frame.size.width) * 0.5f;
frame.origin.y = ((bounds.height - self.keyboardHeight) - frame.size.height) * 0.5f;
self.passcodeView.frame = CGRectIntegral(frame);
// --------------------------------------------------
// Update the accessory button sizes
[self updateAccessoryButtonFontsForSize:maxSize];
// Re-layout the accessory buttons
[self layoutAccessoryButtonsForSize:maxSize];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setNeedsStatusBarAppearanceUpdate];
// Force an initial layout if the view hasn't been presented yet
[UIView performWithoutAnimation:^{
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
}];
// Show the keyboard if we're entering alphanumeric characters
if (self.passcodeType == TOPasscodeTypeCustomAlphanumeric) {
[self.passcodeView.inputField becomeFirstResponder];
}
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// Dismiss the keyboard if it is visible
if (self.passcodeView.inputField.isFirstResponder) {
[self.passcodeView.inputField resignFirstResponder];
}
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
return TOPasscodeViewStyleIsDark(self.style) ? UIStatusBarStyleLightContent : UIStatusBarStyleDefault;
}
#pragma mark - View Rotations -
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
// We don't need to do anything special on iPad or if we're using character input
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad || self.passcodeType == TOPasscodeTypeCustomAlphanumeric) { return; }
// Work out if we need to transition to horizontal
BOOL horizontalLayout = size.height < size.width;
// Perform layout animation
[self.passcodeView setHorizontalLayout:horizontalLayout animated:coordinator.animated duration:coordinator.transitionDuration];
}
#pragma mark - View Styling -
- (void)applyThemeForStyle:(TOPasscodeViewStyle)style
{
BOOL isDark = TOPasscodeViewStyleIsDark(style);
// Apply the tint color to the accessory buttons
UIColor *accessoryTintColor = self.accessoryButtonTintColor;
if (!accessoryTintColor) {
accessoryTintColor = isDark ? [UIColor whiteColor] : nil;
}
self.biometricButton.tintColor = accessoryTintColor;
self.cancelButton.tintColor = accessoryTintColor;
self.leftAccessoryButton.tintColor = accessoryTintColor;
self.rightAccessoryButton.tintColor = accessoryTintColor;
self.backgroundView.backgroundColor = isDark ? [UIColor colorWithWhite:0.1f alpha:1.0f] : [UIColor whiteColor];
}
- (void)updateAccessoryButtonFontsForSize:(CGSize)size
{
CGFloat width = size.width;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
width = MIN(size.width, size.height);
}
CGFloat pointSize = 17.0f;
if (width < TOPasscodeViewContentSizeMedium) {
pointSize = 14.0f;
}
else if (width < TOPasscodeViewContentSizeDefault) {
pointSize = 16.0f;
}
UIFont *accessoryFont = [UIFont systemFontOfSize:pointSize];
self.biometricButton.titleLabel.font = accessoryFont;
self.cancelButton.titleLabel.font = accessoryFont;
self.leftAccessoryButton.titleLabel.font = accessoryFont;
self.rightAccessoryButton.titleLabel.font = accessoryFont;
}
- (void)verticalLayoutAccessoryButtonsForSize:(CGSize)size
{
CGFloat width = MIN(size.width, size.height);
CGFloat verticalInset = 54.0f;
if (width < TOPasscodeViewContentSizeMedium) {
verticalInset = 37.0f;
}
else if (width < TOPasscodeViewContentSizeDefault) {
verticalInset = 43.0f;
}
CGFloat inset = self.passcodeView.keypadButtonInset;
CGPoint point = (CGPoint){0.0f, (self.view.bounds.size.height - self.keyboardHeight) - verticalInset};
if (@available(iOS 11.0, *)) {
UIEdgeInsets safeAreaInsets = self.view.safeAreaInsets;
if (safeAreaInsets.bottom > 0) {
point.y -= safeAreaInsets.bottom;
}
}
if (self.leftButton) {
[self.leftButton sizeToFit];
point.x = self.passcodeView.frame.origin.x + inset;
self.leftButton.center = point;
}
if (self.rightButton) {
[self.rightButton sizeToFit];
point.x = CGRectGetMaxX(self.passcodeView.frame) - inset;
self.rightButton.center = point;
}
}
- (void)horizontalLayoutAccessoryButtonsForSize:(CGSize)size
{
CGRect passcodeViewFrame = self.passcodeView.frame;
CGFloat buttonInset = self.passcodeView.keypadButtonInset;
CGFloat width = MIN(size.width, size.height);
CGFloat verticalInset = 35.0f;
if (width < TOPasscodeViewContentSizeMedium) {
verticalInset = 30.0f;
}
else if (width < TOPasscodeViewContentSizeDefault) {
verticalInset = 35.0f;
}
if (self.leftButton) {
[self.leftButton sizeToFit];
CGRect frame = self.leftButton.frame;
frame.origin.y = (self.view.bounds.size.height - verticalInset) - (frame.size.height * 0.5f);
frame.origin.x = (CGRectGetMaxX(passcodeViewFrame) - buttonInset) - (frame.size.width * 0.5f);
self.leftButton.frame = CGRectIntegral(frame);
}
if (self.rightButton) {
[self.rightButton sizeToFit];
CGRect frame = self.rightButton.frame;
frame.origin.y = verticalInset - (frame.size.height * 0.5f);
frame.origin.x = (CGRectGetMaxX(passcodeViewFrame) - buttonInset) - (frame.size.width * 0.5f);
self.rightButton.frame = CGRectIntegral(frame);
}
[self.view bringSubviewToFront:self.rightButton];
[self.view bringSubviewToFront:self.leftButton];
}
- (void)layoutAccessoryButtonsForSize:(CGSize)size
{
// The buttons are always embedded in the keypad view on iPad
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone) { return; }
if (self.passcodeView.horizontalLayout && self.passcodeType != TOPasscodeTypeCustomAlphanumeric) {
[self horizontalLayoutAccessoryButtonsForSize:size];
}
else {
[self verticalLayoutAccessoryButtonsForSize:size];
}
}
#pragma mark - Interactions -
- (void)accessoryButtonTapped:(id)sender
{
if (sender == self.cancelButton) {
// When entering keyboard input, just leave the button as 'cancel'
if (self.passcodeType != TOPasscodeTypeCustomAlphanumeric && self.passcodeView.passcode.length > 0) {
[self.passcodeView deleteLastPasscodeCharacterAnimated:YES];
[self keypadButtonTapped];
return;
}
if ([self.delegate respondsToSelector:@selector(didTapCancelInPasscodeViewController:)]) {
[self.delegate didTapCancelInPasscodeViewController:self];
}
}
else if (sender == self.biometricButton) {
if ([self.delegate respondsToSelector:@selector(didPerformBiometricValidationRequestInPasscodeViewController:)]) {
[self.delegate didPerformBiometricValidationRequestInPasscodeViewController:self];
}
}
}
- (void)keypadButtonTapped
{
NSString *title = nil;
if (self.passcodeView.passcode.length > 0) {
title = NSLocalizedString(@"Delete", @"Delete");
} else if (self.allowCancel) {
title = NSLocalizedString(@"Cancel", @"Cancel");
}
[UIView performWithoutAnimation:^{
if (title != nil) {
[self.cancelButton setTitle:title forState:UIControlStateNormal];
[self.cancelButton sizeToFit];
[self.cancelButton layoutIfNeeded];
}
self.cancelButton.hidden = (title == nil);
}];
}
- (void)didCompleteEnteringPasscode:(NSString *)passcode
{
if (![self.delegate respondsToSelector:@selector(passcodeViewController:isCorrectCode:)]) {
return;
}
// Validate the code
BOOL isCorrect = [self.delegate passcodeViewController:self isCorrectCode:passcode];
if (!isCorrect) {
[self.passcodeView resetPasscodeAnimated:YES playImpact:YES];
return;
}
// Hang onto the fact the passcode was successful to play a nicer dismissal animation
self.passcodeSuccess = YES;
// Perform handler if correctly entered
if ([self.delegate respondsToSelector:@selector(didInputCorrectPasscodeInPasscodeViewController:)]) {
[self.delegate didInputCorrectPasscodeInPasscodeViewController:self];
}
else {
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
}
#pragma mark - Keyboard Handling -
- (void)keyboardWillChangeFrame:(NSNotification *)notification
{
// Extract the keyboard information we need from the notification
CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat animationDuration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
UIViewAnimationOptions animationCurve = [notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
// Work out the on-screen height of the keyboard
self.keyboardHeight = self.view.bounds.size.height - keyboardFrame.origin.y;
self.keyboardHeight = MAX(self.keyboardHeight, 0.0f);
// Set that the view needs to be laid out
[self.view setNeedsLayout];
if (animationDuration < FLT_EPSILON) {
return;
}
// Animate the content sliding up and down with the keyboard
[UIView animateWithDuration:animationDuration
delay:0.0f
options:animationCurve
animations:^{ [self.view layoutIfNeeded]; }
completion:nil];
}
#pragma mark - Transitioning Delegate -
- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source
{
return [[TOPasscodeViewControllerAnimatedTransitioning alloc] initWithPasscodeViewController:self dismissing:NO success:NO];
}
- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed
{
return [[TOPasscodeViewControllerAnimatedTransitioning alloc] initWithPasscodeViewController:self dismissing:YES success:self.passcodeSuccess];
}
#pragma mark - Convenience Accessors -
- (UIView *)leftButton
{
return self.leftAccessoryButton ? self.leftAccessoryButton : self.biometricButton;
}
- (UIView *)rightButton
{
return self.rightAccessoryButton ? self.rightAccessoryButton : self.cancelButton;
}
#pragma mark - Public Accessors -
- (TOPasscodeView *)passcodeView
{
if (_passcodeView) { return _passcodeView; }
_passcodeView = [[TOPasscodeView alloc] initWithStyle:self.style passcodeType:self.passcodeType];
_passcodeView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin |
UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[_passcodeView sizeToFit];
_passcodeView.center = self.view.center;
[self.view addSubview:_passcodeView];
__weak typeof(self) weakSelf = self;
_passcodeView.passcodeCompletedHandler = ^(NSString *passcode) {
[weakSelf didCompleteEnteringPasscode:passcode];
};
_passcodeView.passcodeDigitEnteredHandler = ^{
[weakSelf keypadButtonTapped];
};
// Set initial layout to horizontal if we're rotated on an iPhone
if (self.passcodeType != TOPasscodeTypeCustomAlphanumeric && UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) {
CGSize boundsSize = self.view.bounds.size;
_passcodeView.horizontalLayout = boundsSize.width > boundsSize.height;
}
return _passcodeView;
}
- (void)setStyle:(TOPasscodeViewStyle)style
{
if (style == _style) { return; }
_style = style;
self.passcodeView.style = style;
[self setUpBackgroundEffectViewForStyle:style];
}
- (void)setAllowBiometricValidation:(BOOL)allowBiometricValidation
{
if (_allowBiometricValidation == allowBiometricValidation) {
return;
}
_allowBiometricValidation = allowBiometricValidation;
[self setUpAccessoryButtons];
[self applyThemeForStyle:self.style];
}
- (void)setTitleLabelColor:(UIColor *)titleLabelColor
{
self.passcodeView.titleLabelColor = titleLabelColor;
}
- (UIColor *)titleLabelColor { return self.passcodeView.titleLabelColor; }
- (void)setInputProgressViewTintColor:(UIColor *)inputProgressViewTintColor
{
self.passcodeView.inputProgressViewTintColor = inputProgressViewTintColor;
}
- (UIColor *)inputProgressViewTintColor { return self.passcodeView.inputProgressViewTintColor; }
- (void)setKeypadButtonBackgroundTintColor:(UIColor *)keypadButtonBackgroundTintColor
{
self.passcodeView.keypadButtonBackgroundColor = keypadButtonBackgroundTintColor;
}
- (void)setKeypadButtonShowLettering:(BOOL)keypadButtonShowLettering
{
self.passcodeView.keypadView.showLettering = keypadButtonShowLettering;
}
- (UIColor *)keypadButtonBackgroundTintColor { return self.passcodeView.keypadButtonBackgroundColor; }
- (void)setKeypadButtonTextColor:(UIColor *)keypadButtonTextColor
{
self.passcodeView.keypadButtonTextColor = keypadButtonTextColor;
}
- (UIColor *)keypadButtonTextColor { return self.passcodeView.keypadButtonTextColor; }
- (void)setKeypadButtonHighlightedTextColor:(UIColor *)keypadButtonHighlightedTextColor
{
self.passcodeView.keypadButtonHighlightedTextColor = keypadButtonHighlightedTextColor;
}
- (UIColor *)keypadButtonHighlightedTextColor { return self.passcodeView.keypadButtonHighlightedTextColor; }
- (void)setAccessoryButtonTintColor:(UIColor *)accessoryButtonTintColor
{
if (accessoryButtonTintColor == _accessoryButtonTintColor) { return; }
_accessoryButtonTintColor = accessoryButtonTintColor;
[self applyThemeForStyle:self.style];
}
- (void)setBiometryType:(TOPasscodeBiometryType)biometryType
{
if (_biometryType == biometryType) { return; }
_biometryType = biometryType;
if (self.biometricButton) {
[self.biometricButton setTitle:TOPasscodeBiometryTitleForType(_biometryType) forState:UIControlStateNormal];
}
}
- (void)setContentHidden:(BOOL)contentHidden
{
[self setContentHidden:contentHidden animated:NO];
}
- (void)setContentHidden:(BOOL)hidden animated:(BOOL)animated
{
if (hidden == _contentHidden) { return; }
_contentHidden = hidden;
void (^setViewsHiddenBlock)(BOOL) = ^(BOOL hidden) {
self.passcodeView.hidden = hidden;
self.leftButton.hidden = hidden;
self.rightButton.hidden = hidden;
};
void (^completionBlock)(BOOL) = ^(BOOL complete) {
setViewsHiddenBlock(hidden);
};
if (!animated) {
completionBlock(YES);
return;
}
// Make sure the views are visible before the animation
setViewsHiddenBlock(NO);
void (^animationBlock)(void) = ^{
CGFloat alpha = hidden ? 0.0f : 1.0f;
self.passcodeView.contentAlpha = alpha;
self.leftButton.alpha = alpha;
self.rightButton.alpha = alpha;
};
// Animate
[UIView animateWithDuration:0.4f animations:animationBlock completion:completionBlock];
}
@end