Skip to content

Commit 25ccb40

Browse files
authored
Center align sign in with Apple button (#829)
1 parent afc3d56 commit 25ccb40

File tree

10 files changed

+67
-14
lines changed

10 files changed

+67
-14
lines changed

AnonymousAuth/FirebaseAnonymousAuthUI/FUIAnonymousAuth.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ NS_ASSUME_NONNULL_BEGIN
2323
*/
2424
@interface FUIAnonymousAuth : NSObject <FUIAuthProvider>
2525

26+
/** @property buttonAlignment
27+
@brief The alignment of the icon and text of the button.
28+
*/
29+
@property(nonatomic, readwrite) FUIButtonAlignment buttonAlignment;
30+
2631
/** @fn init
2732
@brief Initialize the instance with the default AuthUI.
2833
*/

Auth/FirebaseAuthUI/FUIAuthProvider.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ typedef void (^FUIAuthProviderSignInCompletionBlock) (
4848
*/
4949
typedef NSString *FUIAuthProviderSignInUserInfoKey NS_TYPED_ENUM;
5050

51+
/**
52+
@typedef FUIButtonAlignment
53+
@brief The alignment of the icon and text of the button.
54+
*/
55+
typedef NS_ENUM(NSInteger, FUIButtonAlignment) {
56+
FUIButtonAlignmentLeading,
57+
FUIButtonAlignmentCenter,
58+
};
59+
5160
/**
5261
For Firebase-based authentication operations, use this key to obtain the original auth result
5362
that was returned from the sign-in operation.
@@ -93,6 +102,11 @@ static FUIAuthProviderSignInUserInfoKey FUIAuthProviderSignInUserInfoKeyAuthData
93102
*/
94103
@property(nonatomic, strong, readonly) UIColor *buttonTextColor;
95104

105+
/** @property buttonAlignment
106+
@brief The alignment of the icon and text of the button.
107+
*/
108+
@property(nonatomic, readwrite) FUIButtonAlignment buttonAlignment;
109+
96110
/** @fn signInWithEmail:presentingViewController:completion:
97111
@brief Called when the user wants to sign in using this auth provider.
98112
@remarks Implementors should invoke the completion block when the sign-in process has terminated

Auth/FirebaseAuthUI/FUIAuthSignInButton.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#import <UIKit/UIKit.h>
1818

19-
@protocol FUIAuthProvider;
19+
#import "FUIAuthProvider.h"
2020

2121
NS_ASSUME_NONNULL_BEGIN
2222

@@ -53,7 +53,8 @@ NS_ASSUME_NONNULL_BEGIN
5353
image:(UIImage *)image
5454
text:(NSString *)text
5555
backgroundColor:(UIColor *)backgroundColor
56-
textColor:(UIColor *)textColor NS_DESIGNATED_INITIALIZER;
56+
textColor:(UIColor *)textColor
57+
buttonAlignment:(FUIButtonAlignment)buttonAlignment NS_DESIGNATED_INITIALIZER;
5758

5859
/** @fn initWithFrame:providerUI:
5960
@brief Convenience initalizer.

Auth/FirebaseAuthUI/FUIAuthSignInButton.m

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ - (instancetype)initWithFrame:(CGRect)frame
5252
image:(UIImage *)image
5353
text:(NSString *)text
5454
backgroundColor:(UIColor *)backgroundColor
55-
textColor:(UIColor *)textColor {
55+
textColor:(UIColor *)textColor
56+
buttonAlignment:(FUIButtonAlignment)buttonAlignment {
5657
self = [super initWithFrame:frame];
5758
if (!self) {
5859
return nil;
@@ -66,7 +67,11 @@ - (instancetype)initWithFrame:(CGRect)frame
6667
[self setImage:image forState:UIControlStateNormal];
6768

6869
CGFloat paddingTitle = 8.0f;
70+
CGFloat contentWidth = self.imageView.frame.size.width + paddingTitle + self.titleLabel.frame.size.width;
6971
CGFloat paddingImage = 8.0f;
72+
if (buttonAlignment == FUIButtonAlignmentCenter) {
73+
paddingImage = (frame.size.width - contentWidth) / 2 - 4.0f;
74+
}
7075
BOOL isLTRLayout = [[UIApplication sharedApplication] userInterfaceLayoutDirection] ==
7176
UIUserInterfaceLayoutDirectionLeftToRight;
7277
if (isLTRLayout) {
@@ -101,7 +106,8 @@ - (instancetype)initWithFrame:(CGRect)frame providerUI:(id<FUIAuthProvider>)prov
101106
image:providerUI.icon
102107
text:providerUI.signInLabel
103108
backgroundColor:providerUI.buttonBackgroundColor
104-
textColor:providerUI.buttonTextColor];
109+
textColor:providerUI.buttonTextColor
110+
buttonAlignment:providerUI.buttonAlignment];
105111
}
106112

107113
@end

EmailAuth/FirebaseEmailAuthUI/FUIEmailAuth.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ NS_ASSUME_NONNULL_BEGIN
3636
*/
3737
@property(nonatomic, strong, readwrite, nullable) NSString *emailLink;
3838

39+
/** @property buttonAlignment
40+
@brief The alignment of the icon and text of the button.
41+
*/
42+
@property(nonatomic, readwrite) FUIButtonAlignment buttonAlignment;
43+
3944
/** @fn initAuthAuthUI:signInMethod:forceSameDevice:allowNewEmailAccounts:actionCodeSetting:
4045
@brief Initializer with several configurations.
4146
@param authUI The auth UI object that this auth UI provider associate with.

FacebookAuth/FirebaseFacebookAuthUI/FUIFacebookAuth.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ NS_ASSUME_NONNULL_BEGIN
3838
*/
3939
@property(nonatomic, readonly, copy) NSArray<NSString *> *scopes;
4040

41+
/** @property buttonAlignment
42+
@brief The alignment of the icon and text of the button.
43+
*/
44+
@property(nonatomic, readwrite) FUIButtonAlignment buttonAlignment;
45+
4146
/** @fn init
4247
@brief Conevenience initializer. Uses a default permission of `@[ "email" ]`.
4348
*/

GoogleAuth/FirebaseGoogleAuthUI/FUIGoogleAuth.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ static NSString *const kGoogleUserInfoProfileScope = @"https://www.googleapis.co
5050
*/
5151
@property(nonatomic, copy, readonly) NSArray<NSString *> *scopes;
5252

53+
/** @property buttonAlignment
54+
@brief The alignment of the icon and text of the button.
55+
*/
56+
@property(nonatomic, readwrite) FUIButtonAlignment buttonAlignment;
57+
5358
/** @fn init
5459
@brief Convenience initializer. Calls designated init with default
5560
scopes of "email" and "profile".

OAuth/FirebaseOAuthUI/FUIOAuth.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ NS_ASSUME_NONNULL_BEGIN
2323
*/
2424
@interface FUIOAuth : NSObject <FUIAuthProvider>
2525

26+
/** @property buttonAlignment
27+
@brief The alignment of the icon and text of the button.
28+
*/
29+
@property(nonatomic, readwrite) FUIButtonAlignment buttonAlignment;
30+
2631
/** @fn init
2732
@brief Please use `initWithAuthUI:providerID:providerName:buttonColor:iconImage:scopes:
2833
customParameters:` instead.

OAuth/FirebaseOAuthUI/FUIOAuth.m

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,18 @@ + (FUIOAuth *)yahooAuthProvider {
185185
}
186186

187187
+ (FUIOAuth *)appleAuthProvider {
188-
return [[FUIOAuth alloc] initWithAuthUI:[FUIAuth defaultAuthUI]
189-
providerID:@"apple.com"
190-
buttonLabelText:@"Sign in with Apple"
191-
shortName:@"Apple"
192-
buttonColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0]
193-
iconImage:[FUIAuthUtils imageNamed:@"ic_apple"
194-
fromBundleNameOrNil:@"FirebaseOAuthUI"]
195-
scopes:@[@"name", @"email"]
196-
customParameters:nil
197-
loginHintKey:nil];
188+
FUIOAuth *provider = [[FUIOAuth alloc] initWithAuthUI:[FUIAuth defaultAuthUI]
189+
providerID:@"apple.com"
190+
buttonLabelText:@"Sign in with Apple"
191+
shortName:@"Apple"
192+
buttonColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0]
193+
iconImage:[FUIAuthUtils imageNamed:@"ic_apple"
194+
fromBundleNameOrNil:@"FirebaseOAuthUI"]
195+
scopes:@[@"name", @"email"]
196+
customParameters:nil
197+
loginHintKey:nil];
198+
provider.buttonAlignment = FUIButtonAlignmentCenter;
199+
return provider;
198200
}
199201

200202
#pragma mark - FUIAuthProvider

PhoneAuth/FirebasePhoneAuthUI/FUIPhoneAuth.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ NS_ASSUME_NONNULL_BEGIN
2323
*/
2424
@interface FUIPhoneAuth : NSObject <FUIAuthProvider>
2525

26+
/** @property buttonAlignment
27+
@brief The alignment of the icon and text of the button.
28+
*/
29+
@property(nonatomic, readwrite) FUIButtonAlignment buttonAlignment;
30+
2631
/** @fn init
2732
@brief Please use @c initWithAuthUI: .
2833
*/

0 commit comments

Comments
 (0)