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

[iOS] 코디네이터 리팩토링 #343

Merged
merged 4 commits into from
Jan 7, 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
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,22 @@ public final class RecordJourneyButtonStackView: UIView {
}

private func configureBackButtonAction() {
let backButtonAction = UIAction { _ in
self.backButtonDidTap()
let backButtonAction = UIAction { [weak self] _ in
self?.backButtonDidTap()
}
self.backButton.addAction(backButtonAction, for: .touchUpInside)
}

private func configureSpotButtonAction() {
let spotButtonAction = UIAction { _ in
self.spotButtonDidTap()
let spotButtonAction = UIAction { [weak self] _ in
self?.spotButtonDidTap()
}
self.spotButton.addAction(spotButtonAction, for: .touchUpInside)
}

private func configureNextButtonAction() {
let nextButtonAction = UIAction { _ in
self.nextButtonDidTap()
let nextButtonAction = UIAction { [weak self] _ in
self?.nextButtonDidTap()
}
self.nextButton.addAction(nextButtonAction, for: .touchUpInside)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import Foundation

public protocol RewindJourneyNavigationDelegate: AnyObject {

func popToHomeMap()
func popToHome()

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal extension RewindJourneyViewController {
}
case .ended, .cancelled:
if touchPoint.x - self.initialTouchPoint.x > Metric.movedXPositionToBackScene {
self.navigationDelegate?.popToHomeMap()
self.navigationDelegate?.popToHome()
} else {
self.view.frame = CGRect(x: .zero,
y: .zero,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import MSDomain

public protocol SaveJourneyNavigationDelegate: AnyObject {

func popToHome(with endedJourney: Journey)
func popToHome()
func popToSelectSong()

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ extension SaveJourneyViewController {
// MARK: - Configuration: CollectionView

func configureCollectionView() {
let layout = UICollectionViewCompositionalLayout(sectionProvider: { sectionIndex, _ in
guard let section = self.dataSource?.sectionIdentifier(for: sectionIndex) else { return .none }
return self.configureSection(for: section)
let layout = UICollectionViewCompositionalLayout(sectionProvider: { [weak self] sectionIndex, _ in
guard let section = self?.dataSource?.sectionIdentifier(for: sectionIndex) else { return .none }
return self?.configureSection(for: section)
})
layout.register(SaveJourneyBackgroundView.self,
forDecorationViewOfKind: SaveJourneyBackgroundView.elementKind)
Expand Down Expand Up @@ -105,12 +105,12 @@ extension SaveJourneyViewController {
let emptyCellRegistration = EmptyCellRegistration { _, _, _ in }

let headerRegistration = HeaderRegistration(elementKind: SaveJourneyHeaderView.elementKind,
handler: { header, _, indexPath in
handler: { [weak self] header, _, indexPath in
switch indexPath.section {
case .zero:
header.update(with: Typo.songSectionTitle)
case 1:
guard let spots = self.viewModel.state.recordingJourney.value?.spots else { return }
guard let spots = self?.viewModel.state.recordingJourney.value?.spots else { return }
header.update(with: Typo.spotSectionTitle(spots.count))
default:
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Combine
import CoreLocation
import MapKit
import MusicKit
import StoreKit
import SwiftUI
import UIKit

Expand Down Expand Up @@ -138,7 +137,11 @@ public final class SaveJourneyViewController: UIViewController {

public override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)

self.musicPlayer.pause()
if self.isMovingFromParent {
self.navigationDelegate?.popToSelectSong()
}
}

// MARK: - Combine Binding
Expand Down Expand Up @@ -194,8 +197,8 @@ public final class SaveJourneyViewController: UIViewController {

self.viewModel.state.endJourneySucceed
.receive(on: DispatchQueue.main)
.sink { [weak self] endedJourney in
self?.navigationDelegate?.popToHome(with: endedJourney)
.sink { [weak self] _ in
self?.navigationDelegate?.popToHome()
}
.store(in: &self.cancellables)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public final class SaveJourneyViewModel {
#endif
self.state.musicAuthorizatonStatus.send(status)
}

Task {
let subscription = try await MusicSubscription.current
#if DEBUG
Expand Down Expand Up @@ -96,7 +96,7 @@ private extension SaveJourneyViewModel {
func endJourney(named title: String) {
guard let recordingJourney = self.state.recordingJourney.value else { return }
guard let journeyID = self.journeyRepository.fetchRecordingJourneyID() else { return }

let selectedSong = self.state.selectedSong.value
let coordinates = recordingJourney.coordinates + [self.lastCoordiante]
let journey = Journey(id: journeyID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public protocol SelectSongNavigationDelegate: AnyObject {

func navigateToSaveJourney(lastCoordinate: Coordinate,
selectedSong: Song)
func popToHome()

}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ public final class SelectSongViewController: BaseViewController {
self.searchTextField.becomeFirstResponder()
}

public override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)

if self.isMovingFromParent {
self.navigationDelegate?.popToHome()
}
}

// MARK: - Combine Binding

private func bind() {
Expand Down Expand Up @@ -185,8 +193,8 @@ public final class SelectSongViewController: BaseViewController {
private extension SelectSongViewController {

func configureCollectionView() {
let layout = UICollectionViewCompositionalLayout(sectionProvider: { _, _ in
return self.configureSection()
let layout = UICollectionViewCompositionalLayout(sectionProvider: { [weak self] _, _ in
return self?.configureSection()
})

self.collectionView.setCollectionViewLayout(layout, animated: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ import MSDomain

public protocol SpotNavigationDelegate: AnyObject {

func presentPhotos(from viewController: UIViewController)
func presentSpotSave(using image: UIImage, coordinate: Coordinate)
func presentPhotoLibrary(from viewController: UIViewController)
func presentSaveSpot(using image: UIImage, coordinate: Coordinate)
func dismissToSpot()
func popToHome()
func popToHomeWithSpot(spot: Spot)
func popToHome(spot: Spot?)

}

extension SpotNavigationDelegate {

public func popToHome(spot: Spot? = nil) {
self.popToHome(spot: nil)
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// SpotViewController.swift
// SaveSpotViewController.swift
// Spot
//
// Created by 전민건 on 11/22/23.
Expand All @@ -13,7 +13,7 @@ import MSDesignSystem
import MSLogger
import MSUIKit

public final class SpotSaveViewController: UIViewController {
public final class SaveSpotViewController: UIViewController {

// MARK: - Constants

Expand Down Expand Up @@ -60,7 +60,7 @@ public final class SpotSaveViewController: UIViewController {
// MARK: - Properties

public weak var navigationDelegate: SpotNavigationDelegate?
private let viewModel: SpotSaveViewModel
private let viewModel: SaveSpotViewModel
private let image: UIImage

private var cancellables: Set<AnyCancellable> = []
Expand All @@ -82,7 +82,7 @@ public final class SpotSaveViewController: UIViewController {
// MARK: - Initializer

public init(image: UIImage,
viewModel: SpotSaveViewModel,
viewModel: SaveSpotViewModel,
nibName nibNameOrNil: String? = nil,
bundle nibBundleOrNil: Bundle? = nil) {
self.image = image
Expand Down Expand Up @@ -118,7 +118,7 @@ public final class SpotSaveViewController: UIViewController {
.receive(on: DispatchQueue.main)
.sink { [weak self] spot in
guard let spot = spot else { return }
self?.navigationDelegate?.popToHomeWithSpot(spot: spot)
self?.navigationDelegate?.popToHome(spot: spot)
}
.store(in: &self.cancellables)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// SpotSaveViewModel.swift
// SaveSpotViewModel.swift
// Spot
//
// Created by 전민건 on 11/29/23.
Expand All @@ -12,7 +12,7 @@ import MSData
import MSDomain
import MSLogger

public final class SpotSaveViewModel {
public final class SaveSpotViewModel {

public enum Action {
case startUploadSpot(Data)
Expand Down Expand Up @@ -47,7 +47,7 @@ public final class SpotSaveViewModel {

// MARK: - Interface: Actions

internal extension SpotSaveViewModel {
internal extension SaveSpotViewModel {

func trigger(_ action: Action) {
switch action {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,30 +261,30 @@ private extension SpotViewController {
}

func configureShotButtonAction() {
let shotButtonAction = UIAction(handler: { _ in
self.shotButtonTapped()
})
let shotButtonAction = UIAction { [weak self] _ in
self?.shotButtonTapped()
}
self.shotButton.addAction(shotButtonAction, for: .touchUpInside)
}

func configureSwapButtonAction() {
let swapButtonAction = UIAction(handler: { _ in
self.swapButtonTapped()
})
let swapButtonAction = UIAction { [weak self] _ in
self?.swapButtonTapped()
}
self.swapButton.addAction(swapButtonAction, for: .touchUpInside)
}

func configureGalleryButtonAction() {
let galleryButtonAction = UIAction(handler: { _ in
self.galleryButtonTapped()
})
let galleryButtonAction = UIAction { [weak self] _ in
self?.galleryButtonTapped()
}
self.galleryButton.addAction(galleryButtonAction, for: .touchUpInside)
}

func configureBackButtonAction() {
let backButtonAction = UIAction(handler: { _ in
self.backButtonTapped()
})
let backButtonAction = UIAction { [weak self] _ in
self?.backButtonTapped()
}
self.backButton.addAction(backButtonAction, for: .touchUpInside)
}

Expand All @@ -304,7 +304,7 @@ private extension SpotViewController {
}

func galleryButtonTapped() {
self.navigationDelegate?.presentPhotos(from: self)
self.navigationDelegate?.presentPhotoLibrary(from: self)
}

func backButtonTapped() {
Expand Down Expand Up @@ -359,7 +359,7 @@ private extension SpotViewController {

func presentSpotSaveViewController(with image: UIImage, coordinate: Coordinate) {
self.viewModel.stopCamera()
self.navigationDelegate?.presentSpotSave(using: image, coordinate: coordinate)
self.navigationDelegate?.presentSaveSpot(using: image, coordinate: coordinate)
}

}
Loading