Skip to content
This repository was archived by the owner on Jan 16, 2021. It is now read-only.

Commit 996c99a

Browse files
committed
Merge pull request #135 from ParsePlatform/nlutsenko.login.emailAsUsername
Fixed not set fields when emailAsUsername is set before fields are set.
2 parents 9bf8359 + d48428b commit 996c99a

File tree

4 files changed

+200
-97
lines changed

4 files changed

+200
-97
lines changed

ParseUI.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
810D6C3119F7F379005B3DB2 /* PFProductTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 810D6C2F19F7F379005B3DB2 /* PFProductTableViewController.m */; };
3535
810D6C3419F7F38B005B3DB2 /* PFPurchaseTableViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = 810D6C3219F7F38B005B3DB2 /* PFPurchaseTableViewCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
3636
810D6C3519F7F38B005B3DB2 /* PFPurchaseTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 810D6C3319F7F38B005B3DB2 /* PFPurchaseTableViewCell.m */; };
37+
811EE7A31B8C17550058B3BE /* PFLogInView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 811EE7A21B8C17550058B3BE /* PFLogInView_Private.h */; };
3738
8129E5F21A9CB067006752BC /* ParseUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D2AAC07E0554694100DB518D /* ParseUI.framework */; };
3839
8129E5F31A9CB067006752BC /* (null) in Frameworks */ = {isa = PBXBuildFile; };
3940
8129E5F51A9CB067006752BC /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 81472FA71A1AB37500FD6EED /* Images.xcassets */; };
@@ -151,6 +152,7 @@
151152
810D6C3219F7F38B005B3DB2 /* PFPurchaseTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFPurchaseTableViewCell.h; sourceTree = "<group>"; };
152153
810D6C3319F7F38B005B3DB2 /* PFPurchaseTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PFPurchaseTableViewCell.m; sourceTree = "<group>"; };
153154
811B095A1A0843B9008B3393 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = ParseUI/Resources/Info.plist; sourceTree = SOURCE_ROOT; };
155+
811EE7A21B8C17550058B3BE /* PFLogInView_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PFLogInView_Private.h; sourceTree = "<group>"; };
154156
8129E6001A9CB067006752BC /* ParseUIDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ParseUIDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
155157
8129E6081A9CB1BE006752BC /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
156158
8129E6391A9CB320006752BC /* UIDemoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIDemoViewController.swift; sourceTree = "<group>"; };
@@ -630,6 +632,7 @@
630632
81ED075319F68028009745F4 /* PFLogInViewController.h */,
631633
81ED075419F68028009745F4 /* PFLogInViewController.m */,
632634
81ED075119F68028009745F4 /* PFLogInView.h */,
635+
811EE7A21B8C17550058B3BE /* PFLogInView_Private.h */,
633636
81ED075219F68028009745F4 /* PFLogInView.m */,
634637
);
635638
path = LogInViewController;
@@ -751,6 +754,7 @@
751754
81E9CD1419F56D6B00487B0F /* ParseUIConstants.h in Headers */,
752755
8185BA7C1A642A8B002815C0 /* PFCollectionViewCell.h in Headers */,
753756
810D6C1F19F7F006005B3DB2 /* PFImageCache.h in Headers */,
757+
811EE7A31B8C17550058B3BE /* PFLogInView_Private.h in Headers */,
754758
81E9CD1319F56D6B00487B0F /* ParseUI.h in Headers */,
755759
810D6C3419F7F38B005B3DB2 /* PFPurchaseTableViewCell.h in Headers */,
756760
81ED079619F6809F009745F4 /* PFImageView.h in Headers */,

ParseUI/Classes/LogInViewController/PFLogInView.m

+109-51
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737

3838
@implementation PFLogInView
3939

40-
#pragma mark -
41-
#pragma mark Class
40+
///--------------------------------------
41+
#pragma mark - Class
42+
///--------------------------------------
4243

4344
+ (PFActionButtonConfiguration *)_defaultSignUpButtonConfiguration {
4445
PFActionButtonConfiguration *configuration = [[PFActionButtonConfiguration alloc] initWithBackgroundImageColor:[PFColor signupButtonBackgroundColor]
@@ -76,8 +77,9 @@ + (PFActionButtonConfiguration *)_defaultTwitterButtonConfiguration {
7677
return configuration;
7778
}
7879

79-
#pragma mark -
80-
#pragma mark Init
80+
///--------------------------------------
81+
#pragma mark - Init
82+
///--------------------------------------
8183

8284
- (instancetype)initWithFields:(PFLogInFields)otherFields {
8385
self = [super initWithFrame:CGRectZero];
@@ -94,67 +96,116 @@ - (instancetype)initWithFields:(PFLogInFields)otherFields {
9496
_logo.contentMode = UIViewContentModeScaleAspectFit;
9597
[self addSubview:_logo];
9698

99+
[self _updateAllFields];
100+
101+
return self;
102+
}
103+
104+
///--------------------------------------
105+
#pragma mark - Fields
106+
///--------------------------------------
107+
108+
- (void)_updateAllFields {
97109
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;
100117
}
101118

102119
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+
}
111130

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;
120147
}
121148

122149
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;
126158
}
127159

128160
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;
133170
}
134171

135172
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;
139181
}
140182

141183
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;
145192
}
146193

147194
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;
151203
}
152-
153-
return self;
154204
}
155205

156-
#pragma mark -
157-
#pragma mark UIView
206+
///--------------------------------------
207+
#pragma mark - UIView
208+
///--------------------------------------
158209

159210
- (void)layoutSubviews {
160211
[super layoutSubviews];
@@ -285,8 +336,7 @@ - (void)layoutSubviews {
285336
if (_logInButton) {
286337
CGFloat loginButtonTopInset = floorf(24.0f * contentSizeScale.height);
287338

288-
CGRect frame = PFRectMakeWithSizeCenteredInRect([_logInButton sizeThatFits:loginContentSize],
289-
loginContentRect);;
339+
CGRect frame = PFRectMakeWithSizeCenteredInRect([_logInButton sizeThatFits:loginContentSize], loginContentRect);
290340
frame.origin.y = currentY + loginButtonTopInset;
291341
_logInButton.frame = frame;
292342

@@ -350,9 +400,7 @@ - (CGSize)_loginContentSizeThatFits:(CGSize)boundingSize withContentSizeScale:(C
350400
}
351401

352402
- (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));
356404
}
357405

358406
- (CGSize)_contentSizeScaleForContentSize:(CGSize)contentSize {
@@ -367,8 +415,17 @@ - (CGSize)_contentSizeScaleForContentSize:(CGSize)contentSize {
367415
return contentSizeScale;
368416
}
369417

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+
}
372429

373430
- (void)setLogo:(UIView *)logo {
374431
if (self.logo != logo) {
@@ -388,8 +445,9 @@ - (void)setEmailAsUsername:(BOOL)otherEmailAsUsername {
388445
}
389446
}
390447

391-
#pragma mark -
392-
#pragma mark Private
448+
///--------------------------------------
449+
#pragma mark - Private
450+
///--------------------------------------
393451

394452
+ (void)_validateFields:(PFLogInFields)fields {
395453
if (fields == PFLogInFieldsNone) {

0 commit comments

Comments
 (0)