Skip to content

Commit

Permalink
iOS: Hide JetBrains and GitHub social providers with additional tap (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-magda authored Aug 12, 2024
1 parent 753fb3b commit 5d47d7e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ enum Strings {
static let gitHubAccount = sharedStrings.auth_github_account_text.localized()
static let appleAccount = sharedStrings.auth_apple_account_text.localized()
static let emailText = sharedStrings.auth_email_text.localized()
static let moreOptionsButton = sharedStrings.auth_more_options_btn.localized()
}

// MARK: Credentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ final class AuthSocialViewModel: FeatureViewModel<

private let authSocialErrorMapper: AuthSocialErrorMapper

let availableSocialAuthProviders = SocialAuthProvider.allCases.filter(\.isSupported)

var authSocialErrorMessage: String? {
guard let errorState = state as? AuthSocialFeatureStateError else {
return nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import SwiftUI

struct AuthSocialControlsView: View {
let socialAuthProviders: [SocialAuthProvider]
let isInSignUpMode: Bool

let errorMessage: String?

let isContinueWithEmailAvailable: Bool

let onSocialAuthProviderClick: ((SocialAuthProvider) -> Void)
let onContinueWithEmailClick: (() -> Void)

@State private var isShowingMoreOptions = false

private var socialAuthProviders: [SocialAuthProvider] {
let providers: [SocialAuthProvider] =
if isInSignUpMode {
isShowingMoreOptions ? [.google, .apple, .jetbrains, .github] : [.google, .apple]
} else {
[.jetbrains, .google, .github, .apple]
}
return providers.filter(\.isSupported)
}

var body: some View {
VStack(spacing: LayoutInsets.smallInset) {
ForEach(socialAuthProviders, id: \.rawValue) { provider in
Expand All @@ -26,7 +36,19 @@ struct AuthSocialControlsView: View {
AuthCredentialsErrorView(message: errorMessage)
}

if isContinueWithEmailAvailable {
if isInSignUpMode {
if !isShowingMoreOptions {
Button(
Strings.Auth.Social.moreOptionsButton,
action: {
withAnimation {
isShowingMoreOptions = true
}
}
)
.padding(.top)
}
} else {
Button(
Strings.Auth.Social.emailText,
action: onContinueWithEmailClick
Expand Down Expand Up @@ -69,18 +91,16 @@ struct AuthSocialControlsView_Previews: PreviewProvider {
static var previews: some View {
Group {
AuthSocialControlsView(
socialAuthProviders: SocialAuthProvider.allCases,
isInSignUpMode: false,
errorMessage: "Error message",
isContinueWithEmailAvailable: true,
onSocialAuthProviderClick: { _ in },
onContinueWithEmailClick: {}
)
.preferredColorScheme(.light)

AuthSocialControlsView(
socialAuthProviders: SocialAuthProvider.allCases,
isInSignUpMode: false,
errorMessage: "Error message",
isContinueWithEmailAvailable: true,
onSocialAuthProviderClick: { _ in },
onContinueWithEmailClick: {}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ struct AuthSocialView: View {
.padding(horizontalSizeClass == .regular ? .bottom : .vertical, appearance.logoWidthHeight)

AuthSocialControlsView(
socialAuthProviders: viewModel.availableSocialAuthProviders,
isInSignUpMode: isInSignUpMode,
errorMessage: viewModel.authSocialErrorMessage,
isContinueWithEmailAvailable: !isInSignUpMode,
onSocialAuthProviderClick: viewModel.signIn(with:),
onContinueWithEmailClick: {
viewModel.logClickedContinueWithEmailEvent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ final class SocialAuthService: SocialAuthServiceProtocol {

// MARK: - SocialAuthProvider -

enum SocialAuthProvider: String, CaseIterable {
enum SocialAuthProvider: String {
case jetbrains
case google
case github
Expand Down
1 change: 1 addition & 0 deletions shared/src/commonMain/moko-resources/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<string name="auth_email_text">Continue with email</string>
<string name="auth_social_email_already_used">The email associated with this social network is already in use. Try authorizing via email</string>
<string name="auth_social_email_not_provided_by_social">Authorization error: email is not provided by social network</string>
<string name="auth_more_options_btn">More options</string>

<!-- Auth credentials -->
<string name="auth_credentials_social_text">Continue with social networks</string>
Expand Down

0 comments on commit 5d47d7e

Please sign in to comment.