Skip to content

Commit 7ed6b27

Browse files
committed
refactor #128: 피드백 반영
- BaseButton 공통 이벤트 처리 구조 적용 - Relay/Signal 기반 중간 View 이벤트 전달 구조 확장
1 parent 33e67cf commit 7ed6b27

7 files changed

Lines changed: 149 additions & 44 deletions

File tree

dogether/Presentation/Base/BaseButton.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,18 @@
66
//
77

88
import UIKit
9+
import RxSwift
10+
import RxCocoa
911

1012
class BaseButton: UIButton {
13+
/// 외부 노출용 Signal
14+
var tap: Signal<Void> { tapRelay.asSignal() }
15+
16+
/// 내부 이벤트 스트림
17+
// fileprivate let tapRelay = PublishRelay<Void>()
18+
let tapRelay = PublishRelay<Void>()
19+
fileprivate let disposeBag = DisposeBag()
20+
1121
override init(frame: CGRect) {
1222
super.init(frame: frame)
1323

@@ -22,7 +32,9 @@ class BaseButton: UIButton {
2232
func configureView() { }
2333

2434
/// 뷰의 동작 및 이벤트 처리를 설정하는 역할을 합니다
25-
func configureAction() { }
35+
func configureAction() {
36+
bindTap()
37+
}
2638

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

3345
/// 뷰의 가변 요소들을 업데이트하는 역할을 합니다
3446
func updateView(_ data: any BaseEntity) { }
47+
48+
/// 공통 버튼 탭 이벤트 바인딩
49+
private func bindTap() {
50+
rx.tap
51+
.throttle(.milliseconds(500), scheduler: MainScheduler.instance)
52+
.bind(to: tapRelay)
53+
.disposed(by: disposeBag)
54+
}
3555
}

dogether/Presentation/Common/DogetherButton.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88
import UIKit
99

10-
import RxSwift
11-
import RxCocoa
10+
//import RxSwift
11+
//import RxCocoa
1212

1313
final class DogetherButton: BaseButton {
1414
private(set) var title: String
1515
private(set) var status: ButtonStatus
1616

17-
// ✅ 버튼 탭 이벤트 노출 (RxRelay)
18-
let tapRelay = PublishRelay<Void>()
19-
private let disposeBag = DisposeBag()
17+
// // ✅ 버튼 탭 이벤트 노출 (RxRelay)
18+
// let tapRelay = PublishRelay<Void>()
19+
// private let disposeBag = DisposeBag()
2020

2121
init(title: String, status: ButtonStatus = .enabled) {
2222
self.title = title
@@ -33,13 +33,15 @@ final class DogetherButton: BaseButton {
3333
titleLabel?.font = Fonts.body1B
3434
layer.cornerRadius = 8
3535

36-
rx.tap
37-
.throttle(.milliseconds(500), scheduler: MainScheduler.instance) // 중복클릭 방지
38-
.bind(to: tapRelay)
39-
.disposed(by: disposeBag)
36+
// rx.tap
37+
// .throttle(.milliseconds(500), scheduler: MainScheduler.instance) // 중복클릭 방지
38+
// .bind(to: tapRelay)
39+
// .disposed(by: disposeBag)
4040
}
4141

42-
override func configureAction() { }
42+
override func configureAction() {
43+
super.configureAction()
44+
}
4345

4446
override func configureHierarchy() { }
4547

dogether/Presentation/Common/JoinCodeShareButton.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import UIKit
99

10-
import RxSwift
11-
import RxCocoa
10+
//import RxSwift
11+
//import RxCocoa
1212

1313
final class JoinCodeShareButton: BaseButton {
1414
private let codeLabel = UILabel()
@@ -17,9 +17,9 @@ final class JoinCodeShareButton: BaseButton {
1717
)
1818
private let stackView = UIStackView()
1919

20-
// ✅ 버튼 탭 이벤트 노출
21-
let tapRelay = PublishRelay<Void>()
22-
private let disposeBag = DisposeBag()
20+
// // ✅ 버튼 탭 이벤트 노출
21+
// let tapRelay = PublishRelay<Void>()
22+
// private let disposeBag = DisposeBag()
2323

2424
override func configureView() {
2525
layer.cornerRadius = 12
@@ -34,14 +34,16 @@ final class JoinCodeShareButton: BaseButton {
3434
stackView.spacing = 8
3535
stackView.isUserInteractionEnabled = false
3636

37-
// ✅ 탭 이벤트 바인딩
38-
rx.tap
39-
.throttle(.milliseconds(500), scheduler: MainScheduler.instance) // 중복클릭 방지
40-
.bind(to: tapRelay)
41-
.disposed(by: disposeBag)
37+
// // ✅ 탭 이벤트 바인딩
38+
// rx.tap
39+
// .throttle(.milliseconds(500), scheduler: MainScheduler.instance) // 중복클릭 방지
40+
// .bind(to: tapRelay)
41+
// .disposed(by: disposeBag)
4242
}
4343

44-
override func configureAction() { }
44+
override func configureAction() {
45+
super.configureAction()
46+
}
4547

4648
override func configureHierarchy() {
4749
addSubview(stackView)

dogether/Presentation/Features/Complete/Components/CompletePage.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import UIKit
1010
import RxCocoa
1111

1212
final class CompletePage: BasePage {
13-
var homeTap: Signal<Void> { completeButton.tapRelay.asSignal() }
14-
var shareTap: Signal<Void> { joinCodeShareButton.tapRelay.asSignal() }
13+
// var homeTap: Signal<Void> { completeButton.tapRelay.asSignal() }
14+
// var shareTap: Signal<Void> { joinCodeShareButton.tapRelay.asSignal() }
15+
16+
var homeTap: Signal<Void> { completeButton.tap }
17+
var shareTap: Signal<Void> { joinCodeShareButton.tap }
1518

1619
private let firecrackerImageView = UIImageView(image: .firecracker)
1720
private let titleLabel = UILabel()

dogether/Presentation/Features/Main/Components/GroupInfoView.swift

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,40 @@
77

88
import UIKit
99

10-
final class GroupInfoView: BaseView {
11-
var delegate: MainDelegate? {
12-
didSet {
13-
groupNameStackView.addTapAction { [weak self] in
14-
guard let self else { return }
15-
delegate?.updateBottomSheetVisibleAction(isShowSheet: true)
16-
}
17-
18-
joinCodeStackView.addTapAction { [weak self] in
19-
guard let self else { return }
20-
delegate?.inviteAction()
21-
}
22-
}
10+
import RxSwift
11+
import RxRelay
12+
import RxCocoa
13+
14+
struct GroupInfoEvent {
15+
enum Action {
16+
case openGroupSelector
17+
case invite
2318
}
19+
20+
let action: Action
21+
let group: ChallengeGroupInfo
22+
}
23+
24+
final class GroupInfoView: BaseView {
25+
// var delegate: MainDelegate? {
26+
// didSet {
27+
// groupNameStackView.addTapAction { [weak self] in
28+
// guard let self else { return }
29+
// delegate?.updateBottomSheetVisibleAction(isShowSheet: true)
30+
// }
31+
//
32+
// joinCodeStackView.addTapAction { [weak self] in
33+
// guard let self else { return }
34+
// delegate?.inviteAction()
35+
// }
36+
// }
37+
// }
38+
39+
// ✅ 외부 노출용 이벤트 스트림
40+
var event: Signal<GroupInfoEvent> { _eventRelay.asSignal() }
41+
42+
private let _eventRelay = PublishRelay<GroupInfoEvent>()
43+
private let disposeBag = DisposeBag()
2444

2545
private let hasCopyImage: Bool
2646
private(set) var challengeGroupInfo: ChallengeGroupInfo
@@ -121,7 +141,27 @@ final class GroupInfoView: BaseView {
121141
durationProgressView.transform = CGAffineTransform(translationX: 0, y: 1) // MARK: 디자인 디테일 반영
122142
}
123143

124-
override func configureAction() { }
144+
override func configureAction() {
145+
groupNameStackView.addTapAction { [weak self] in
146+
guard let self else { return }
147+
_eventRelay.accept(
148+
GroupInfoEvent(
149+
action: .openGroupSelector,
150+
group: challengeGroupInfo
151+
)
152+
)
153+
}
154+
155+
joinCodeStackView.addTapAction { [weak self] in
156+
guard let self else { return }
157+
_eventRelay.accept(
158+
GroupInfoEvent(
159+
action: .invite,
160+
group: challengeGroupInfo
161+
)
162+
)
163+
}
164+
}
125165

126166
override func configureHierarchy() {
127167
[dosikImageView, groupNameStackView, groupInfoStackView, durationStackView].forEach { self.addSubview($0) }

dogether/Presentation/Features/Main/Components/MainPage.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
import UIKit
99
import SnapKit
1010

11+
import RxSwift
12+
import RxRelay
13+
import RxCocoa
14+
1115
final class MainPage: BasePage {
1216
var delegate: MainDelegate? {
1317
didSet {
1418
bottomSheetView.delegate = delegate
1519

16-
groupInfoView.delegate = delegate
20+
// groupInfoView.delegate = delegate
1721
rankingButton.delegate = delegate
1822

1923
sheetHeaderView.delegate = delegate
@@ -23,6 +27,10 @@ final class MainPage: BasePage {
2327
}
2428
}
2529

30+
var groupInfoEvent: Signal<GroupInfoEvent> { _groupInfoEvent.asSignal() }
31+
private let _groupInfoEvent = PublishRelay<GroupInfoEvent>()
32+
private let disposeBag = DisposeBag()
33+
2634
private let dogetherHeader = DogetherHeader()
2735

2836
private let dosikCommentButton = DosikCommentButton()
@@ -60,6 +68,10 @@ final class MainPage: BasePage {
6068
let dogetherPanGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:)))
6169
dogetherPanGesture.delegate = self
6270
dogetherSheet.addGestureRecognizer(dogetherPanGesture)
71+
72+
groupInfoView.event
73+
.emit(to: _groupInfoEvent)
74+
.disposed(by: disposeBag)
6375
}
6476

6577
override func configureHierarchy() {

dogether/Presentation/Features/Main/MainViewController.swift

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,32 @@ final class MainViewController: BaseViewController {
3333
bind(viewModel.sheetViewDatas)
3434
bind(viewModel.timerViewDatas)
3535
}
36+
37+
override func bindAction() {
38+
mainPage.groupInfoEvent
39+
.emit(onNext: { [weak self] event in
40+
guard let self else { return }
41+
42+
switch event.action {
43+
44+
case .openGroupSelector:
45+
viewModel.bottomSheetViewDatas.update {
46+
$0.isShowSheet = true
47+
}
48+
49+
case .invite:
50+
let inviteGroup = SystemManager.inviteGroup(
51+
groupName: event.group.name,
52+
joinCode: event.group.joinCode
53+
)
54+
present(
55+
UIActivityViewController(activityItems: inviteGroup, applicationActivities: nil),
56+
animated: true
57+
)
58+
}
59+
})
60+
.disposed(by: disposeBag)
61+
}
3662
}
3763

3864
extension MainViewController {
@@ -114,7 +140,7 @@ protocol MainDelegate {
114140
func updateBottomSheetVisibleAction(isShowSheet: Bool)
115141
func selectGroupAction(index: Int)
116142
func addGroupAction()
117-
func inviteAction()
143+
// func inviteAction()
118144
func goPastAction()
119145
func goFutureAction()
120146
func startTimerAction()
@@ -186,10 +212,10 @@ extension MainViewController: MainDelegate {
186212
coordinator?.pushViewController(startViewController, datas: startViewDatas)
187213
}
188214

189-
func inviteAction() {
190-
let inviteGroup = SystemManager.inviteGroup(groupName: viewModel.currentGroup.name, joinCode: viewModel.currentGroup.joinCode)
191-
present(UIActivityViewController(activityItems: inviteGroup, applicationActivities: nil), animated: true)
192-
}
215+
// func inviteAction() {
216+
// let inviteGroup = SystemManager.inviteGroup(groupName: viewModel.currentGroup.name, joinCode: viewModel.currentGroup.joinCode)
217+
// present(UIActivityViewController(activityItems: inviteGroup, applicationActivities: nil), animated: true)
218+
// }
193219

194220
func goPastAction() {
195221
viewModel.sheetViewDatas.update {

0 commit comments

Comments
 (0)