37
37
38
38
@implementation PFLogInView
39
39
40
- #pragma mark -
41
- #pragma mark Class
40
+ // /--------------------------------------
41
+ #pragma mark - Class
42
+ // /--------------------------------------
42
43
43
44
+ (PFActionButtonConfiguration *)_defaultSignUpButtonConfiguration {
44
45
PFActionButtonConfiguration *configuration = [[PFActionButtonConfiguration alloc ] initWithBackgroundImageColor: [PFColor signupButtonBackgroundColor ]
@@ -76,8 +77,9 @@ + (PFActionButtonConfiguration *)_defaultTwitterButtonConfiguration {
76
77
return configuration;
77
78
}
78
79
79
- #pragma mark -
80
- #pragma mark Init
80
+ // /--------------------------------------
81
+ #pragma mark - Init
82
+ // /--------------------------------------
81
83
82
84
- (instancetype )initWithFields : (PFLogInFields)otherFields {
83
85
self = [super initWithFrame: CGRectZero ];
@@ -94,67 +96,116 @@ - (instancetype)initWithFields:(PFLogInFields)otherFields {
94
96
_logo.contentMode = UIViewContentModeScaleAspectFit;
95
97
[self addSubview: _logo];
96
98
99
+ [self _updateAllFields ];
100
+
101
+ return self;
102
+ }
103
+
104
+ // /--------------------------------------
105
+ #pragma mark - Fields
106
+ // /--------------------------------------
107
+
108
+ - (void )_updateAllFields {
97
109
if (_fields & PFLogInFieldsDismissButton) {
98
- _dismissButton = [[PFDismissButton alloc ] initWithFrame: CGRectZero ];
99
- [self addSubview: _dismissButton];
110
+ if (!_dismissButton) {
111
+ _dismissButton = [[PFDismissButton alloc ] initWithFrame: CGRectZero ];
112
+ [self addSubview: _dismissButton];
113
+ }
114
+ } else {
115
+ [_dismissButton removeFromSuperview ];
116
+ _dismissButton = nil ;
100
117
}
101
118
102
119
if (_fields & PFLogInFieldsUsernameAndPassword) {
103
- _usernameField = [[PFTextField alloc ] initWithFrame: CGRectZero
104
- separatorStyle: (PFTextFieldSeparatorStyleTop |
105
- PFTextFieldSeparatorStyleBottom)];
106
- _usernameField.autocorrectionType = UITextAutocorrectionTypeNo;
107
- _usernameField.autocapitalizationType = UITextAutocapitalizationTypeNone;
108
- _usernameField.returnKeyType = UIReturnKeyNext;
109
- [self addSubview: _usernameField];
110
- [self _updateUsernameFieldStyle ];
120
+ if (!_usernameField) {
121
+ _usernameField = [[PFTextField alloc ] initWithFrame: CGRectZero
122
+ separatorStyle: (PFTextFieldSeparatorStyleTop |
123
+ PFTextFieldSeparatorStyleBottom)];
124
+ _usernameField.autocorrectionType = UITextAutocorrectionTypeNo;
125
+ _usernameField.autocapitalizationType = UITextAutocapitalizationTypeNone;
126
+ _usernameField.returnKeyType = UIReturnKeyNext;
127
+ [self addSubview: _usernameField];
128
+ [self _updateUsernameFieldStyle ];
129
+ }
111
130
112
- _passwordField = [[PFTextField alloc ] initWithFrame: CGRectZero
113
- separatorStyle: PFTextFieldSeparatorStyleBottom];
114
- _passwordField.placeholder = NSLocalizedString(@" Password" , @" Password" );
115
- _passwordField.secureTextEntry = YES ;
116
- _passwordField.autocorrectionType = UITextAutocorrectionTypeNo;
117
- _passwordField.autocapitalizationType = UITextAutocapitalizationTypeNone;
118
- _passwordField.returnKeyType = UIReturnKeyDone;
119
- [self addSubview: _passwordField];
131
+ if (!_passwordField) {
132
+ _passwordField = [[PFTextField alloc ] initWithFrame: CGRectZero
133
+ separatorStyle: PFTextFieldSeparatorStyleBottom];
134
+ _passwordField.placeholder = NSLocalizedString(@" Password" , @" Password" );
135
+ _passwordField.secureTextEntry = YES ;
136
+ _passwordField.autocorrectionType = UITextAutocorrectionTypeNo;
137
+ _passwordField.autocapitalizationType = UITextAutocapitalizationTypeNone;
138
+ _passwordField.returnKeyType = UIReturnKeyDone;
139
+ [self addSubview: _passwordField];
140
+ }
141
+ } else {
142
+ [_usernameField removeFromSuperview ];
143
+ _usernameField = nil ;
144
+
145
+ [_passwordField removeFromSuperview ];
146
+ _passwordField = nil ;
120
147
}
121
148
122
149
if (_fields & PFLogInFieldsSignUpButton) {
123
- _signUpButton = [[PFActionButton alloc ] initWithConfiguration: [[self class ] _defaultSignUpButtonConfiguration ]
124
- buttonStyle: PFActionButtonStyleNormal];
125
- [self addSubview: _signUpButton];
150
+ if (!_signUpButton) {
151
+ _signUpButton = [[PFActionButton alloc ] initWithConfiguration: [[self class ] _defaultSignUpButtonConfiguration ]
152
+ buttonStyle: PFActionButtonStyleNormal];
153
+ [self addSubview: _signUpButton];
154
+ }
155
+ } else {
156
+ [_signUpButton removeFromSuperview ];
157
+ _signUpButton = nil ;
126
158
}
127
159
128
160
if (_fields & PFLogInFieldsPasswordForgotten) {
129
- _passwordForgottenButton = [[PFTextButton alloc ] initWithFrame: CGRectZero ];
130
- [_passwordForgottenButton setTitle: NSLocalizedString(@" Forgot Password?" , " Forgot Password?" )
131
- forState: UIControlStateNormal];
132
- [self addSubview: _passwordForgottenButton];
161
+ if (_passwordForgottenButton) {
162
+ _passwordForgottenButton = [[PFTextButton alloc ] initWithFrame: CGRectZero ];
163
+ [_passwordForgottenButton setTitle: NSLocalizedString(@" Forgot Password?" , " Forgot Password?" )
164
+ forState: UIControlStateNormal];
165
+ [self addSubview: _passwordForgottenButton];
166
+ }
167
+ } else {
168
+ [_passwordForgottenButton removeFromSuperview ];
169
+ _passwordForgottenButton = nil ;
133
170
}
134
171
135
172
if (_fields & PFLogInFieldsLogInButton) {
136
- _logInButton = [[PFPrimaryButton alloc ] initWithBackgroundImageColor: [PFColor loginButtonBackgroundColor ]];
137
- [_logInButton setTitle: NSLocalizedString(@" Log In" , @" Log In" ) forState: UIControlStateNormal];
138
- [self addSubview: _logInButton];
173
+ if (!_logInButton) {
174
+ _logInButton = [[PFPrimaryButton alloc ] initWithBackgroundImageColor: [PFColor loginButtonBackgroundColor ]];
175
+ [_logInButton setTitle: NSLocalizedString(@" Log In" , @" Log In" ) forState: UIControlStateNormal];
176
+ [self addSubview: _logInButton];
177
+ }
178
+ } else {
179
+ [_logInButton removeFromSuperview ];
180
+ _logInButton = nil ;
139
181
}
140
182
141
183
if (_fields & PFLogInFieldsFacebook) {
142
- _facebookButton = [[PFActionButton alloc ] initWithConfiguration: [[self class ] _defaultFacebookButtonConfiguration ]
143
- buttonStyle: PFActionButtonStyleNormal];
144
- [self addSubview: _facebookButton];
184
+ if (!_facebookButton) {
185
+ _facebookButton = [[PFActionButton alloc ] initWithConfiguration: [[self class ] _defaultFacebookButtonConfiguration ]
186
+ buttonStyle: PFActionButtonStyleNormal];
187
+ [self addSubview: _facebookButton];
188
+ }
189
+ } else {
190
+ [_facebookButton removeFromSuperview ];
191
+ _facebookButton = nil ;
145
192
}
146
193
147
194
if (_fields & PFLogInFieldsTwitter) {
148
- _twitterButton = [[PFActionButton alloc ] initWithConfiguration: [[self class ] _defaultTwitterButtonConfiguration ]
149
- buttonStyle: PFActionButtonStyleNormal];
150
- [self addSubview: _twitterButton];
195
+ if (_twitterButton) {
196
+ _twitterButton = [[PFActionButton alloc ] initWithConfiguration: [[self class ] _defaultTwitterButtonConfiguration ]
197
+ buttonStyle: PFActionButtonStyleNormal];
198
+ [self addSubview: _twitterButton];
199
+ }
200
+ } else {
201
+ [_twitterButton removeFromSuperview ];
202
+ _twitterButton = nil ;
151
203
}
152
-
153
- return self;
154
204
}
155
205
156
- #pragma mark -
157
- #pragma mark UIView
206
+ // /--------------------------------------
207
+ #pragma mark - UIView
208
+ // /--------------------------------------
158
209
159
210
- (void )layoutSubviews {
160
211
[super layoutSubviews ];
@@ -285,8 +336,7 @@ - (void)layoutSubviews {
285
336
if (_logInButton) {
286
337
CGFloat loginButtonTopInset = floorf (24 .0f * contentSizeScale.height );
287
338
288
- CGRect frame = PFRectMakeWithSizeCenteredInRect ([_logInButton sizeThatFits: loginContentSize],
289
- loginContentRect);;
339
+ CGRect frame = PFRectMakeWithSizeCenteredInRect ([_logInButton sizeThatFits: loginContentSize], loginContentRect);
290
340
frame.origin .y = currentY + loginButtonTopInset;
291
341
_logInButton.frame = frame;
292
342
@@ -350,9 +400,7 @@ - (CGSize)_loginContentSizeThatFits:(CGSize)boundingSize withContentSizeScale:(C
350
400
}
351
401
352
402
- (CGSize )_maxContentSize {
353
- return (UI_USER_INTERFACE_IDIOM () == UIUserInterfaceIdiomPad ?
354
- CGSizeMake (420 .0f , 550 .0f ) :
355
- CGSizeMake (500 .0f , 800 .0f ));
403
+ return (UI_USER_INTERFACE_IDIOM () == UIUserInterfaceIdiomPad ? CGSizeMake (420 .0f , 550 .0f ) : CGSizeMake (500 .0f , 800 .0f ));
356
404
}
357
405
358
406
- (CGSize )_contentSizeScaleForContentSize : (CGSize )contentSize {
@@ -367,8 +415,17 @@ - (CGSize)_contentSizeScaleForContentSize:(CGSize)contentSize {
367
415
return contentSizeScale;
368
416
}
369
417
370
- #pragma mark -
371
- #pragma mark Accessors
418
+ // /--------------------------------------
419
+ #pragma mark - Accessors
420
+ // /--------------------------------------
421
+
422
+ - (void )setFields : (PFLogInFields)fields {
423
+ if (_fields != fields) {
424
+ _fields = fields;
425
+ [self _updateAllFields ];
426
+ [self setNeedsLayout ];
427
+ }
428
+ }
372
429
373
430
- (void )setLogo : (UIView *)logo {
374
431
if (self.logo != logo) {
@@ -388,8 +445,9 @@ - (void)setEmailAsUsername:(BOOL)otherEmailAsUsername {
388
445
}
389
446
}
390
447
391
- #pragma mark -
392
- #pragma mark Private
448
+ // /--------------------------------------
449
+ #pragma mark - Private
450
+ // /--------------------------------------
393
451
394
452
+ (void )_validateFields : (PFLogInFields)fields {
395
453
if (fields == PFLogInFieldsNone) {
0 commit comments