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

flow 기초 추가 #258

Merged
merged 8 commits into from
Feb 27, 2024
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
3 changes: 2 additions & 1 deletion Projects/Core/Sources/Base/BaseViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import RxSwift
import RxCocoa
import RxFlow

public protocol BaseViewModel {
public protocol BaseViewModel: ViewModel {

associatedtype Input
associatedtype Output

Expand Down
112 changes: 112 additions & 0 deletions Projects/Core/Sources/Coordinator/FlowSugar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import RxFlow
import UIKit
import Then

typealias ViewModelStepper = BaseViewModel & Stepper
typealias ViewModelController = ViewModelProtocol & UIViewController

class FlowSugar<VM, VC>: NSObject where VM: ViewModelStepper, VC: ViewModelController {
var vm: VM!
var vc: VC?

override init() {
fatalError("init() has not been supported")
}

init(viewModel vm: VM) {
self.vm = vm
super.init()
}

init(_ flow: Flow, _ step: Step) {
}

init(_ vm: VM, _ vc: VC.Type) {
self.vm = vm
self.vc = VC().then {
$0.viewModel = vm as? VC.ViewModelType
}
super.init()
}

func presentable(_ vc: VC.Type) -> Self {
self.vc = VC().then {
$0.viewModel = vm as? VC.ViewModelType
}
return self
}

func presentableForStoryBoard(_ vc: VC) -> Self {
self.vc = vc
vc.viewModel = vm as? VC.ViewModelType
return self
}

func navigationItem(with block: @escaping (UIViewController) -> Void) -> Self {
if let vc = self.vc {
block(vc)
}
return self
}

func getViewController() -> VC? {
if let vc = self.vc {
return vc
} else {
return nil
}
}

func setVCProperty(viewControllerBlock block: @escaping (VC) -> Void) -> Self {
if let vc = self.vc {
block(vc)
}
return self
}

func justRegiste() -> FlowContributor? {
if let vc = self.vc {
return .contribute(withNextPresentable: vc, withNextStepper: vm)
}
return nil
}

func oneStepPushBy(_ navi: UINavigationController, isHideBottombar: Bool = false, includeOpaqueBar: Bool = false, animation: Bool = true) -> FlowContributors {
if let vc = self.vc {
vc.hidesBottomBarWhenPushed = isHideBottombar
vc.extendedLayoutIncludesOpaqueBars = includeOpaqueBar
navi.pushViewController(vc, animated: animation)
return .one(flowContributor: .contribute(withNextPresentable: vc, withNextStepper: vm))
}
return .none
}

func oneStepModalPresent(_ parentVC: UIViewController, _ modalStyle: UIModalPresentationStyle = .fullScreen, _ animated: Bool = true) -> FlowContributors {
if let vc = self.vc {
vc.modalPresentationStyle = modalStyle
parentVC.present(vc, animated: animated)
return .one(flowContributor: .contribute(withNextPresentable: vc, withNextStepper: vm))
}
return .none
}

func oneStepPopoverPresent(_ parentVC: UIViewController, _ modalStyle: UIModalPresentationStyle = .popover, _ animated: Bool = true) -> FlowContributors {
if let vc = self.vc {
vc.modalPresentationStyle = modalStyle
parentVC.present(vc, animated: animated)
return .one(flowContributor: .contribute(withNextPresentable: vc, withNextStepper: vm))
}
return .none
}

func oneStepModalPresentMakeNavi(_ parentVC: UIViewController, _ modalStyle: UIModalPresentationStyle = .fullScreen, _ animated: Bool = true) -> FlowContributors {
if let vc = self.vc {
let navigationController = UINavigationController(rootViewController: vc)
navigationController.setNavigationBarHidden(true, animated: true)
navigationController.modalPresentationStyle = modalStyle
parentVC.present(navigationController, animated: animated)
return .one(flowContributor: .contribute(withNextPresentable: navigationController, withNextStepper: vm))
}
return .none
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ public enum AppStep: Step {
case pickleRequired

case otherDestination

case initialization

//selfCore
case myProfileRequired
}
18 changes: 18 additions & 0 deletions Projects/Core/Sources/Coordinator/Stepper/AppStepper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Foundation
import UIKit
import RxFlow
import RxCocoa

public class AppStepper: Stepper {
public static let shared = AppStepper()

public var steps = PublishRelay<Step>()

public var initialStep: Step {
return AppStep.initialization
}

public init(steps: PublishRelay<Step> = PublishRelay<Step>()) {
self.steps = steps
}
}
30 changes: 30 additions & 0 deletions Projects/Core/Sources/Supporter/ViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// ViewModel.swift
// Core
//
// Created by 박준하 on 2/27/24.
// Copyright © 2024 MaeumGaGym-iOS. All rights reserved.
//

import UIKit

public protocol ViewModel {
}

public protocol ServicesViewModel: ViewModel {
associatedtype Services
var services: Services! { get set }
}

public protocol ViewModelProtocol: AnyObject {
associatedtype ViewModelType: ViewModel
var viewModel: ViewModelType! { get set }
}

public extension ViewModelProtocol where Self: UIViewController {
static func instantiate<ViewModelType> (withViewModel viewModel: ViewModelType) -> Self where ViewModelType == Self.ViewModelType {
let viewController = Self()
viewController.viewModel = viewModel
return viewController
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
//
// PostureSearchModel.swift
// Domain
//
// Created by 박준하 on 2/27/24.
// Copyright © 2024 MaeumGaGym-iOS. All rights reserved.
//

import UIKit

public struct PostureSearchModel {
Expand All @@ -13,7 +21,7 @@ public struct PostureSearchContentModel {
public var exerciseName: String
public var exercisePart: String

public init(exerciseImage: UIImage,
public init(exerciseImage: UIImage,
exerciseName: String,
exercisePart: String
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class NicknameViewController: BaseViewController<NicknameViewModel> {

private let nicknameTF = MGTextField(placeholder: "닉네임")

private let cancelButton = MGImageButton(image: DSKitAsset.Assets.cancle.image)
private let cancelButton = MGImageButton(image: DSKitAsset.Assets.whiteCancel.image)

private var checkButton = MGCheckButton(text: "회원가입")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class HomeTimerView: UIView {
}

private let alarmImage = UIImageView().then {
$0.image = DSKitAsset.Assets.homeTimerBell.image
$0.image = DSKitAsset.Assets.timerActIcon.image
}

private var timerAlarmTitle = UILabel().then {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class TimerAlarmAlertView: BaseView {
$0.layer.shadowRadius = 6
}
private let timerImage = UIImageView().then {
$0.image = DSKitAsset.Assets.homeTimerLogo.image
$0.image = DSKitAsset.Assets.timerActIcon.image
}

private let timerTitleLabel = UILabel().then {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class TimerCollectionViewCell: UICollectionViewCell {
private var containerView = UIView()

private var checkImage = UIImageView().then {
$0.image = DSKitAsset.Assets.yesCheck.image
$0.image = DSKitAsset.Assets.yesCheckActIcon.image
$0.isHidden = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public class TimerViewController: BaseViewController<TimerViewModel> {

private var alaertView = TimerAlarmAlertView()

private var navBeforeButton = MGImageButton(image: DSKitAsset.Assets.timerNavLeft.image)
private var navBeforeButton = MGImageButton(image: DSKitAsset.Assets.leftBarArrow.image)

private var navAddButton = MGImageButton(image: DSKitAsset.Assets.timerNavPlus.image)
private var navAddButton = MGImageButton(image: DSKitAsset.Assets.blackPlus.image)

private var navEditButton = MGImageButton(image: DSKitAsset.Assets.timerNavDots.image)
private var navEditButton = MGImageButton(image: DSKitAsset.Assets.dotsActIcon.image)

private var editView = TimerEditView()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class PickleCell: PickleCollectionViewCell {
self.contentStackView.addArrangedSubviews(heartButton, commentButton, shareButton, dotButton)

bottomSheetItems = [
BottomSheetItem(icon: DSKitAsset.Assets.pencil.image, title: "신고")
BottomSheetItem(icon: DSKitAsset.Assets.pencilActIcon.image, title: "신고")
]

bottomSheetViewController.bottomSheetDelegate = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ open class UserProfileView: UIView {

public init(
userName: String,
userProfileImage: UIImage? = DSKitAsset.Assets.basicProfile.image
userProfileImage: UIImage? = DSKitAsset.Assets.basicProfileIcon.image
) {
super.init(frame: .zero)

setupUI(text: userName, image: userProfileImage ?? DSKitAsset.Assets.basicProfile.image)
setupUI(text: userName, image: userProfileImage ?? DSKitAsset.Assets.basicProfileIcon.image)
}

required public init?(coder: NSCoder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import UIKit
import RootFeature
import RxFlow
import Core
import Foundation

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?
var coordinator = FlowCoordinator()
var mainFlow: AppFlow!

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
func scene(_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }

window = UIWindow(windowScene: windowScene)
Expand Down
4 changes: 2 additions & 2 deletions Projects/Features/RootFeature/Sources/AppFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class AppFlow: Flow {
let homeService = HomeService()
let homeRepository = HomeRepository(networkService: homeService)
let homeFlow = HomeFlow(repository: homeRepository)

let postureFlow = PostureFlow()
let shopFlow = ShopFlow()
let pickleFlow = PickleFlow()
Expand All @@ -61,6 +61,6 @@ public class AppFlow: Flow {
}

public init() {

}
}
14 changes: 7 additions & 7 deletions Projects/Features/RootFeature/Sources/HomeFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import HomeFeature
import HomeFeatureInterface

public class HomeFlow: Flow {

public var repository: HomeRepositoryInterface

public var root: Presentable {
return self.rootViewController
}
Expand All @@ -23,15 +23,15 @@ public class HomeFlow: Flow {

init(repository: HomeRepositoryInterface) {
self.repository = repository

let useCase = DefaultHomeUseCase(repository: repository)
let viewModel = HomeViewModel(useCase: useCase)
let viewController = HomeViewController(viewModel)

viewController.view.backgroundColor = DSKitAsset.Colors.gray25.color
viewController.tabBarItem = UITabBarItem(title: "홈",
image: DSKitAsset.Assets.blackHome.image,
selectedImage: DSKitAsset.Assets.blueHome.image
image: DSKitAsset.Assets.blackHomeTapBar.image,
selectedImage: DSKitAsset.Assets.blueHomeTapBar.image
)

self.rootViewController.setViewControllers([viewController], animated: false)
Expand All @@ -42,7 +42,7 @@ public class HomeFlow: Flow {

switch step {
case .otherDestination:
rootViewController.tabBarItem.image = DSKitAsset.Assets.blackHome.image
rootViewController.tabBarItem.image = DSKitAsset.Assets.blackHomeTapBar.image
return .none
default:
return .none
Expand Down
Loading