Closed fangyuxi closed 3 years ago
I found a few problems with this issue:
I can't create a FUIOAuth use custom text button color.
So I have to use the following code to fix this UI problem so that I can adapt to the dark mode. UGLY CODE
Without correction, my app will not pass the review. The reason is as follows.
@fangyuxi I transferred this to the FirebaseUI repo itself since it's related here. This is also related to #823
We should be using ASAuthorizationAppleIDButton
since it's the button provided by Apple and will always conform to proper UI guidelines.
We should be using
ASAuthorizationAppleIDButton
since it's the button provided by Apple and will always conform to proper UI guidelines.
We don't have to use the button provided by Apple. At some point, you need to customize this button, and Apple also provides a ui guide to guide us how to customize.
How do you customize it?
@Casey10110 I can show some code for you.
@Casey10110 here is the code that customize apple sign in button.
The @"applelogo" image, is provided by Apple.
NSMutableArray<id <FUIAuthProvider>> *providers = @[].mutableCopy;
if (@available(iOS 13.0, *)) {
FUIOAuth *apple = [[FUIOAuth alloc] initWithAuthUI:[FUIAuth defaultAuthUI]
providerID:@"apple.com"
buttonLabelText:@"Sign in with Apple"
shortName:@"Apple"
buttonColor:[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]
iconImage:[UIImage imageNamed:@"applelogo"]
scopes:@[@"name", @"email"]
customParameters:nil
loginHintKey:nil];
[providers addObject:apple];
}
[providers addObject:[FUIFacebookAuth new]];
[providers addObject:[FUIGoogleAuth new]];
[providers addObject:[FUIEmailAuth new]];
- (void)reviseAppleSignInButtonUI:(UIView *)rootView {
for (UIView *subView in [rootView subviews]){
if (!rootView.subviews.count) {
return;
}
if ([subView isKindOfClass:[UIButton class]]) {
if ([subView respondsToSelector:@selector(providerUI)]) {
id<FUIAuthProvider> provider = [subView performSelector:@selector(providerUI)];
if ([provider.providerID isEqualToString:@"apple.com"]) {
self.appleLoginButton = (UIButton *)subView;
//revise button ui
if (@available(iOS 13.0, *)){
self.appleLoginButton.titleLabel.font = [UIFont systemFontOfSize:19.0f];
self.appleLoginButton.height = 44;
[self.appleLoginButton setTitleColor:[UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull trait) {
if (trait.userInterfaceStyle == UIUserInterfaceStyleDark) {
return [UIColor blackColor];
} else {
return [UIColor whiteColor];
}
}] forState:UIControlStateNormal];
[self.appleLoginButton setBackgroundColor:[UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull trait) {
if (trait.userInterfaceStyle == UIUserInterfaceStyleDark) {
return [UIColor whiteColor];
} else {
return [UIColor blackColor];
}
}]];
}
return;
}
}
}
[self reviseAppleSignInButtonUI:subView];
}
}
The method 'reviseAppleSignInButtonUI' defined in the controller whose super class controller is FUIAuthPickerViewController.
#import <UIKit/UIKit.h>
@import FirebaseUI;
NS_ASSUME_NONNULL_BEGIN
@interface ENLoginController : FUIAuthPickerViewController<FIRAuthUIDelegate>
@end
NS_ASSUME_NONNULL_END
Right on, thank you. I just modified the file in the FirebaseUI and recompiled: + (FUIOAuth *)appleAuthProvider { UIImage *iconImage = [FUIAuthUtils imageNamed:@"ic_apple" fromBundleNameOrNil:@"FirebaseOAuthUI"]; UIColor *buttonColor = [UIColor blackColor]; UIColor *buttonTextColor = [UIColor whiteColor]; if (UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) { iconImage = [iconImage imageWithTintColor:[UIColor whiteColor]]; buttonColor = [UIColor blackColor]; buttonTextColor = [UIColor whiteColor]; } FUIOAuth *provider = [[FUIOAuth alloc] initWithAuthUI:[FUIAuth defaultAuthUI] providerID:@"apple.com" buttonLabelText:@"Sign in with Apple" shortName:@"Apple" buttonColor:buttonColor iconImage:iconImage scopes:@[@"name", @"email"] customParameters:nil loginHintKey:nil]; //provider.buttonAlignment = FUIButtonAlignmentCenter; provider.buttonTextColor = buttonTextColor; return provider; }
This should be fixed in the latest version of FirebaseUI. Please let me know if that's not the case.
[REQUIRED] Step 1: Describe your environment
Xcode version: _11.3.1
Firebase SDK version: _____
Firebase Component: _Auth____ (Auth, Core, Database, Firestore, Messaging, Storage, etc)
Component version: _____
Installation method:
CocoaPods | Carthage | Zip file
(select one)Firebase/Analytics (6.16.0):
Firebase/Auth (6.16.0):
Firebase/Core (6.16.0):
Firebase/CoreOnly (6.16.0):
Firebase/Database (6.16.0):
Firebase/Firestore (6.16.0):
Firebase/Messaging (6.16.0):
Firebase/Performance (6.16.0):
Firebase/RemoteConfig (6.16.0):
Firebase/Storage (6.16.0):
FirebaseABTesting (3.1.2):
FirebaseAnalytics (6.2.2):
FirebaseAnalyticsInterop (1.5.0)
FirebaseAuth (6.4.3):
FirebaseAuthInterop (1.0.0)
FirebaseCore (6.6.1):
FirebaseCoreDiagnostics (1.2.0):
FirebaseCoreDiagnosticsInterop (1.2.0)
FirebaseDatabase (6.1.4):
FirebaseFirestore (1.10.1):
FirebaseInstallations (1.1.0):
FirebaseInstanceID (4.3.0):
FirebaseMessaging (4.2.0):
FirebasePerformance (3.1.9):
FirebaseRemoteConfig (4.4.6):
FirebaseStorage (3.5.0):
FirebaseUI (8.4.1):
FirebaseUI/Anonymous (8.4.1):
FirebaseUI/Auth (8.4.1):
FirebaseUI/Database (8.4.1):
FirebaseUI/Email (8.4.1):
FirebaseUI/Facebook (8.4.1):
FirebaseUI/Firestore (8.4.1):
FirebaseUI/Google (8.4.1):
FirebaseUI/OAuth (8.4.1):
FirebaseUI/Phone (8.4.1):
FirebaseUI/Storage (8.4.1):
[REQUIRED] Step 2: Describe the problem