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

[Test] Gift #185

Merged
merged 4 commits into from
Jul 28, 2023
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
2 changes: 1 addition & 1 deletion Favor/Favor/Sources/Flows/AppFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private extension AppFlow {
let navigationControllers: [BaseNavigationController] = [homeNC, myPageNC]
self.rootViewController.setViewControllers(navigationControllers, animated: false)
}

return [
.contribute(
withNextPresentable: homeFlow,
Expand Down
6 changes: 3 additions & 3 deletions Favor/Favor/Sources/Flows/GiftFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ final class GiftFlow: Flow {

case .giftDetailFriendsBottomSheetIsRequired(let friends):
return self.navigateToFriends(with: friends)

case .friendPageIsRequired(let friend):
return self.navigateToFriendPage(with: friend)

Expand Down Expand Up @@ -205,7 +205,7 @@ private extension GiftFlow {
withNextStepper: friendPageReactor
))
}

func popToGiftDetail(with gift: Gift? = nil) -> FlowContributors {
// TODO: 메모리 해제
DispatchQueue.main.async {
Expand All @@ -219,7 +219,7 @@ private extension GiftFlow {

return .none
}

func navigateToGiftShare(with gift: Gift) -> FlowContributors {
let giftShareVC = GiftShareViewController()
let giftShareReactor = GiftShareViewReactor(gift: gift)
Expand Down
26 changes: 0 additions & 26 deletions Favor/Favor/Sources/Flows/HomeFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,30 +86,4 @@ private extension HomeFlow {
withNextStepper: OneStepper(withSingleStep: AppStep.giftDetailIsRequired(gift))
))
}

// func navigateToFilter(sortedBy sortType: SortType) -> FlowContributors {
// let filterBottomSheet = FilterBottomSheet()
// filterBottomSheet.currentSortType = sortType
// filterBottomSheet.modalPresentationStyle = .overFullScreen
// self.rootViewController.present(filterBottomSheet, animated: false)
// self.filterBottomSheet = filterBottomSheet
//
// return .one(flowContributor: .contribute(
// withNextPresentable: filterBottomSheet,
// withNextStepper: filterBottomSheet
// ))
// }

// func dismissFilter(sortedBy sortType: SortType) -> FlowContributors {
// self.filterBottomSheet?.animateDismissView()
// self.filterBottomSheet = nil
//
// guard let homeVC = self.rootViewController.topViewController as? HomeViewController else {
// return .none
// }
// // TODO: Realm DB 구현하며 Sort, Filter 방식 변경
//// homeVC.reactor?.currentSortType.accept(sortType)
//// homeVC.filterDidEnded()
// return .none
// }
}
3 changes: 1 addition & 2 deletions Favor/Favor/Sources/Flows/NewGiftFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ private extension NewGiftFlow {
withNextStepper: reactor
))
}

@MainActor
func popToTabBar(with gift: Gift? = nil) -> FlowContributors {
self.rootViewController.dismiss(animated: true)

return .end(forwardToParentFlowWithStep: AppStep.dashboardIsRequired)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ final class FavorTabBar: UITabBar {

extension FavorTabBar: BaseView {
func setupStyles() {
self.backgroundColor = .favorColor(.white)
self.barTintColor = .favorColor(.white)
self.backgroundColor = .clear
self.barTintColor = .clear
}

func setupLayouts() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ final class GiftDetailViewController: BaseViewController, View {
.disposed(by: self.disposeBag)

self.deleteButton.rx.tap
.map { Reactor.Action.deleteButtonDidTap }
.bind(to: reactor.action)
.asDriver()
.drive(with: self) { owner, _ in owner.presentRemovalPopup() }
.disposed(by: self.disposeBag)

self.shareButton.rx.tap
Expand All @@ -126,7 +126,7 @@ final class GiftDetailViewController: BaseViewController, View {
}
.bind(to: reactor.action)
.disposed(by: self.disposeBag)

// State
Observable.combineLatest(self.rx.viewDidLoad, reactor.state.map { $0.items })
.debounce(.milliseconds(100), scheduler: MainScheduler.instance)
Expand Down Expand Up @@ -161,7 +161,7 @@ final class GiftDetailViewController: BaseViewController, View {
}

// MARK: - Functions

public func update(gift: Gift) {
guard let reactor = self.reactor else { return }
reactor.action.onNext(.giftNeedsUpdated(gift))
Expand All @@ -180,7 +180,7 @@ final class GiftDetailViewController: BaseViewController, View {
animated: false
)
}

override func setupLayouts() {
self.view.addSubview(self.collectionView)
}
Expand Down Expand Up @@ -267,7 +267,7 @@ private extension GiftDetailViewController {
totalPages: self.totalPages.asObservable()
)
}

self.dataSource?.supplementaryViewProvider = { [weak self] collectionView, kind, indexPath in
guard self != nil else { return UICollectionReusableView() }
switch kind {
Expand All @@ -279,6 +279,20 @@ private extension GiftDetailViewController {
}
}
}

/// `deleteButton`을 클릭하면 `Popup`으로 전환되는 메서드
func presentRemovalPopup() {
let removalPopup = NewAlertPopup(
.onlyTitle(
title: "삭제 하시겠습니까?",
NewAlertPopup.ActionButtons(reject: "취소", accept: "삭제")
),
identifier: "RemoveGift"
)
removalPopup.delegate = self
removalPopup.modalPresentationStyle = .overFullScreen
self.present(removalPopup, animated: false)
}
}

// MARK: - GiftDetailTitleCell
Expand Down Expand Up @@ -347,3 +361,13 @@ extension GiftDetailViewController: GalleryItemsDataSource {
]
}
}

// MARK: - RemovalPopup

extension GiftDetailViewController: AlertPopupDelegate {
/// `AlertPopup`에서 `삭제`버튼을 눌렀을 때 호출됩니다.
func actionDidSelected(_ isAccepted: Bool, from identifier: String) {
guard isAccepted else { return }
self.reactor?.action.onNext(.deleteButtonDidTap)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ final class GiftManagementViewReactor: Reactor, Stepper {
case updateMemo(String?)
case updateIsPinned(Bool)
}

struct State {
var viewType: GiftManagementViewController.ViewType
var giftType: GiftManagementViewController.GiftType = .received
var isEnabledDoneButton: Bool = false
var gift: Gift

var sections: [Section] = [.title, .category, .photos, .friends(isGiven: false), .date, .memo, .pin]
var items: [[Item]] = []
}
Expand Down Expand Up @@ -159,21 +160,21 @@ final class GiftManagementViewReactor: Reactor, Stepper {

func reduce(state: State, mutation: Mutation) -> State {
var newState = state

switch mutation {
case .updateGiftType(let isGiven):
if let index = newState.sections.firstIndex(of: .friends(isGiven: !isGiven)) {
let newFriendsSection: Section = .friends(isGiven: isGiven)
newState.sections[index] = newFriendsSection
}
newState.giftType = isGiven ? .given : .received

case .updateTitle(let title):
newState.gift.name = title ?? ""

case .updateCategory(let category):
newState.gift.category = category

case .updatePhotos(let photos):
newState.gift.photos = photos

Expand All @@ -199,7 +200,12 @@ final class GiftManagementViewReactor: Reactor, Stepper {
newState.items = [
[.title], [.category], photoItems, [.friends], [.date], [.memo], [.pin]
]


if !state.gift.name.isEmpty,
!(state.gift.date == nil) {
newState.isEnabledDoneButton = true
}

return newState
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ final class GiftManagementViewController: BaseViewController, View {
case .edit: return "완료"
}
}

public var cancelButtonImage: UIImage.FavorIcon {
switch self {
case .new: return .down
case .edit: return .left
}
}
}

public enum GiftType {
case received, given

Expand Down Expand Up @@ -114,27 +114,38 @@ final class GiftManagementViewController: BaseViewController, View {
self.setupDataSource()
self.composer.compose()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.setupNavigationBar()
}

// MARK: - Binding

func bind(reactor: GiftManagementViewReactor) {
// Action

// 취소 버튼 터치
self.cancelButton.rx.tap
.map { Reactor.Action.cancelButtonDidTap }
.bind(to: reactor.action)
.disposed(by: self.disposeBag)


// 완료/등록 버튼 터치
self.doneButton.rx.tap
.debug("Done Button")
.map { Reactor.Action.doneButtonDidTap }
.bind(to: reactor.action)
.disposed(by: self.disposeBag)


// 화면 빈공간 터치
self.collectionView.rx.tapGesture()
.skip(1)
.asDriver(onErrorRecover: { _ in return .empty() })
.drive(with: self) { owner, _ in
owner.view.endEditing(true)
}
.disposed(by: self.disposeBag)

self.collectionView.rx.itemSelected
.map { [weak self] indexPath in
guard
Expand Down Expand Up @@ -185,30 +196,35 @@ final class GiftManagementViewController: BaseViewController, View {
.withRenderingMode(.alwaysTemplate)
})
.disposed(by: self.disposeBag)

reactor.state.map { $0.giftType }
.distinctUntilChanged()
.asDriver(onErrorRecover: { _ in return .empty()})
.drive(with: self, onNext: { owner, giftType in
owner.giftType = giftType
})
.disposed(by: self.disposeBag)

reactor.state.map { $0.isEnabledDoneButton }
.bind(to: self.doneButton.rx.isEnabled)
.disposed(by: self.disposeBag)
}

// MARK: - Functions

// MARK: - UI Setups

override func setupLayouts() {
self.view.addSubview(self.collectionView)
}

override func setupConstraints() {
self.collectionView.snp.makeConstraints { make in
make.edges.equalToSuperview()
make.top.directionalHorizontalEdges.equalTo(self.view.safeAreaLayoutGuide)
make.bottom.equalTo(self.view.keyboardLayoutGuide.snp.top).inset(20.0)
}
}

private func setupNavigationBar() {
self.navigationItem.setRightBarButton(self.doneButton.toBarButtonItem(), animated: false)
self.navigationItem.setLeftBarButton(self.cancelButton.toBarButtonItem(), animated: false)
Expand All @@ -228,7 +244,7 @@ private extension GiftManagementViewController {
cell.bind(placeholder: "선물 이름 (최대 20자)")
cell.bind(text: reactor.currentState.gift.name)
}

let categoryCellRegistration = UICollectionView.CellRegistration
<GiftManagementCategoryViewCell, GiftManagementSectionItem> { [weak self] cell, _, _ in
guard let self = self, let reactor = self.reactor else { return }
Expand Down
11 changes: 9 additions & 2 deletions Favor/Favor/Sources/Scenes/Home/ViewControllers/HomeVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ final class HomeViewController: BaseViewController, View {

override func setupConstraints() {
self.collectionView.snp.makeConstraints { make in
make.directionalVerticalEdges.equalTo(self.view.safeAreaLayoutGuide)
make.directionalHorizontalEdges.equalToSuperview()
make.top.directionalHorizontalEdges.equalTo(self.view.safeAreaLayoutGuide)
make.bottom.equalToSuperview()
}
}

Expand Down Expand Up @@ -165,6 +165,13 @@ final class HomeViewController: BaseViewController, View {
.bind(to: self.rx.isLoading)
.disposed(by: self.disposeBag)
}

// MARK: - Functions

/// 선물이 생성된 후, `선물이 등록되었어요.`라는 메세지의 `ToastMessage`를 띄워주는 메서드
func giftDidCreated() {
self.presentToast(.giftAdded, duration: .short)
}
}

// MARK: - Privates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final class HomeTimelineCell: BaseCollectionViewCell {
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: - Functions

public func bind(with gift: Gift) {
Expand Down
Loading