Skip to content
Open
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
21 changes: 20 additions & 1 deletion dogether/Presentation/Base/BaseButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
//

import UIKit
import RxSwift
import RxCocoa

class BaseButton: UIButton {
/// 외부 노출용 Signal
var tap: Signal<Void> { tapRelay.asSignal() }
/// 내부 이벤트 스트림
let tapRelay = PublishRelay<Void>()

fileprivate let disposeBag = DisposeBag()

override init(frame: CGRect) {
super.init(frame: frame)

Expand All @@ -22,7 +31,9 @@ class BaseButton: UIButton {
func configureView() { }

/// 뷰의 동작 및 이벤트 처리를 설정하는 역할을 합니다
func configureAction() { }
func configureAction() {
bindTap()
}

/// 뷰 계층을 구성하는 역할을 합니다
func configureHierarchy() { }
Expand All @@ -32,4 +43,12 @@ class BaseButton: UIButton {

/// 뷰의 가변 요소들을 업데이트하는 역할을 합니다
func updateView(_ data: any BaseEntity) { }

/// 공통 버튼 탭 이벤트 바인딩
private func bindTap() {
rx.tap
.throttle(.milliseconds(500), scheduler: MainScheduler.instance)
.bind(to: tapRelay)
.disposed(by: disposeBag)
}
}
6 changes: 5 additions & 1 deletion dogether/Presentation/Base/BaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BaseViewController: UIViewController, CoordinatorDelegate {
var datas: (any BaseEntity)?
var pages: Array<BasePage>?

private let disposeBag = DisposeBag()
let disposeBag = DisposeBag()

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -31,6 +31,7 @@ class BaseViewController: UIViewController, CoordinatorDelegate {
configurePages(pages)

setViewDatas()
bindAction()
}

/// 뷰의 시각적인 속성을 설정하는 역할을 합니다
Expand Down Expand Up @@ -63,6 +64,9 @@ class BaseViewController: UIViewController, CoordinatorDelegate {
/// View를 구성하는 필수 데이터를 세팅하고 바인딩하는 역할을 합니다
func setViewDatas() { }

/// 버튼이나 제스처, Rx 이벤트 바인딩
func bindAction() { }

/// ViewDatas의 변화에 Page가 update 되도록 바인딩하는 역할을 합니다
func bind<Entity: BaseEntity>(_ relay: BehaviorRelay<Entity>) {
relay
Expand Down
9 changes: 7 additions & 2 deletions dogether/Presentation/Common/DogetherButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

import UIKit

import RxSwift
import RxCocoa

final class DogetherButton: BaseButton {
private let title: String

init(_ title: String) {
self.title = title

Expand All @@ -25,7 +28,9 @@ final class DogetherButton: BaseButton {
layer.cornerRadius = 8
}

override func configureAction() { }
override func configureAction() {
super.configureAction()
}

override func configureHierarchy() { }

Expand Down
4 changes: 3 additions & 1 deletion dogether/Presentation/Common/JoinCodeShareButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ final class JoinCodeShareButton: BaseButton {
stackView.isUserInteractionEnabled = false
}

override func configureAction() { }
override func configureAction() {
super.configureAction()
}

override func configureHierarchy() {
addSubview(stackView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ final class CompleteViewController: BaseViewController {
private let viewModel = CompleteViewModel()

override func viewDidLoad() {
completePage.delegate = self
pages = [completePage]
super.viewDidLoad()
}
Expand All @@ -24,25 +23,24 @@ final class CompleteViewController: BaseViewController {

bind(viewModel.completeViewDatas)
}
}

protocol CompleteDelegate: AnyObject {
func goHomeAction()
func shareJoinCodeAction()
}

extension CompleteViewController: CompleteDelegate {
func goHomeAction() {
coordinator?.setNavigationController(MainViewController())
}

func shareJoinCodeAction() {
let data = viewModel.completeViewDatas.value
override func bindAction() {
completePage.homeTap
.emit(onNext: { [weak self] in
self?.coordinator?.setNavigationController(MainViewController())
})
.disposed(by: disposeBag)

let invite = SystemManager.inviteGroup(
groupName: data.groupInfo.name,
joinCode: data.joinCode
)
present(UIActivityViewController(activityItems: invite, applicationActivities: nil), animated: true)
completePage.shareTap
.emit(onNext: { [weak self] in
guard let self else { return }
let data = viewModel.completeViewDatas.value
let invite = SystemManager.inviteGroup(
groupName: data.groupInfo.name,
joinCode: data.joinCode
)
present(UIActivityViewController(activityItems: invite, applicationActivities: nil), animated: true)
})
.disposed(by: disposeBag)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,11 @@

import UIKit

import RxCocoa

final class CompletePage: BasePage {
weak var delegate: CompleteDelegate? {
didSet {
completeButton.addAction(
UIAction { [weak self] _ in
guard let self else { return }
delegate?.goHomeAction()
},
for: .touchUpInside
)

joinCodeShareButton.addAction(
UIAction { [weak self] _ in
guard let self else { return }
delegate?.shareJoinCodeAction()
},
for: .touchUpInside
)
}
}
var homeTap: Signal<Void> { completeButton.tap }
var shareTap: Signal<Void> { joinCodeShareButton.tap }

private let firecrackerImageView = UIImageView(image: .firecracker)
private let titleLabel = UILabel()
Expand Down
68 changes: 54 additions & 14 deletions dogether/Presentation/Features/Main/Components/GroupInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,40 @@

import UIKit

final class GroupInfoView: BaseView {
var delegate: MainDelegate? {
didSet {
groupNameStackView.addTapAction { [weak self] _ in
guard let self else { return }
delegate?.updateBottomSheetVisibleAction(isShowSheet: true)
}

joinCodeStackView.addTapAction { [weak self] _ in
guard let self else { return }
delegate?.inviteAction()
}
}
import RxSwift
import RxRelay
import RxCocoa

struct GroupInfoEvent {
enum Action {
case openGroupSelector
case invite
}

let action: Action
let group: ChallengeGroupInfo
}

final class GroupInfoView: BaseView {
// var delegate: MainDelegate? {
// didSet {
// groupNameStackView.addTapAction { [weak self] in
// guard let self else { return }
// delegate?.updateBottomSheetVisibleAction(isShowSheet: true)
// }
//
// joinCodeStackView.addTapAction { [weak self] in
// guard let self else { return }
// delegate?.inviteAction()
// }
// }
// }

// ✅ 외부 노출용 이벤트 스트림
var event: Signal<GroupInfoEvent> { _eventRelay.asSignal() }

private let _eventRelay = PublishRelay<GroupInfoEvent>()
private let disposeBag = DisposeBag()

private let hasCopyImage: Bool
private(set) var challengeGroupInfo: ChallengeGroupInfo
Expand Down Expand Up @@ -128,7 +148,27 @@ final class GroupInfoView: BaseView {
durationProgressView.transform = CGAffineTransform(translationX: 0, y: 1) // MARK: 디자인 디테일 반영
}

override func configureAction() { }
override func configureAction() {
groupNameStackView.addTapAction { [weak self] _ in
guard let self else { return }
_eventRelay.accept(
GroupInfoEvent(
action: .openGroupSelector,
group: challengeGroupInfo
)
)
}

joinCodeStackView.addTapAction { [weak self] _ in
guard let self else { return }
_eventRelay.accept(
GroupInfoEvent(
action: .invite,
group: challengeGroupInfo
)
)
}
}

override func configureHierarchy() {
[nameLabel, changeGroupImageView, nameSpacerView].forEach { groupNameStackView.addArrangedSubview($0) }
Expand Down
14 changes: 13 additions & 1 deletion dogether/Presentation/Features/Main/Components/MainPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
import UIKit
import SnapKit

import RxSwift
import RxRelay
import RxCocoa

final class MainPage: BasePage {
var delegate: MainDelegate? {
didSet {
bottomSheetView.delegate = delegate

groupInfoView.delegate = delegate
// groupInfoView.delegate = delegate
rankingButton.delegate = delegate

sheetHeaderView.delegate = delegate
Expand All @@ -23,6 +27,10 @@ final class MainPage: BasePage {
}
}

var groupInfoEvent: Signal<GroupInfoEvent> { _groupInfoEvent.asSignal() }
private let _groupInfoEvent = PublishRelay<GroupInfoEvent>()
private let disposeBag = DisposeBag()

private let dogetherHeader = DogetherHeader()

private let dosikCommentButton = DosikCommentButton()
Expand Down Expand Up @@ -60,6 +68,10 @@ final class MainPage: BasePage {
let dogetherPanGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:)))
dogetherPanGesture.delegate = self
dogetherSheet.addGestureRecognizer(dogetherPanGesture)

groupInfoView.event
.emit(to: _groupInfoEvent)
.disposed(by: disposeBag)
}

override func configureHierarchy() {
Expand Down
36 changes: 31 additions & 5 deletions dogether/Presentation/Features/Main/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,32 @@ final class MainViewController: BaseViewController {
bind(viewModel.sheetViewDatas)
bind(viewModel.timerViewDatas)
}

override func bindAction() {
mainPage.groupInfoEvent
.emit(onNext: { [weak self] event in
guard let self else { return }

switch event.action {

case .openGroupSelector:
viewModel.bottomSheetViewDatas.update {
$0.isShowSheet = true
}

case .invite:
let inviteGroup = SystemManager.inviteGroup(
groupName: event.group.name,
joinCode: event.group.joinCode
)
present(
UIActivityViewController(activityItems: inviteGroup, applicationActivities: nil),
animated: true
)
}
})
.disposed(by: disposeBag)
}
}

extension MainViewController {
Expand Down Expand Up @@ -114,7 +140,7 @@ protocol MainDelegate {
func updateBottomSheetVisibleAction(isShowSheet: Bool)
func selectGroupAction(index: Int)
func addGroupAction()
func inviteAction()
// func inviteAction()
func goPastAction()
func goFutureAction()
func startTimerAction()
Expand Down Expand Up @@ -186,10 +212,10 @@ extension MainViewController: MainDelegate {
coordinator?.pushViewController(startViewController, datas: startViewDatas)
}

func inviteAction() {
let inviteGroup = SystemManager.inviteGroup(groupName: viewModel.currentGroup.name, joinCode: viewModel.currentGroup.joinCode)
present(UIActivityViewController(activityItems: inviteGroup, applicationActivities: nil), animated: true)
}
// func inviteAction() {
// let inviteGroup = SystemManager.inviteGroup(groupName: viewModel.currentGroup.name, joinCode: viewModel.currentGroup.joinCode)
// present(UIActivityViewController(activityItems: inviteGroup, applicationActivities: nil), animated: true)
// }

func goPastAction() {
viewModel.sheetViewDatas.update {
Expand Down
Loading