Skip to content

Commit

Permalink
✨ MainFeature 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
juyeong525 committed Apr 26, 2024
1 parent bf96d58 commit 8b8d5cd
Show file tree
Hide file tree
Showing 19 changed files with 183 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extension ModulePaths: MicroTargetPathConvertable {

public extension ModulePaths {
enum Feature: String, MicroTargetPathConvertable {
case MainFeature
case SigninFeature
case SplashFeature
case RootFeature
Expand Down
5 changes: 5 additions & 0 deletions Projects/App/Sources/Application/DI/AppComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import SplashFeature
import SplashFeatureInterface
import SigninFeature
import SigninFeatureInterface
import MainFeature
import MainFeatureInterface

public final class AppComponent: BootstrapComponent {
// private let _keychain: any Keychain
Expand Down Expand Up @@ -36,4 +38,7 @@ public extension AppComponent {
var signinFactory: any SigninFactory {
SigninComponent(parent: self)
}
var mainFactory: any MainFactory {
MainComponent(parent: self)
}
}
2 changes: 1 addition & 1 deletion Projects/App/Sources/Application/KillerGramApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ViewUtil

@main
struct KillerGramApp: App {
@StateObject var appState = AppState(sceneFlow: .splash)
@ObservedObject var appState = AppStateProvider(sceneFlow: .splash, rule: .student)

init() {
DesignSystemFontFamily.registerAllCustomFonts()
Expand Down
24 changes: 24 additions & 0 deletions Projects/App/Sources/Application/NeedleGenerated.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@


import MainFeature
import MainFeatureInterface
import NeedleFoundation
import RootFeature
import RootFeatureInterface
Expand Down Expand Up @@ -33,13 +35,27 @@ private class SplashDependencye0cb7136f2ec3edfd60aProvider: SplashDependency {
private func factoryace9f05f51d68f4c0677e3b0c44298fc1c149afb(_ component: NeedleFoundation.Scope) -> AnyObject {
return SplashDependencye0cb7136f2ec3edfd60aProvider()
}
private class MainDependency7c6a5b4738b211b8e155Provider: MainDependency {


init() {

}
}
/// ^->AppComponent->MainComponent
private func factoryc9274e46e78e70f29c54e3b0c44298fc1c149afb(_ component: NeedleFoundation.Scope) -> AnyObject {
return MainDependency7c6a5b4738b211b8e155Provider()
}
private class RootDependency3944cc797a4a88956fb5Provider: RootDependency {
var splashFactory: any SplashFactory {
return appComponent.splashFactory
}
var signinFactory: any SigninFactory {
return appComponent.signinFactory
}
var mainFactory: any MainFactory {
return appComponent.mainFactory
}
private let appComponent: AppComponent
init(appComponent: AppComponent) {
self.appComponent = appComponent
Expand Down Expand Up @@ -67,17 +83,24 @@ extension AppComponent: Registration {

localTable["splashFactory-any SplashFactory"] = { [unowned self] in self.splashFactory as Any }
localTable["signinFactory-any SigninFactory"] = { [unowned self] in self.signinFactory as Any }
localTable["mainFactory-any MainFactory"] = { [unowned self] in self.mainFactory as Any }
}
}
extension SplashComponent: Registration {
public func registerItems() {

}
}
extension MainComponent: Registration {
public func registerItems() {

}
}
extension RootComponent: Registration {
public func registerItems() {
keyPathToName[\RootDependency.splashFactory] = "splashFactory-any SplashFactory"
keyPathToName[\RootDependency.signinFactory] = "signinFactory-any SigninFactory"
keyPathToName[\RootDependency.mainFactory] = "mainFactory-any MainFactory"
}
}
extension SigninComponent: Registration {
Expand All @@ -103,6 +126,7 @@ private func registerProviderFactory(_ componentPath: String, _ factory: @escapi
@inline(never) private func register1() {
registerProviderFactory("^->AppComponent", factoryEmptyDependencyProvider)
registerProviderFactory("^->AppComponent->SplashComponent", factoryace9f05f51d68f4c0677e3b0c44298fc1c149afb)
registerProviderFactory("^->AppComponent->MainComponent", factoryc9274e46e78e70f29c54e3b0c44298fc1c149afb)
registerProviderFactory("^->AppComponent->RootComponent", factory264bfc4d4cb6b0629b40f47b58f8f304c97af4d5)
registerProviderFactory("^->AppComponent->SigninComponent", factory2882a056d84a613debcce3b0c44298fc1c149afb)
}
Expand Down
25 changes: 21 additions & 4 deletions Projects/Feature/BaseFeature/Sources/AppState.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import Foundation
import SwiftUI

public final class AppState: ObservableObject {
@Published public var sceneFlow: SceneFlow
@propertyWrapper
public struct AppState: DynamicProperty {
@EnvironmentObject private var object: AppStateProvider

public var wrappedValue: AppStateProvider {
object
}

public init() { }
}

public init(sceneFlow: SceneFlow) {
public final class AppStateProvider: ObservableObject {
@Published public var sceneFlow: SceneFlow
@Published public var rule: RuleExample
public init(sceneFlow: SceneFlow, rule: RuleExample) {
self.sceneFlow = sceneFlow
self.rule = rule
}
}

public enum RuleExample {
case student
case manager
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
19 changes: 19 additions & 0 deletions Projects/Feature/MainFeature/Demo/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import UIKit

@main
final class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
let viewController = UIViewController()
viewController.view.backgroundColor = .yellow
window?.rootViewController = viewController
window?.makeKeyAndVisible()

return true
}
}
6 changes: 6 additions & 0 deletions Projects/Feature/MainFeature/Interface/MainFactory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import SwiftUI

public protocol MainFactory {
associatedtype SomeView: View
func makeView() -> SomeView
}
23 changes: 23 additions & 0 deletions Projects/Feature/MainFeature/Project.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import DependencyPlugin
import ProjectDescription
import ProjectDescriptionHelpers

let project = Project.module(
name: ModulePaths.Feature.MainFeature.rawValue,
targets: [
.interface(module: .feature(.MainFeature)),
.implements(
module: .feature(.MainFeature),
dependencies: [
.feature(target: .MainFeature, type: .interface),
.feature(target: .BaseFeature)
]
),
.tests(module: .feature(.MainFeature), dependencies: [
.feature(target: .MainFeature)
]),
.demo(module: .feature(.MainFeature), dependencies: [
.feature(target: .MainFeature)
])
]
)
11 changes: 11 additions & 0 deletions Projects/Feature/MainFeature/Sources/MainComponent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import SwiftUI
import NeedleFoundation
import MainFeatureInterface

public protocol MainDependency: Dependency {}

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

public struct MainView: View {
public var body: some View {
Color.red
}
}
11 changes: 11 additions & 0 deletions Projects/Feature/MainFeature/Tests/MainFeatureTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import XCTest

final class MainFeatureTests: XCTestCase {
override func setUpWithError() throws {}

override func tearDownWithError() throws {}

func testExample() {
XCTAssertEqual(1, 1)
}
}
11 changes: 11 additions & 0 deletions Projects/Feature/MainFeature/UITests/MainFeatureUITests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import XCTest

final class MainFeatureTests: XCTestCase {
override func setUpWithError() throws {}

override func tearDownWithError() throws {}

func testExample() throws {
XCTAssertEqual("A", "A")
}
}
5 changes: 4 additions & 1 deletion Projects/Feature/RootFeature/Sources/RootComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ import NeedleFoundation
import SwiftUI
import SplashFeatureInterface
import SigninFeatureInterface
import MainFeatureInterface

public protocol RootDependency: Dependency {
var splashFactory: any SplashFactory { get }
var signinFactory: any SigninFactory { get }
var mainFactory: any MainFactory { get }
}

public final class RootComponent: Component<RootDependency>, RootFactory {
public func makeView() -> some View {
RootView(
splashFactory: dependency.splashFactory,
signinFactory: dependency.signinFactory
signinFactory: dependency.signinFactory,
mainFactory: dependency.mainFactory
)
}
}
10 changes: 7 additions & 3 deletions Projects/Feature/RootFeature/Sources/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ import SwiftUI
import DesignSystem
import SplashFeatureInterface
import SigninFeatureInterface
import MainFeatureInterface
import ViewUtil

struct RootView: View {
@EnvironmentObject var appState: AppState
@AppState var appState
private let splashFactory: any SplashFactory
private let signinFactory: any SigninFactory
private let mainFactory: any MainFactory

public init(
splashFactory: any SplashFactory,
signinFactory: any SigninFactory
signinFactory: any SigninFactory,
mainFactory: any MainFactory
) {
self.splashFactory = splashFactory
self.signinFactory = signinFactory
self.mainFactory = mainFactory
}

var body: some View {
Expand All @@ -26,7 +30,7 @@ struct RootView: View {
.environmentObject(appState)

case .main:
EmptyView()
mainFactory.makeView().eraseToAnyView()
.environmentObject(appState)

case .splash:
Expand Down
4 changes: 4 additions & 0 deletions Projects/Feature/SigninFeature/Sources/SigninView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ struct SigninView: View {
case email
case password
}
@AppState var appState
@FocusState private var focusField: FocusField?
@StateObject var viewModel: SigninViewModel

Expand Down Expand Up @@ -62,5 +63,8 @@ struct SigninView: View {

Spacer()
}
.onChange(of: viewModel.isSuccessToSignin) { _ in
self.appState.sceneFlow = .main
}
}
}
3 changes: 2 additions & 1 deletion Projects/Feature/SigninFeature/Sources/SigninViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import Combine
final class SigninViewModel: BaseViewModel {
@Published var email: String = ""
@Published var password: String = ""
@Published var isSuccessToSignin: Bool = false

func signinButtonDidTap() {
print("Signin")
self.isSuccessToSignin = true
}
}
2 changes: 1 addition & 1 deletion Projects/Feature/SplashFeature/Sources/SplashView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import BaseFeature

struct SplashView: View {
@StateObject var viewModel: SplashViewModel
@EnvironmentObject var appState: AppState
@AppState var appState

init(
viewModel: SplashViewModel
Expand Down
Binary file added graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8b8d5cd

Please sign in to comment.