Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Social login: Handle new identity provider brand field in order to customize buttons #3982

Merged
merged 4 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Changes to be released in next version
*

🙌 Improvements
*
* Social login: Handle new identity provider brand field in order to customize buttons (#3980).

🐛 Bugfix
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "social_login_button_gitlab.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Riot/Generated/Images.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal enum Asset {
internal static let socialLoginButtonApple = ImageAsset(name: "social_login_button_apple")
internal static let socialLoginButtonFacebook = ImageAsset(name: "social_login_button_facebook")
internal static let socialLoginButtonGithub = ImageAsset(name: "social_login_button_github")
internal static let socialLoginButtonGitlab = ImageAsset(name: "social_login_button_gitlab")
internal static let socialLoginButtonGoogle = ImageAsset(name: "social_login_button_google")
internal static let socialLoginButtonTwitter = ImageAsset(name: "social_login_button_twitter")
internal static let callAudioMuteOffIcon = ImageAsset(name: "call_audio_mute_off_icon")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,7 @@ class SocialLoginButtonFactory {
let defaultStyle: SocialLoginButtonStyle
var styles: [String: SocialLoginButtonStyle] = [:]

switch identityProvider.identifier {
case "google":
(defaultStyle, styles) = self.buildGoogleButtonStyles()
case "facebook":
(defaultStyle, styles) = self.buildFacebookButtonStyles()
case "github":
(defaultStyle, styles) = self.buildGitHubButtonStyles()
case "apple":
(defaultStyle, styles) = self.buildAppleButtonStyles()
case "twitter":
(defaultStyle, styles) = self.buildTwitterButtonStyles()
default:
let buildDefaultButtonStyles: () -> (SocialLoginButtonStyle, [String: SocialLoginButtonStyle]) = {
let image: SourceImage?

if let imageStringURL = identityProvider.icon, let imageURL = URL(string: imageStringURL) {
Expand All @@ -54,7 +43,30 @@ class SocialLoginButtonFactory {
image = nil
}

(defaultStyle, styles) = self.buildDefaultButtonStyles(with: image)
return self.buildDefaultButtonStyles(with: image)
}

if let idpBrandIdentifier = identityProvider.brand {
let idpBrand = MXLoginSSOIdentityProviderBrand(rawValue: idpBrandIdentifier)

switch idpBrand {
case .gitlab:
(defaultStyle, styles) = self.buildGitLabButtonStyles()
case .github:
(defaultStyle, styles) = self.buildGitHubButtonStyles()
case .apple:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apple should be the first :)

(defaultStyle, styles) = self.buildAppleButtonStyles()
case .google:
(defaultStyle, styles) = self.buildGoogleButtonStyles()
case .facebook:
(defaultStyle, styles) = self.buildFacebookButtonStyles()
case .twitter:
(defaultStyle, styles) = self.buildTwitterButtonStyles()
default:
(defaultStyle, styles) = buildDefaultButtonStyles()
}
} else {
(defaultStyle, styles) = buildDefaultButtonStyles()
}

let title = self.buildButtonTitle(with: identityProvider.name, mode: mode)
Expand Down Expand Up @@ -211,6 +223,31 @@ class SocialLoginButtonFactory {
return (defaultStyle, styles)
}

private func buildGitLabButtonStyles() -> (SocialLoginButtonStyle, [String: SocialLoginButtonStyle]) {

let logo: SourceImage = .local(Asset.Images.socialLoginButtonGitlab.image)

let lightStyle = SocialLoginButtonStyle(logo: logo,
titleColor: .black,
backgroundColor: .white,
borderColor: .black)

let darkStyle = SocialLoginButtonStyle(logo: logo,
titleColor: .white,
backgroundColor: .black,
borderColor: .white)

let defaultStyle: SocialLoginButtonStyle = lightStyle

let styles: [String: SocialLoginButtonStyle] = [
ThemeIdentifier.light.rawValue: lightStyle,
ThemeIdentifier.dark.rawValue: darkStyle,
ThemeIdentifier.black.rawValue: darkStyle
]

return (defaultStyle, styles)
}

private func buildDefaultButtonStyles(with image: SourceImage?) -> (SocialLoginButtonStyle, [String: SocialLoginButtonStyle]) {

let lightStyle = SocialLoginButtonStyle(logo: image,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ final class SocialLoginListView: UIView, NibLoadable {

// Order alphabeticaly by Identity Provider identifier
let sortedIdentityProviders = identityProviders.sorted { (firstIdentityProvider, secondIdentityProvider) -> Bool in
firstIdentityProvider.identifier < secondIdentityProvider.identifier
if let firstIdentityProviderBrand = firstIdentityProvider.brand, let secondIdentityProviderBrand = secondIdentityProvider.brand {
return firstIdentityProviderBrand < secondIdentityProviderBrand
} else {
return firstIdentityProvider.identifier < secondIdentityProvider.identifier
}
}

for identityProvider in sortedIdentityProviders {
Expand Down