Skip to content

Commit

Permalink
Merge pull request #82 from Team-MindWay/78-add-gauthsignin
Browse files Browse the repository at this point in the history
🔀 :: [#78] GauthSignin 추가
  • Loading branch information
kimkyumbi authored Jun 12, 2024
2 parents 5c47d36 + d5c0160 commit 90a4c89
Show file tree
Hide file tree
Showing 47 changed files with 815 additions and 42 deletions.
29 changes: 29 additions & 0 deletions App/Sources/Application/DI/AppComponent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import NeedleFoundation
import Service
import SwiftUI

public final class AppComponent: BootstrapComponent {
public func makeRootView() -> some View {
rootComponent.makeView()
}

var rootComponent: RootComponent {
RootComponent(parent: self)
}

public var keychain: Keychain {
shared {
KeychainImpl()
}
}
}

public extension AppComponent {
var signinFactory: any SigninFactory {
SigninComponent(parent: self)
}

var mainFactory: any MainFactory {
MainComponent(parent: self)
}
}
37 changes: 37 additions & 0 deletions App/Sources/Application/DI/Auth/AppComponent+Auth.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import NeedleFoundation
import Service

public extension AppComponent {
var localAuthDataSource: any LocalAuthDataSource {
shared {
LocalAuthDataSourceImpl(keychain: keychain)
}
}

var remoteAuthDataSource: any RemoteAuthDataSource {
shared {
RemoteAuthDataSourceImpl(keychain: keychain)
}
}

var authRepository: any AuthRepository {
shared {
AuthRepositoryImpl(
remoteAuthDataSource: remoteAuthDataSource,
localAuthDataSource: localAuthDataSource
)
}
}

var loginUseCase: any LoginUseCase {
shared {
LoginUseCaseImpl(authRepository: authRepository)
}
}

var logoutUseCase: any LogoutUseCase {
shared {
LogoutUseCaseImpl(authRepository: authRepository)
}
}
}
8 changes: 7 additions & 1 deletion App/Sources/Application/MindWayApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import Service
@main
struct MindWayApp: App {
@State private var showMainView = false
@StateObject private var sceneState = SceneState(sceneFlow: .login)

init() {
registerProviderFactories()
}

var body: some Scene {
WindowGroup {
if showMainView {
TabBarView(viewModel: MyPageViewModel())
AppComponent().makeRootView()
.environmentObject(sceneState)
} else {
SplashView()
.onAppear {
Expand Down
118 changes: 118 additions & 0 deletions App/Sources/Application/NeedleGenerated.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@


import NeedleFoundation
import Service
import SwiftUI

// swiftlint:disable unused_declaration
private let needleDependenciesHash : String? = nil

// MARK: - Traversal Helpers

private func parent1(_ component: NeedleFoundation.Scope) -> NeedleFoundation.Scope {
return component.parent
}

// MARK: - Providers

#if !NEEDLE_DYNAMIC

private class MainDependency7c6a5b4738b211b8e155Provider: MainDependency {


init() {

}
}
/// ^->AppComponent->MainComponent
private func factoryc9274e46e78e70f29c54e3b0c44298fc1c149afb(_ component: NeedleFoundation.Scope) -> AnyObject {
return MainDependency7c6a5b4738b211b8e155Provider()
}
private class RootDependency3944cc797a4a88956fb5Provider: RootDependency {
var signinFactory: any SigninFactory {
return appComponent.signinFactory
}
private let appComponent: AppComponent
init(appComponent: AppComponent) {
self.appComponent = appComponent
}
}
/// ^->AppComponent->RootComponent
private func factory264bfc4d4cb6b0629b40f47b58f8f304c97af4d5(_ component: NeedleFoundation.Scope) -> AnyObject {
return RootDependency3944cc797a4a88956fb5Provider(appComponent: parent1(component) as! AppComponent)
}
private class SigninDependencyde06a9d0b22764487733Provider: SigninDependency {
var loginUseCase: any LoginUseCase {
return appComponent.loginUseCase
}
var mainFactory: any MainFactory {
return appComponent.mainFactory
}
private let appComponent: AppComponent
init(appComponent: AppComponent) {
self.appComponent = appComponent
}
}
/// ^->AppComponent->SigninComponent
private func factory2882a056d84a613debccf47b58f8f304c97af4d5(_ component: NeedleFoundation.Scope) -> AnyObject {
return SigninDependencyde06a9d0b22764487733Provider(appComponent: parent1(component) as! AppComponent)
}

#else
extension MainComponent: Registration {
public func registerItems() {

}
}
extension RootComponent: Registration {
public func registerItems() {
keyPathToName[\RootDependency.signinFactory] = "signinFactory-any SigninFactory"
}
}
extension SigninComponent: Registration {
public func registerItems() {
keyPathToName[\SigninDependency.loginUseCase] = "loginUseCase-any LoginUseCase"
keyPathToName[\SigninDependency.mainFactory] = "mainFactory-any MainFactory"
}
}
extension AppComponent: Registration {
public func registerItems() {

localTable["keychain-Keychain"] = { [unowned self] in self.keychain as Any }
localTable["localAuthDataSource-any LocalAuthDataSource"] = { [unowned self] in self.localAuthDataSource as Any }
localTable["remoteAuthDataSource-any RemoteAuthDataSource"] = { [unowned self] in self.remoteAuthDataSource as Any }
localTable["authRepository-any AuthRepository"] = { [unowned self] in self.authRepository as Any }
localTable["loginUseCase-any LoginUseCase"] = { [unowned self] in self.loginUseCase as Any }
localTable["logoutUseCase-any LogoutUseCase"] = { [unowned self] in self.logoutUseCase as Any }
localTable["signinFactory-any SigninFactory"] = { [unowned self] in self.signinFactory as Any }
localTable["mainFactory-any MainFactory"] = { [unowned self] in self.mainFactory as Any }
}
}


#endif

private func factoryEmptyDependencyProvider(_ component: NeedleFoundation.Scope) -> AnyObject {
return EmptyDependencyProvider(component: component)
}

// MARK: - Registration
private func registerProviderFactory(_ componentPath: String, _ factory: @escaping (NeedleFoundation.Scope) -> AnyObject) {
__DependencyProviderRegistry.instance.registerDependencyProviderFactory(for: componentPath, factory)
}

#if !NEEDLE_DYNAMIC

@inline(never) private func register1() {
registerProviderFactory("^->AppComponent->MainComponent", factoryc9274e46e78e70f29c54e3b0c44298fc1c149afb)
registerProviderFactory("^->AppComponent->RootComponent", factory264bfc4d4cb6b0629b40f47b58f8f304c97af4d5)
registerProviderFactory("^->AppComponent->SigninComponent", factory2882a056d84a613debccf47b58f8f304c97af4d5)
registerProviderFactory("^->AppComponent", factoryEmptyDependencyProvider)
}
#endif

public func registerProviderFactories() {
#if !NEEDLE_DYNAMIC
register1()
#endif
}
7 changes: 7 additions & 0 deletions App/Sources/DesignSystem/Extensions/View+eraseToAnyView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import SwiftUI

public extension View {
func eraseToAnyView() -> AnyView {
AnyView(self)
}
}
31 changes: 31 additions & 0 deletions App/Sources/Feature/BaseFeature/BaseViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import UIKit

open class BaseViewModel: ObservableObject {
@Published public var isErrorOccurred = false
@Published public var isLoading = false
@Published public var errorMessage = ""

public init() {}

public func addCancellable<T>(
_ task: @escaping @Sendable () async throws -> T,
onReceiveValue: @escaping (T) -> Void,
onReceiveError: ((Error) -> Void)? = nil
) {
isLoading = true
Task {
do {
let value = try await task()
onReceiveValue(value)
} catch {
if let onReceiveError {
onReceiveError(error)
}

errorMessage = error.localizedDescription
isErrorOccurred = true
}
isLoading = false
}
}
}
5 changes: 5 additions & 0 deletions App/Sources/Feature/BaseFeature/Flow/SceneFlow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

public enum SceneFlow: String, RawRepresentable {
case login
}
8 changes: 8 additions & 0 deletions App/Sources/Feature/BaseFeature/Flow/TabFlow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Foundation

public enum TabFlow: String, RawRepresentable {
case home
case event
case book
case my
}
9 changes: 9 additions & 0 deletions App/Sources/Feature/BaseFeature/Sources/SceneState.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation

public final class SceneState: ObservableObject {
@Published public var sceneFlow: SceneFlow

init(sceneFlow: SceneFlow) {
self.sceneFlow = sceneFlow
}
}
31 changes: 0 additions & 31 deletions App/Sources/Feature/LoginFeature/LoginView.swift

This file was deleted.

11 changes: 11 additions & 0 deletions App/Sources/Feature/MainFeature/MainComponent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import NeedleFoundation
import Service
import SwiftUI

public protocol MainDependency: Dependency {}

public final class MainComponent: Component<MainDependency>, MainFactory {
public func makeView() -> some View {
MainView()
}
}
7 changes: 7 additions & 0 deletions App/Sources/Feature/MainFeature/MainFactory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import SwiftUI

public protocol MainFactory {
associatedtype SomeView: View
func makeView() -> SomeView
}

14 changes: 14 additions & 0 deletions App/Sources/Feature/RootFeature/RootComponent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import NeedleFoundation
import SwiftUI

public protocol RootDependency: Dependency {
var signinFactory: any SigninFactory { get }
}

public final class RootComponent: Component<RootDependency> {
public func makeView() -> some View {
RootView(
signinFactory: self.dependency.signinFactory
)
}
}
24 changes: 24 additions & 0 deletions App/Sources/Feature/RootFeature/RootView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import SwiftUI

struct RootView: View {
@EnvironmentObject var sceneState: SceneState
private let signinFactory: any SigninFactory

public init(
signinFactory: any SigninFactory
) {
self.signinFactory = signinFactory
}

var body: some View {
Group {
switch sceneState.sceneFlow {
case .login:
signinFactory.makeView()
.eraseToAnyView()
.environmentObject(sceneState)
}
}
.animation(.default, value: sceneState.sceneFlow)
}
}
35 changes: 35 additions & 0 deletions App/Sources/Feature/SigninFeature/Component/GAuthButtonView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import GAuthSignin
import SwiftUI
import UIKit

struct GAuthButtonView: UIViewRepresentable {
private let completion: (String) -> Void

init(
completion: @escaping (String) -> Void
) {
self.completion = completion
}

func updateUIView(_ uiView: UIViewType, context: Context) { }

func makeUIView(context: Context) -> some UIView {
let gauthButton = GAuthButton(
auth: .signup,
color: .outline,
rounded: .default
)
guard let presentingViewController = (UIApplication.shared.connectedScenes.first as? UIWindowScene)?
.windows
.first?
.rootViewController
else { return gauthButton }
gauthButton.prepare(
clientID: Bundle.main.object(forInfoDictionaryKey: "CLIENT_ID") as? String ?? "",
redirectURI: Bundle.main.object(forInfoDictionaryKey: "REDIRECT_URI") as? String ?? "",
presenting: presentingViewController,
completion: completion
)
return gauthButton
}
}
Loading

0 comments on commit 90a4c89

Please sign in to comment.