-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
🔀 :: [#256] flow 기초 추가
- Loading branch information
Showing
24 changed files
with
299 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
Projects/Core/Sources/Coordinator/Stepper/AppStepper.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.