Skip to content

Commit

Permalink
fix: CameraDisplayNavigator 추가
Browse files Browse the repository at this point in the history
- CameraDisplayViewController BBToast 메서드 추가
- CameraDisplayViewController 비즈니스 로직 수정
  • Loading branch information
Do-hyun-Kim committed Sep 26, 2024
1 parent 0e94bcd commit 2c89387
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ final class NavigatorDIContainer: BaseContainer {
)
}

container.register(type: CameraDisplayNavigatorProtocol.self) { _ in
CameraDisplayNavigator(
navigationController: makeUINavigationController()
)
}

container.register(type: ManagementNavigatorProtocol.self) { _ in
ManagementNavigator(
navigationController: makeUINavigationController()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// CameraDisplayNavigator.swift
// App
//
// Created by Kim dohyun on 9/26/24.
//

import Core
import DesignSystem
import UIKit

protocol CameraDisplayNavigatorProtocol: BaseNavigator {
func toHome()
func showToast()
func showArchiveToast()
func showWarningToast()
}

final class CameraDisplayNavigator: CameraDisplayNavigatorProtocol {

//MARK: - Properties
var navigationController: UINavigationController


//MARK: - Intializer
init(navigationController: UINavigationController) {
self.navigationController = navigationController
}

//MARK: - Configure
func toHome() {
let vc = MainViewControllerWrapper().viewController
navigationController.setViewControllers([vc], animated: true)
}

func showToast() {
let config = BBToastConfiguration(direction: .bottom(yOffset: -360), animationTime: 1.0)
let viewConfig = BBToastViewConfiguration(minWidth: 207)
BBToast.default(
image: DesignSystemAsset.warning.image,
title: "8자까지 입력 가능해요",
viewConfig: viewConfig,
config: config
).show()
}

func showArchiveToast() {
let config = BBToastConfiguration(direction: .bottom(yOffset: 75))
let viewConfig = BBToastViewConfiguration(minWidth: 194)
BBToast.default(
image: DesignSystemAsset.camera.image.withTintColor(DesignSystemAsset.gray300.color),
title: "사진이 저장되었습니다.",
viewConfig: viewConfig,
config: config
).show()
}

func showWarningToast() {
let config = BBToastConfiguration(direction: .bottom(yOffset: -360), animationTime: 1.0)
let viewConfig = BBToastViewConfiguration(minWidth: 207)
BBToast.default(
image: DesignSystemAsset.warning.image,
title: "띄어쓰기는 할 수 없어요",
viewConfig: viewConfig,
config: config
).show()

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public final class CameraDisplayViewController: BaseViewController<CameraDisplay

archiveButton
.rx.tap
.throttle(.seconds(1), scheduler: MainScheduler.instance)
.throttle(RxInterval._600milliseconds, scheduler: RxScheduler.main)
.map { Reactor.Action.didTapArchiveButton }
.bind(to: reactor.action)
.disposed(by: disposeBag)
Expand Down Expand Up @@ -245,21 +245,24 @@ public final class CameraDisplayViewController: BaseViewController<CameraDisplay
displayEditTextField.rx
.text.orEmpty
.filter { $0.contains(" ")}
.map { $0.trimmingCharacters(in: .whitespaces)}
.map { Reactor.Action.showInputBlankTextError($0)}
.bind(to: reactor.action)
.disposed(by: disposeBag)

reactor.pulse(\.$displayText)
.bind(to: displayEditTextField.rx.text)
.disposed(by: disposeBag)

displayEditTextField.rx
.text.orEmpty
.map { $0.contains(" ") }
.text.changed
.compactMap { $0 }
.filter { $0.contains(" ") }
.debug("카메라 상세 공백 체크")
.distinctUntilChanged()
.debounce(.seconds(1), scheduler: MainScheduler.instance)
.withUnretained(self)
.bind { owner, isShow in
guard isShow == true else { return }
owner.makeBibbiToastView(text: "띄어쓰기는 할 수 없어요", image: DesignSystemAsset.warning.image, duration: 1, delay: 1, offset: 400)
}.disposed(by: disposeBag)

.map { _ in Reactor.Action.showInputTextError }
.bind(to: reactor.action)
.disposed(by: disposeBag)

reactor.pulse(\.$isError)
.filter { $0 }
.withUnretained(self)
Expand All @@ -268,16 +271,16 @@ public final class CameraDisplayViewController: BaseViewController<CameraDisplay

displayEditTextField.rx
.text.orEmpty
.map { ($0.count > 8) }
.debounce(.milliseconds(300), scheduler: MainScheduler.instance)
.withUnretained(self)
.bind { owner, isShow in
guard isShow == true else { return }
owner.makeBibbiToastView(text: "8자까지 입력가능해요", image: DesignSystemAsset.warning.image, offset: 400)
}.disposed(by: disposeBag)
.filter{ $0.count > 8 }
.debounce(RxInterval._600milliseconds, scheduler: RxScheduler.main)
.map { _ in Reactor.Action.showInputTextError }
.bind(to: reactor.action)
.disposed(by: disposeBag)

displayEditTextField.rx
.text.orEmpty
.filter { !$0.contains(" ")}
.debounce(RxInterval._600milliseconds, scheduler: RxScheduler.main)
.scan("") { previous, new -> String in
if new.count > 8 {
return previous
Expand All @@ -290,7 +293,7 @@ public final class CameraDisplayViewController: BaseViewController<CameraDisplay

confirmButton.rx
.tap
.throttle(.seconds(1), scheduler: MainScheduler.instance)
.throttle(RxInterval._600milliseconds, scheduler: RxScheduler.main)
.map { Reactor.Action.didTapConfirmButton}
.bind(to: reactor.action)
.disposed(by: disposeBag)
Expand All @@ -303,7 +306,7 @@ public final class CameraDisplayViewController: BaseViewController<CameraDisplay

displayEditButton
.rx.tap
.throttle(.milliseconds(300), scheduler: MainScheduler.instance)
.throttle(RxInterval._600milliseconds, scheduler: RxScheduler.main)
.withLatestFrom(reactor.state.map{ $0.displayDescrption })
.filter { $0.isValidation() }
.withUnretained(self)
Expand All @@ -314,15 +317,14 @@ public final class CameraDisplayViewController: BaseViewController<CameraDisplay
displayEditCollectionView
.rx.tap
.observe(on: MainScheduler.instance)
.throttle(.milliseconds(300), scheduler: MainScheduler.instance)
.throttle(RxInterval._300milliseconds, scheduler: RxScheduler.main)
.withUnretained(self)
.bind(onNext: { $0.0.didTapCollectionViewTransition()})
.disposed(by: disposeBag)

displayDimView
.rx.tap
.throttle(.milliseconds(300), scheduler: MainScheduler.instance)
.observe(on: MainScheduler.instance)
.throttle(RxInterval._300milliseconds, scheduler: RxScheduler.main)
.withUnretained(self)
.bind { owner, _ in
owner.view.endEditing(true)
Expand Down Expand Up @@ -388,12 +390,6 @@ public final class CameraDisplayViewController: BaseViewController<CameraDisplay
.drive(displayIndicatorView.rx.isHidden)
.disposed(by: disposeBag)

reactor.pulse(\.$displayData)
.skip(until: rx.methodInvoked(#selector(viewWillAppear(_:))))
.withUnretained(self)
.bind(onNext: { $0.0.setupCameraDisplayPermission($0.1) })
.disposed(by: disposeBag)

displayEditCollectionView.rx
.setDelegate(self)
.disposed(by: disposeBag)
Expand All @@ -403,14 +399,6 @@ public final class CameraDisplayViewController: BaseViewController<CameraDisplay
.asDriver(onErrorJustReturn: [])
.drive(displayEditCollectionView.rx.items(dataSource: displayEditDataSources))
.disposed(by: disposeBag)

reactor.state
.compactMap { $0.displayPostEntity?.postId }
.filter { !$0.isEmpty }
.withUnretained(self)
.bind(onNext: { $0.0.transitionToHomeViewController()})
.disposed(by: disposeBag)

}
}

Expand All @@ -423,10 +411,6 @@ extension CameraDisplayViewController {
guard let `self` = self else { return }
let creationRequest = PHAssetCreationRequest.forAsset()
creationRequest.addResource(with: .photo, data: originalData, options: nil)
self.makeBibbiToastView(
text: "사진이 저장되었습니다.",
image: DesignSystemAsset.camera.image.withTintColor(DesignSystemAsset.gray300.color)
)
}
} else {
PHPhotoLibrary.requestAuthorization(for: .addOnly) { stauts in
Expand Down Expand Up @@ -506,9 +490,6 @@ extension CameraDisplayViewController {
present(permissionAlertController, animated: true)
}

private func transitionToHomeViewController() {
self.navigationController?.popToRootViewController(animated: true)
}
}

extension CameraDisplayViewController: UICollectionViewDelegateFlowLayout {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ public final class CameraDisplayViewReactor: Reactor {
@Injected private var createPresignedCameraUseCase: CreateCameraUseCaseProtocol
@Injected private var uploadImageUseCase: FetchCameraUploadImageUseCaseProtocol
@Injected private var fetchCameraImageUseCase: CreateCameraImageUseCaseProtocol
@Navigator private var cameraDisplayNavigator: CameraDisplayNavigatorProtocol

public enum Action {
case viewDidLoad
case didTapArchiveButton
case fetchDisplayImage(String)
case didTapConfirmButton
case hideDisplayEditCell
case showInputTextError
case showInputBlankTextError(String)
}

public enum Mutation {
Expand All @@ -35,6 +38,7 @@ public final class CameraDisplayViewReactor: Reactor {
case setRenderImage(Data)
case saveDeviceimage(Data)
case setDescription(String)
case setTrimedText(String)
case setDisplayEntity(CameraPreSignedEntity?)
case setDisplayOriginalEntity(Bool)
case setPostEntity(CameraPostEntity?)
Expand All @@ -51,6 +55,7 @@ public final class CameraDisplayViewReactor: Reactor {
@Pulse var displayEntity: CameraPreSignedEntity?
@Pulse var displayOringalEntity: Bool
@Pulse var displayPostEntity: CameraPostEntity?
@Pulse var displayText: String
}


Expand All @@ -70,7 +75,8 @@ public final class CameraDisplayViewReactor: Reactor {
displaySection: [.displayKeyword([])],
displayEntity: nil,
displayOringalEntity: false,
displayPostEntity: nil
displayPostEntity: nil,
displayText: ""
)
}

Expand Down Expand Up @@ -134,6 +140,7 @@ public final class CameraDisplayViewReactor: Reactor {
}
)
case .didTapArchiveButton:
cameraDisplayNavigator.showArchiveToast()
return .concat(
.just(.setLoading(false)),
.just(.saveDeviceimage(currentState.displayData)),
Expand All @@ -157,16 +164,18 @@ public final class CameraDisplayViewReactor: Reactor {
return fetchCameraImageUseCase.execute(parameter: parameters, query: cameraQuery)
.asObservable()
.catchAndReturn(nil)
.flatMap { entity -> Observable<CameraDisplayViewReactor.Mutation> in
.withUnretained(self)
.flatMap { owner, entity -> Observable<CameraDisplayViewReactor.Mutation> in
if entity == nil {
return .just(.setError(true))
} else {
owner.cameraDisplayNavigator.toHome()
return .concat(
.just(.setLoading(false)),
.just(.setPostEntity(entity)),
.just(.setLoading(true)),
.just(.setError(false)),
self.provider.mainService.refreshMain()
owner.provider.mainService.refreshMain()
.flatMap { _ in Observable<Mutation>.empty() }
)
}
Expand All @@ -176,6 +185,14 @@ public final class CameraDisplayViewReactor: Reactor {
.just(.setDescription("")),
.just(.setDisplayEditSection([]))
)
case .showInputTextError:
cameraDisplayNavigator.showToast()
return .empty()

case let .showInputBlankTextError(displayText):
cameraDisplayNavigator.showWarningToast()
let generateText = displayText.trimmingCharacters(in: .whitespaces)
return .just(.setTrimedText(generateText))
}
}

Expand All @@ -202,6 +219,8 @@ public final class CameraDisplayViewReactor: Reactor {
newState.displayPostEntity = entity
case let .setError(isError):
newState.isError = isError
case let .setTrimedText(displayText):
newState.displayText = displayText
}
return newState
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ private extension BBToastConfiguration {
switch direction {
case let .top(yOffset):
return .custom(
transformation: CGAffineTransform(scaleX: 0.9, y: 0.9).translatedBy(x: 0, y: -yOffset - 100)
transformation: CGAffineTransform(scaleX: 0.9, y: 0.9).translatedBy(x: 0, y: -yOffset - 300)
)

case let .bottom(yOffset):
return .custom(
transformation: CGAffineTransform(scaleX: 0.9, y: 0.9).translatedBy(x: 0, y: +yOffset + 100)
transformation: CGAffineTransform(scaleX: 0.9, y: 0.9).translatedBy(x: 0, y: -yOffset + 300)
)

case .center:
Expand Down

0 comments on commit 2c89387

Please sign in to comment.