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

[Refactor] #239 - 화면 전환 Coordinator Router 로직 분리 #240

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from

Conversation

mini-min
Copy link
Member

✨ 해결한 이슈

🛠️ 작업내용

원래 예전에 하자고 했던 Coordinator Pattern을 그냥 공부할 겸 대작업해서 올렸습니다!
따로 회의를 가진지가 오래되서 별도의 설명이 필요할 것 같긴 한데 / 나중에 다덜 여유되면 코드 살펴보고 - 수정하거나 질문받고 - 머지해서 적용해보면 좋을 듯해요!

아직 팝업창과 관련된 화면 전환이나 / 로그아웃 시 루트로 돌아오는 부분들은 코디네이터 적용을 하지 않았습니다. (이것까지 하고 올리면 너무 길어질 것 같아서요...!!!)

  • 화면 전환 로직 분리를 위한 Coordinator & Router 프로토콜 / 구현부 파일 세팅
  • DI를 위한 VC 내 생성자 주입 방식 수정, ViewControllerFactory로 객체 생성 과정 캡슐화
  • AppCoordinator, LoginCoordinator, TabBarCoordinator -> 하위 탭 Coordinator로 이루어지는 화면 전환 구성 구현
  • 몇 개의 버그 수정 (Timer에서 Setting 넘어갈 때의 네비게이션바 표출 문제, 어색한 애니메이션 제거 등)
  • 몇 개의 가독성을 위한 코드 수정 (개행, 오타 수정, CustomTabBar 클래스 분리, 사용하지 않는 Delegate 함수 삭제 등)

🖥️ 주요 코드 설명

코드 설명에 대한 내용은 블로그로 올렸습니다~~!
이해 안되는 부분 질문 주시길~ 혹은 개선 필요사항 있으면 거침없이 피드백 주시길~~

(코드 사용 설명)
Clip 탭 기준으로 설명하면, 클립에서 이루어지는 모든 화면 전환은 ClipCoordinator에서 관리하는 느낌입니다.
이때, 다음으로 이동할 뷰나 / 클로저에 대한 부분은 Coordinator가, 구체적으로 어떻게 화면을 전환할지는 Router가 담당하게 됩니다.

아래 코드를 살펴보면,
TabCoordinator에서는 클립 탭을 선택하면, ClipCoordinator를 생성하고 start() 메서드 부분이 동작합니다.
start에서는 ClipVC를 Factory에서 만들고 - router를 통한 화면 전환 방식을 정의하구 있죠.

final class ClipCoordinator: BaseCoordinator, CoordinatorFinishOutput {
var onFinish: (() -> Void)?
private let router: RouterProtocol
private let viewControllerFactory: ViewControllerFactoryProtocol
private let coordinatorFactory: CoordinatorFactoryProtocol
init(
router: RouterProtocol,
viewControllerFactory: ViewControllerFactoryProtocol,
coordinatorFactory: CoordinatorFactoryProtocol
) {
self.router = router
self.viewControllerFactory = viewControllerFactory
self.coordinatorFactory = coordinatorFactory
}
override func start() {
showClipVC()
}
}
private extension ClipCoordinator {
func showClipVC() {
let vc = viewControllerFactory.makeClipVC()
vc.onEditClipSelected = { [weak self] clipList in
self?.showEditClipVC(clipList: clipList)
}
vc.onClipItemSelected = { [weak self] clipId, clipName in
self?.showDetailClipVC(id: clipId, name: clipName)
}
router.setRoot(vc, animated: false)
}

쭉쭉쭉 클로저로 이어서 이어서 가면, 다음 VC를 만들고 - 화면을 전환하고 - 클로저 호출하고 이 부분이 반복되는 흐름입니다.

func showEditClipVC(clipList: ClipModel) {
let vc = viewControllerFactory.makeEditClipVC()
vc.setupDataBind(clipModel: clipList)
router.push(vc, animated: false, hideBottomBarWhenPushed: true)
}
func showDetailClipVC(id: Int, name: String) {
let vc = viewControllerFactory.makeDetailClipVC()
vc.setupCategory(id: id, name: name)
vc.onLinkSelected = { [weak self] linkURL, isRead, id in
self?.showLinkWebVC(linkURL: linkURL, isRead: isRead, id: id)
}
router.push(vc, animated: true, hideBottomBarWhenPushed: true)
}
func showLinkWebVC(linkURL: String, isRead: Bool, id: Int) {
let vc = viewControllerFactory.makeLinkWebVC()
vc.setupDataBind(linkURL: linkURL, isRead: isRead, id: id)
vc.onBack = { [weak self] in
self?.router.pop(animated: true)
}
router.push(vc, animated: true, hideBottomBarWhenPushed: true)
}

정리하면, 각 VC에서 흩어져있던 객체 생성과, 화면 전환 코드를 그냥 Coordinator라는 한 곳에서 모두 관리한다! 라고 생각하시면 되겠네요.
질문있으면, 디코에서 기다리고 있겠습니다.
그럼 다덜 화이팅.

✅ Checklist

  • 필요없는 주석, 프린트문 제거했는지 확인
  • 컨벤션 지켰는지 확인

@mini-min mini-min added ♻️ Refactor 전면 수정이 있을 때 사용합니다 🐻‍❄️ 민재 민재 선생님 작업 labels Jan 20, 2025
@mini-min mini-min self-assigned this Jan 20, 2025
@mini-min mini-min removed the request for review from yeahh315 January 20, 2025 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
♻️ Refactor 전면 수정이 있을 때 사용합니다 🐻‍❄️ 민재 민재 선생님 작업
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Refactor] 화면 전환 로직 Coordinator Router 분리
1 participant