Skip to content

Commit

Permalink
refactor: add SocialSignView previews
Browse files Browse the repository at this point in the history
  • Loading branch information
eyatsenkoperpetio committed Nov 28, 2023
1 parent abeeaf5 commit 2761c84
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public struct SignInView: View {
}
}
if viewModel.socialLoginEnabled {
SocialSignView(onSigned: viewModel.sign)
SocialSignView(viewModel: .init(onSigned: viewModel.sign))
}
Spacer()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public struct SignUpView: View {
if viewModel.socialLoginEnabled {
SocialSignView(
signType: .register,
onSigned: viewModel.register
viewModel: .init(onSigned: viewModel.register)
)
.padding(.bottom, 30)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ struct SocialSignView: View {

init(
signType: SignType = .signIn,
onSigned: @escaping (Result<SocialResult, Error>) -> Void
viewModel: SocialSignViewModel
) {
let viewModel: SocialSignViewModel = .init(onSigned: onSigned)
self._viewModel = .init(wrappedValue: viewModel)
self.signType = signType
}
Expand Down Expand Up @@ -103,3 +102,12 @@ struct SocialSignView: View {
}
}
}

#if DEBUG
struct SocialSignView_Previews: PreviewProvider {
static var previews: some View {
let vm = SocialSignViewModel(onSigned: { _ in })
SocialSignView(viewModel: vm).padding()
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ final public class SocialSignViewModel: ObservableObject {

private var onSigned: ((Result<SocialResult, Error>) -> Void)

init(onSigned: @escaping (Result<SocialResult, Error>) -> Void) {
init(
config: ConfigProtocol = Container.shared.resolve(ConfigProtocol.self) ?? ConfigMock(),
onSigned: @escaping (Result<SocialResult, Error>) -> Void
) {
self.config = config
self.onSigned = onSigned
}

let config: ConfigProtocol

private let appleSingInProvider: AppleSingInProvider = .init()
private let googleSingInProvider: GoogleSingInProvider = .init()
private let facebookSingInProvider: FacebookSingInProvider = .init()
Expand All @@ -52,8 +58,6 @@ final public class SocialSignViewModel: ObservableObject {
UIApplication.topViewController()
}

private(set) lazy var config = Container.shared.resolve(ConfigProtocol.self)!

// MARK: - Public Intens -

func signInWithApple() {
Expand Down
17 changes: 17 additions & 0 deletions Core/Core/Configuration/Config/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,23 @@ public class ConfigMock: Config {
"AGREEMENT_URLS": [
"PRIVACY_POLICY_URL": "https://www.example.com/privacy",
"TOS_URL": "https://www.example.com/tos"
],
"GOOGLE": [
"ENABLED": true,
"CLIENT_ID": "CLIENT_ID"
],
"FACEBOOK": [
"ENABLED": true,
"FACEBOOK_APP_ID": "FACEBOOK_APP_ID",
"CLIENT_TOKEN": "CLIENT_TOKEN",
],
"MICROSOFT": [
"ENABLED": true,
"APP_ID": "APP_ID"
],
"SOCIAL_LOGINS": [
"ENABLED": true,
"APPLE_SIGNIN_ENABLED": true
]
]

Expand Down
1 change: 0 additions & 1 deletion Core/Core/Configuration/Config/GoogleConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public final class GoogleConfig: NSObject {
public var googlePlusKey: String?
public var clientID: String?


public var requiredKeysAvailable: Bool {
return clientID != nil
}
Expand Down
13 changes: 13 additions & 0 deletions Core/Core/View/Base/LabelButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,16 @@ public struct LabelButton: View {

}
}

#if DEBUG
struct LabelButton_Previews: PreviewProvider {
static var previews: some View {
LabelButton(
image: CoreAssets.iconApple.swiftUIImage,
title: "Apple",
backgroundColor: CoreAssets.appleButtonColor.swiftUIColor,
action: { }
)
}
}
#endif

0 comments on commit 2761c84

Please sign in to comment.