Skip to content

[IDLE-000] Refactor, 라우터 및 Splash모듈 개발 #80

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

Merged
merged 16 commits into from
Oct 2, 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
10 changes: 9 additions & 1 deletion project/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# Module creation

# Test

test:
TUIST_ROOT_DIR=${PWD} tuist test

# Project generation

generate:
TUIST_ROOT_DIR=${PWD} tuist generate

genModule:
TUIST_ROOT_DIR=${PWD} tuist generate ${name}

# Module generation

USER_NAME = $(shell python3 Scaffold/Scripts/author_name.py)
CURRENT_DATE = $(shell pipenv run python Scaffold/Scripts/current_date.py)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// SplashFeatureDependency.swift
// DependencyPlugin
//
// Created by 최준영 on 6/21/24.
//

import ProjectDescription

public extension ModuleDependency.Presentation {

static let SplashFeature: TargetDependency = .project(target: "SplashFeature", path: .relativeToRoot("Projects/Presentation/Feature/Splash"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ class RootCoordinator {

func start() {
navigationController.setNavigationBarHidden(true, animated: false)

// Root VC
let vc = InitialScreenVC()
let vm = InitialScreenVM(coordinator: self)

vc.bind(viewModel: vm)

navigationController.pushViewController(vc, animated: false)
}

func popViewController() {
Expand Down
22 changes: 12 additions & 10 deletions project/Projects/App/Sources/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@
import UIKit
import PresentationCore
import Core
import RootFeature
import BaseFeature

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?

// RootCoordinator
var rootCoordinator: RootCoordinator!
let router: Router = .init()

lazy var appCoordinator: AppCoordinator = {
let coodinator = AppCoordinator(router: router)
return coodinator
}()

// FCMService
var fcmService: FCMService!
Expand All @@ -24,8 +31,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
guard let windowScene = scene as? UIWindowScene else { return }

window = UIWindow(windowScene: windowScene)
window?.makeKeyAndVisible()

let rootNavigationController = UINavigationController()
let injector = DependencyInjector.shared

injector
Expand All @@ -37,13 +44,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {

// FCMService
fcmService = FCMService()

// RootCoordinator
rootCoordinator = RootCoordinator(navigationController: rootNavigationController)

rootCoordinator?.start()

window?.rootViewController = rootNavigationController
window?.makeKeyAndVisible()

// Start AppCoodinator
appCoordinator.start()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// ObservableType+Extension.swift
// Core
//
// Created by choijunios on 10/1/24.
//

import Foundation


import RxSwift

public extension ObservableType {

func unretained<T: AnyObject>(_ object: T) -> Observable<(T, Element)> {

self
.compactMap { [weak object] output -> (T, Element)? in

guard let object else { return nil }

return (object, output)
}
.asObservable()
}

func mapToVoid() -> Observable<Void> {

self.map { _ in () }
}
}

public extension ObservableType where Element == Bool {

func onSuccess() -> Observable<Void> {

self
.filter { $0 }
.mapToVoid()
}

func onSuccess<T>(transform: @escaping () throws -> T) -> Observable<T> {

self
.filter { $0 }
.mapToVoid()
.map(transform)
.asObservable()
}

func onSuccess(onNext: @escaping () -> Void) -> Disposable {

self
.filter { $0 }
.mapToVoid()
.subscribe(onNext: onNext)
}

func onFailure() -> Observable<Void> {

self
.filter { !$0 }
.mapToVoid()
}

func onFailure<T>(transform: @escaping () throws -> T) -> Observable<T> {

self
.filter { !$0 }
.mapToVoid()
.map(transform)
.asObservable()
}

func onFailure(onNext: @escaping () -> Void) -> Disposable {

self
.filter { !$0 }
.mapToVoid()
.subscribe(onNext: onNext)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,20 @@ public class DefaultIdleAlertVM: IdleAlertViewModelable {

public class IdleAlertObject {

public struct Action {
let name: String
let action: (() -> ())?

public init(name: String, action: (() -> Void)? = nil) {
self.name = name
self.action = action
}
}

public private(set) var title: String = ""
public private(set) var description: String = ""
public private(set) var acceptButtonLabelText: String = ""
public private(set) var cancelButtonLabelText: String = ""

public var acceptButtonClicked: PublishRelay<Void> = .init()
public var cancelButtonClicked: PublishRelay<Void> = .init()
public private(set) var acceptAction: Action = .init(name: "", action: nil)
public private(set) var cancelAction: Action = .init(name: "", action: nil)

public init() { }

Expand All @@ -83,13 +90,13 @@ public class IdleAlertObject {
return self
}

public func setAcceptButtonLabelText(_ text: String) -> Self {
self.acceptButtonLabelText = text
public func setAcceptAction(_ action: Action) -> Self {
self.acceptAction = action
return self
}

public func setCancelButtonLabelText(_ text: String) -> Self {
self.cancelButtonLabelText = text
public func setCancelAction(_ action: Action) -> Self {
self.cancelAction = action
return self
}
}
Expand Down Expand Up @@ -237,8 +244,8 @@ public class IdleBigAlertController: UIViewController {
descriptionLabel.textString = object.description
descriptionLabel.textAlignment = .center

acceptButton.label.textString = object.acceptButtonLabelText
cancelButton.label.textString = object.cancelButtonLabelText
acceptButton.label.textString = object.acceptAction.name
cancelButton.label.textString = object.cancelAction.name


Observable.merge(
Expand All @@ -255,11 +262,17 @@ public class IdleBigAlertController: UIViewController {
.disposed(by: disposeBag)

acceptButton.rx.tap
.bind(to: object.acceptButtonClicked)
.subscribe(onNext: { [object] _ in

object.acceptAction.action?()
})
.disposed(by: disposeBag)

cancelButton.rx.tap
.bind(to: object.cancelButtonClicked)
.subscribe(onNext: { [object] _ in

object.cancelAction.action?()
})
.disposed(by: disposeBag)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,100 @@ import BaseFeature

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

let navigationController: UINavigationController = .init()

var window: UIWindow?

var router: Router!

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

guard let windowScene = scene as? UIWindowScene else { return }

window = UIWindow(windowScene: windowScene)
window?.makeKeyAndVisible()

let vm = BaseViewModel()
let vc = ViewController()
vc.bind(viewModel: vm)
var rootVC: UIViewController!

window = UIWindow(windowScene: windowScene)
window?.rootViewController = vc
navigationController.setNavigationBarHidden(true, animated: false)
self.router = Router()
router.setRootModuleTo(module: .createRand())

window?.makeKeyAndVisible()
DispatchQueue.main.asyncAfter(deadline: .now()+3) {

rootVC = .createRand()

self.router.replaceRootModuleTo(module: rootVC, animated: true) {

print("루트 변경 완료")
}
}

DispatchQueue.main.asyncAfter(deadline: .now()+4) {

self.router.push(
module: .createRand(),
animated: true) {
print("첫번째 푸쉬 팝")
}
}

DispatchQueue.main.asyncAfter(deadline: .now()+5) {

self.router.push(
module: .createRand(),
animated: true) {
print("두번째 푸쉬 팝")
}
}

DispatchQueue.main.asyncAfter(deadline: .now()+6) {

self.router.popModule(animated: true)
}

DispatchQueue.main.asyncAfter(deadline: .now()+7) {

self.router.popModule(animated: true)
}

DispatchQueue.main.asyncAfter(deadline: .now()+8) {

self.router.push(
module: .createRand(),
animated: true)
}

DispatchQueue.main.asyncAfter(deadline: .now()+9) {

self.router.push(
module: .createRand(),
animated: true)
}

DispatchQueue.main.asyncAfter(deadline: .now()+10) {

self.router.popTo(module: rootVC, animated: true)
}
}
}

extension UIViewController {

static func createRand() -> UIViewController {
let vc = UIViewController()
vc.view.backgroundColor = UIColor.randomColor()
return vc
}
}

extension UIColor {
static func randomColor() -> UIColor {
return UIColor(
red: CGFloat.random(in: 0...1),
green: CGFloat.random(in: 0...1),
blue: CGFloat.random(in: 0...1),
alpha: 1.0
)
}
}
Loading
Loading