From 9605250d0ed967fb045251a51f7c42ca8bd30c48 Mon Sep 17 00:00:00 2001 From: Xerath Date: Thu, 30 Nov 2023 14:08:45 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20AppCoordinator=20=EB=82=B4=20ext?= =?UTF-8?q?ension=20=EB=B6=84=EB=A6=AC,=20=ED=95=A8=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD,=20=EB=8B=A4=EC=A4=91=20pop=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MusicSpot.xcodeproj/project.pbxproj | 8 +- .../MSCoordinator/AppCoordinator.swift | 121 +++++++++++------- .../MSCoordinator/HomeMapCoordinator.swift | 12 +- .../MSCoordinator/RewindCoordinator.swift | 4 +- .../SaveJourneyCoordinator.swift | 8 +- .../SearchMusicCoordinator.swift | 8 +- .../MSCoordinator/SettingCoordinator.swift | 4 +- .../MSCoordinator/SpotCoordinator.swift | 8 +- 8 files changed, 99 insertions(+), 74 deletions(-) diff --git a/iOS/MusicSpot/MusicSpot.xcodeproj/project.pbxproj b/iOS/MusicSpot/MusicSpot.xcodeproj/project.pbxproj index 1fbc183..1551efe 100644 --- a/iOS/MusicSpot/MusicSpot.xcodeproj/project.pbxproj +++ b/iOS/MusicSpot/MusicSpot.xcodeproj/project.pbxproj @@ -79,14 +79,14 @@ 08CBF86F2B18468E007D3797 /* MSCoordinator */ = { isa = PBXGroup; children = ( - 08CBF8702B18468E007D3797 /* SaveJourneyCoordinator.swift */, + 08CBF8772B18468E007D3797 /* Coordinator.swift */, 08CBF8712B18468E007D3797 /* AppCoordinator.swift */, - 08CBF8722B18468E007D3797 /* RewindCoordinator.swift */, 08CBF8732B18468E007D3797 /* HomeMapCoordinator.swift */, - 08CBF8742B18468E007D3797 /* SettingCoordinator.swift */, 08CBF8752B18468E007D3797 /* SpotCoordinator.swift */, + 08CBF8722B18468E007D3797 /* RewindCoordinator.swift */, + 08CBF8742B18468E007D3797 /* SettingCoordinator.swift */, 08CBF8762B18468E007D3797 /* SearchMusicCoordinator.swift */, - 08CBF8772B18468E007D3797 /* Coordinator.swift */, + 08CBF8702B18468E007D3797 /* SaveJourneyCoordinator.swift */, ); path = MSCoordinator; sourceTree = ""; diff --git a/iOS/MusicSpot/MusicSpot/MSCoordinator/AppCoordinator.swift b/iOS/MusicSpot/MusicSpot/MSCoordinator/AppCoordinator.swift index 224f3d9..207dad5 100644 --- a/iOS/MusicSpot/MusicSpot/MSCoordinator/AppCoordinator.swift +++ b/iOS/MusicSpot/MusicSpot/MSCoordinator/AppCoordinator.swift @@ -7,13 +7,7 @@ import UIKit -final class AppCoordinator: Coordinator, - HomeMapCoordinatorDelegate, - SpotCoordinatorDelegate, - RewindCoordinatorDelegate, - SettingCoordinatorDelegate, - SearchMusicCoordinatorDelegate, - SaveJourneyCoordinatorDelegate { +final class AppCoordinator: Coordinator { // MARK: - Properties @@ -35,8 +29,27 @@ final class AppCoordinator: Coordinator, self.childCoordinators.append(homeMapCoordinator) homeMapCoordinator.start() } +} + +extension AppCoordinator { + + /// 현재 ViewController 아래에 깔린 ViewController 내에서 HomeMapViewController를 찾는 함수 + private func findHomeMapViewController() { + guard let homeMapViewController = navigationController.viewControllers.first(where: { $0 is HomeMapViewController }) else { + navigationController.setViewControllers([HomeMapViewController()], animated: true) + return + } - func navigateToSpot(coordinator: HomeMapCoordinator) { + navigationController.popToViewController(homeMapViewController, animated: true) + } +} + +// MARK: - HomeMapCoordinatorDelegate + +extension AppCoordinator: HomeMapCoordinatorDelegate { + + /// From: HomeMap, To: Spot + func pushToSpot(coordinator: HomeMapCoordinator) { let spotCoordinator = SpotCoordinator(navigationController: navigationController) spotCoordinator.delegate = self @@ -44,7 +57,8 @@ final class AppCoordinator: Coordinator, spotCoordinator.start() } - func navigateToRewind(coordinator: HomeMapCoordinator) { + /// From: HomeMap, To: Rewind + func pushToRewind(coordinator: HomeMapCoordinator) { let rewindCoordinator = RewindCoordinator(navigationController: navigationController) rewindCoordinator.delegate = self @@ -52,74 +66,85 @@ final class AppCoordinator: Coordinator, rewindCoordinator.start() } - func navigateToSetting(coordinator: HomeMapCoordinator) { + /// From: HomeMap, To: Setting + func pushToSetting(coordinator: HomeMapCoordinator) { let settingCoordinator = SettingCoordinator(navigationController: navigationController) settingCoordinator.delegate = self self.childCoordinators.append(settingCoordinator) settingCoordinator.start() } +} - func navigateToHomeMap(coordinator: SpotCoordinator) { - removeChildCoordinator(child: coordinator) - navigationController.popViewController(animated: true) - } +// MARK: - SpotCoordinatorDelegate - func navigateToHomeMap(coordinator: RewindCoordinator) { +extension AppCoordinator: SpotCoordinatorDelegate { + + /// From: Spot, To: HomeMap + func popToHomeMap(coordinator: SpotCoordinator) { removeChildCoordinator(child: coordinator) navigationController.popViewController(animated: true) } - - func navigateToHomeMap(coordinator: SettingCoordinator) { - navigationController.popViewController(animated: true) - } - - // MARK: - From: Spot - - func navigateToSearchMusic(coordinator: SpotCoordinator) { + + /// From: Spot, To: SearchMusic + func pushToSearchMusic(coordinator: SpotCoordinator) { let searchMusicCoordinator = SearchMusicCoordinator(navigationController: navigationController) searchMusicCoordinator.delegate = self self.childCoordinators.append(searchMusicCoordinator) searchMusicCoordinator.start() } +} - // MARK: - From: SearchMusic - - func navigateToHomeMap(coordinator: SearchMusicCoordinator) { - guard let homeMapViewController = navigationController.viewControllers.first(where: { - $0 is HomeMapViewController - }) else { - navigationController.setViewControllers([HomeMapViewController()], animated: true) - return - } +// MARK: - SearchMusicCoordinatorDelegate - while navigationController.topViewController !== homeMapViewController { - navigationController.popViewController(animated: true) - } +extension AppCoordinator: SearchMusicCoordinatorDelegate { + + /// From: SearchMusic, To: HomeMap + func popToHomeMap(coordinator: SearchMusicCoordinator) { + findHomeMapViewController() } - func navigateToSaveJourney(coordinator: SearchMusicCoordinator) { + /// From: SearchMusic, To: SaveJourney + func pushToSaveJourney(coordinator: SearchMusicCoordinator) { let saveJourneyCoordinator = SaveJourneyCoordinator(navigationController: navigationController) saveJourneyCoordinator.delegate = self self.childCoordinators.append(saveJourneyCoordinator) saveJourneyCoordinator.start() } +} - // MARK: - From: SaveJourney - func navigateToHomeMap(coordinator: SaveJourneyCoordinator) { - guard let homeMapViewController = navigationController.viewControllers.first(where: { - $0 is HomeMapViewController - }) else { - navigationController.setViewControllers([HomeMapViewController()], animated: true) - return - } +// MARK: - RewindCoordinatorDelegate - while navigationController.topViewController !== homeMapViewController { - navigationController.popViewController(animated: true) - } +extension AppCoordinator: RewindCoordinatorDelegate { + + /// From: Rewind, To: HomeMap + func popToHomeMap(coordinator: RewindCoordinator) { + removeChildCoordinator(child: coordinator) + navigationController.popViewController(animated: true) + } +} + +// MARK: - SettingCoordinatorDelegate + +extension AppCoordinator: SettingCoordinatorDelegate { + + /// From: Setting, To: HomeMap + func popToHomeMap(coordinator: SettingCoordinator) { + navigationController.popViewController(animated: true) + } +} + +// MARK: - SaveJourneyCoordinatorDelegate + +extension AppCoordinator: SaveJourneyCoordinatorDelegate { + + /// From: SaveJourney, To: HomeMap + func popToHomeMap(coordinator: SaveJourneyCoordinator) { + findHomeMapViewController() } - func navigateToSearchMusic(coordinator: SaveJourneyCoordinator) { + /// From: SaveJourney, To: SearchMusic + func popToSearchMusic(coordinator: SaveJourneyCoordinator) { let searchMusicCoordinator = SearchMusicCoordinator(navigationController: navigationController) searchMusicCoordinator.delegate = self self.childCoordinators.append(searchMusicCoordinator) diff --git a/iOS/MusicSpot/MusicSpot/MSCoordinator/HomeMapCoordinator.swift b/iOS/MusicSpot/MusicSpot/MSCoordinator/HomeMapCoordinator.swift index ae20cb8..b3b6106 100644 --- a/iOS/MusicSpot/MusicSpot/MSCoordinator/HomeMapCoordinator.swift +++ b/iOS/MusicSpot/MusicSpot/MSCoordinator/HomeMapCoordinator.swift @@ -8,9 +8,9 @@ import UIKit protocol HomeMapCoordinatorDelegate: AnyObject { - func navigateToSpot(coordinator: HomeMapCoordinator) - func navigateToRewind(coordinator: HomeMapCoordinator) - func navigateToSetting(coordinator: HomeMapCoordinator) + func pushToSpot(coordinator: HomeMapCoordinator) + func pushToRewind(coordinator: HomeMapCoordinator) + func pushToSetting(coordinator: HomeMapCoordinator) } final class HomeMapCoordinator: Coordinator, HomeMapViewControllerDelegate { @@ -38,14 +38,14 @@ final class HomeMapCoordinator: Coordinator, HomeMapViewControllerDelegate { } func goSpot() { - delegate?.navigateToSpot(coordinator: self) + delegate?.pushToSpot(coordinator: self) } func goRewind() { - delegate?.navigateToRewind(coordinator: self) + delegate?.pushToRewind(coordinator: self) } func goSetting() { - delegate?.navigateToSetting(coordinator: self) + delegate?.pushToSetting(coordinator: self) } } diff --git a/iOS/MusicSpot/MusicSpot/MSCoordinator/RewindCoordinator.swift b/iOS/MusicSpot/MusicSpot/MSCoordinator/RewindCoordinator.swift index 231d4c2..300fedd 100644 --- a/iOS/MusicSpot/MusicSpot/MSCoordinator/RewindCoordinator.swift +++ b/iOS/MusicSpot/MusicSpot/MSCoordinator/RewindCoordinator.swift @@ -8,7 +8,7 @@ import UIKit protocol RewindCoordinatorDelegate: AnyObject { - func navigateToHomeMap(coordinator: RewindCoordinator) + func popToHomeMap(coordinator: RewindCoordinator) } final class RewindCoordinator: Coordinator, RewindViewControllerDelegate { @@ -36,6 +36,6 @@ final class RewindCoordinator: Coordinator, RewindViewControllerDelegate { } func goHomeMap() { - delegate?.navigateToHomeMap(coordinator: self) + delegate?.popToHomeMap(coordinator: self) } } diff --git a/iOS/MusicSpot/MusicSpot/MSCoordinator/SaveJourneyCoordinator.swift b/iOS/MusicSpot/MusicSpot/MSCoordinator/SaveJourneyCoordinator.swift index 380e1be..f76b393 100644 --- a/iOS/MusicSpot/MusicSpot/MSCoordinator/SaveJourneyCoordinator.swift +++ b/iOS/MusicSpot/MusicSpot/MSCoordinator/SaveJourneyCoordinator.swift @@ -8,8 +8,8 @@ import UIKit protocol SaveJourneyCoordinatorDelegate: AnyObject { - func navigateToHomeMap(coordinator: SaveJourneyCoordinator) - func navigateToSearchMusic(coordinator: SaveJourneyCoordinator) + func popToHomeMap(coordinator: SaveJourneyCoordinator) + func popToSearchMusic(coordinator: SaveJourneyCoordinator) } final class SaveJourneyCoordinator: Coordinator, SaveJourneyViewControllerDelegate { @@ -37,10 +37,10 @@ final class SaveJourneyCoordinator: Coordinator, SaveJourneyViewControllerDelega } func goHomeMap() { - delegate?.navigateToHomeMap(coordinator: self) + delegate?.popToHomeMap(coordinator: self) } func goSearchMusic() { - delegate?.navigateToSearchMusic(coordinator: self) + delegate?.popToSearchMusic(coordinator: self) } } diff --git a/iOS/MusicSpot/MusicSpot/MSCoordinator/SearchMusicCoordinator.swift b/iOS/MusicSpot/MusicSpot/MSCoordinator/SearchMusicCoordinator.swift index 41d8d8f..ca84c89 100644 --- a/iOS/MusicSpot/MusicSpot/MSCoordinator/SearchMusicCoordinator.swift +++ b/iOS/MusicSpot/MusicSpot/MSCoordinator/SearchMusicCoordinator.swift @@ -8,8 +8,8 @@ import UIKit protocol SearchMusicCoordinatorDelegate: AnyObject { - func navigateToHomeMap(coordinator: SearchMusicCoordinator) - func navigateToSaveJourney(coordinator: SearchMusicCoordinator) + func popToHomeMap(coordinator: SearchMusicCoordinator) + func pushToSaveJourney(coordinator: SearchMusicCoordinator) } final class SearchMusicCoordinator: Coordinator, SearchMusicViewControllerDelegate { @@ -37,10 +37,10 @@ final class SearchMusicCoordinator: Coordinator, SearchMusicViewControllerDelega } func goHomeMap() { - delegate?.navigateToHomeMap(coordinator: self) + delegate?.popToHomeMap(coordinator: self) } func goSaveJourney() { - delegate?.navigateToSaveJourney(coordinator: self) + delegate?.pushToSaveJourney(coordinator: self) } } diff --git a/iOS/MusicSpot/MusicSpot/MSCoordinator/SettingCoordinator.swift b/iOS/MusicSpot/MusicSpot/MSCoordinator/SettingCoordinator.swift index 7695177..b8579af 100644 --- a/iOS/MusicSpot/MusicSpot/MSCoordinator/SettingCoordinator.swift +++ b/iOS/MusicSpot/MusicSpot/MSCoordinator/SettingCoordinator.swift @@ -8,7 +8,7 @@ import UIKit protocol SettingCoordinatorDelegate: AnyObject { - func navigateToHomeMap(coordinator: SettingCoordinator) + func popToHomeMap(coordinator: SettingCoordinator) } final class SettingCoordinator: Coordinator, SettingViewControllerDelegate { @@ -36,6 +36,6 @@ final class SettingCoordinator: Coordinator, SettingViewControllerDelegate { } func goHomeMap() { - delegate?.navigateToHomeMap(coordinator: self) + delegate?.popToHomeMap(coordinator: self) } } diff --git a/iOS/MusicSpot/MusicSpot/MSCoordinator/SpotCoordinator.swift b/iOS/MusicSpot/MusicSpot/MSCoordinator/SpotCoordinator.swift index 9b3f077..4c1c219 100644 --- a/iOS/MusicSpot/MusicSpot/MSCoordinator/SpotCoordinator.swift +++ b/iOS/MusicSpot/MusicSpot/MSCoordinator/SpotCoordinator.swift @@ -8,8 +8,8 @@ import UIKit protocol SpotCoordinatorDelegate: AnyObject { - func navigateToHomeMap(coordinator: SpotCoordinator) - func navigateToSearchMusic(coordinator: SpotCoordinator) + func popToHomeMap(coordinator: SpotCoordinator) + func pushToSearchMusic(coordinator: SpotCoordinator) } final class SpotCoordinator: Coordinator, SpotViewControllerDelegate { @@ -36,10 +36,10 @@ final class SpotCoordinator: Coordinator, SpotViewControllerDelegate { } func goHomeMap() { - delegate?.navigateToHomeMap(coordinator: self) + delegate?.popToHomeMap(coordinator: self) } func goSearchMusic() { - delegate?.navigateToSearchMusic(coordinator: self) + delegate?.pushToSearchMusic(coordinator: self) } }