From 34098939609549070ce2ff2958778f54fb711466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Junnos=20=EF=A3=BF?= Date: Wed, 10 Jan 2024 16:43:01 +0900 Subject: [PATCH] =?UTF-8?q?:bug:=20Spot=20=EC=99=84=EB=A3=8C=20Navigation?= =?UTF-8?q?=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Presentation/SaveSpotViewController.swift | 8 +++----- .../Spot/Presentation/SaveSpotViewModel.swift | 15 ++++++++------- .../Spot/Presentation/SpotViewController.swift | 8 +------- .../Spot/Presentation/SpotViewModel.swift | 4 +--- .../MusicSpot/Coordinator/SpotCoordinator.swift | 16 ++++++++++------ 5 files changed, 23 insertions(+), 28 deletions(-) diff --git a/iOS/Features/Spot/Sources/Spot/Presentation/SaveSpotViewController.swift b/iOS/Features/Spot/Sources/Spot/Presentation/SaveSpotViewController.swift index 77f9e50..f6a882e 100644 --- a/iOS/Features/Spot/Sources/Spot/Presentation/SaveSpotViewController.swift +++ b/iOS/Features/Spot/Sources/Spot/Presentation/SaveSpotViewController.swift @@ -114,10 +114,9 @@ public final class SaveSpotViewController: UIViewController { // MARK: - Combine Binding private func bind() { - self.viewModel.state.spot + self.viewModel.state.uploadedSpot .receive(on: DispatchQueue.main) .sink { [weak self] spot in - guard let spot = spot else { return } self?.navigationDelegate?.popToHome(spot: spot) } .store(in: &self.cancellables) @@ -262,12 +261,11 @@ public final class SaveSpotViewController: UIViewController { private func completeButtonDidTap() { guard let jpegData = self.image.jpegData(compressionQuality: 0.1) else { - MSLogger.make(category: .spot).debug("현재 이미지를 Data로 변환할 수 없습니다.") + MSLogger.make(category: .spot).warning("현재 이미지를 Data로 변환할 수 없습니다.") return } - self.viewModel.trigger(.startUploadSpot(jpegData)) - self.navigationDelegate?.popToHome() + self.viewModel.trigger(.uploadSpot(jpegData)) } } diff --git a/iOS/Features/Spot/Sources/Spot/Presentation/SaveSpotViewModel.swift b/iOS/Features/Spot/Sources/Spot/Presentation/SaveSpotViewModel.swift index 941d19b..6db1c41 100644 --- a/iOS/Features/Spot/Sources/Spot/Presentation/SaveSpotViewModel.swift +++ b/iOS/Features/Spot/Sources/Spot/Presentation/SaveSpotViewModel.swift @@ -15,11 +15,12 @@ import MSLogger public final class SaveSpotViewModel { public enum Action { - case startUploadSpot(Data) + case uploadSpot(Data) } public struct State { - public var spot = PassthroughSubject() + // Passthrough + public var uploadedSpot = PassthroughSubject() } // MARK: - Properties @@ -51,21 +52,21 @@ internal extension SaveSpotViewModel { func trigger(_ action: Action) { switch action { - case .startUploadSpot(let data): + case .uploadSpot(let data): Task { guard let recordingJourneyID = self.journeyRepository.recordingJourneyID else { MSLogger.make(category: .spot).error("recoding 중인 journeyID를 찾지 못하였습니다.") return } let spot = RequestableSpot(journeyID: recordingJourneyID, - coordinate: self.coordinate, - timestamp: .now, - photoData: data) + coordinate: self.coordinate, + timestamp: .now, + photoData: data) let result = await self.spotRepository.upload(spot: spot) switch result { case .success(let spot): - self.state.spot.send(spot) + self.state.uploadedSpot.send(spot) MSLogger.make(category: .network).debug("성공적으로 업로드되었습니다: \(spot)") case .failure(let error): MSLogger.make(category: .network).error("\(error): 업로드에 실패하였습니다.") diff --git a/iOS/Features/Spot/Sources/Spot/Presentation/SpotViewController.swift b/iOS/Features/Spot/Sources/Spot/Presentation/SpotViewController.swift index bf6bf73..833421d 100644 --- a/iOS/Features/Spot/Sources/Spot/Presentation/SpotViewController.swift +++ b/iOS/Features/Spot/Sources/Spot/Presentation/SpotViewController.swift @@ -351,13 +351,7 @@ extension SpotViewController: UIImagePickerControllerDelegate { self.presentSpotSaveViewController(with: image, coordinate: self.viewModel.coordinate) } -} - -// MARK: - Functions - -private extension SpotViewController { - - func presentSpotSaveViewController(with image: UIImage, coordinate: Coordinate) { + private func presentSpotSaveViewController(with image: UIImage, coordinate: Coordinate) { self.viewModel.stopCamera() self.navigationDelegate?.presentSaveSpot(using: image, coordinate: coordinate) } diff --git a/iOS/Features/Spot/Sources/Spot/Presentation/SpotViewModel.swift b/iOS/Features/Spot/Sources/Spot/Presentation/SpotViewModel.swift index ce2d960..d4a6dc9 100644 --- a/iOS/Features/Spot/Sources/Spot/Presentation/SpotViewModel.swift +++ b/iOS/Features/Spot/Sources/Spot/Presentation/SpotViewModel.swift @@ -50,9 +50,7 @@ public final class SpotViewModel: NSObject { weak var delegate: ShotDelegate? var swapMode: SwapMode = .back { - didSet { - self.configureSwapMode() - } + didSet { self.configureSwapMode() } } private let session = AVCaptureSession() diff --git a/iOS/MusicSpot/MusicSpot/Coordinator/SpotCoordinator.swift b/iOS/MusicSpot/MusicSpot/Coordinator/SpotCoordinator.swift index 3f6cd34..95a45af 100644 --- a/iOS/MusicSpot/MusicSpot/Coordinator/SpotCoordinator.swift +++ b/iOS/MusicSpot/MusicSpot/Coordinator/SpotCoordinator.swift @@ -51,7 +51,7 @@ extension SpotCoordinator: SpotNavigationDelegate { picker.sourceType = .photoLibrary picker.allowsEditing = true picker.delegate = spotViewController - spotViewController.present(picker, animated: true) + self.navigationController.present(picker, animated: true) } func presentSaveSpot(using image: UIImage, coordinate: Coordinate) { @@ -61,10 +61,12 @@ extension SpotCoordinator: SpotNavigationDelegate { spotRepository: spotRepository, coordinate: coordinate) let spotSaveViewController = SaveSpotViewController(image: image, viewModel: viewModel) - spotSaveViewController.modalPresentationStyle = .fullScreen + spotSaveViewController.modalPresentationStyle = .overFullScreen spotSaveViewController.navigationDelegate = self - self.navigationController.presentedViewController?.dismiss(animated: true) - self.navigationController.present(spotSaveViewController, animated: true) + + self.navigationController.presentedViewController?.dismiss(animated: true) { [weak self] in + self?.navigationController.present(spotSaveViewController, animated: true) + } } func dismissToSpot() { @@ -76,8 +78,10 @@ extension SpotCoordinator: SpotNavigationDelegate { spotSaveViewController.dismiss(animated: true) } - func popToHome(spot: Spot? = nil) { - self.finish() + func popToHome(spot: Spot?) { + self.navigationController.presentedViewController?.dismiss(animated: true) { [weak self] in + self?.finish() + } } }