-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMypageView.swift
More file actions
184 lines (151 loc) · 6.52 KB
/
MypageView.swift
File metadata and controls
184 lines (151 loc) · 6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//
// MypageView.swift
// Presentation
//
// Created by 이동현 on 7/17/25.
//
import Combine
import SafariServices
import Shared
import SnapKit
import UIKit
final class MypageView: BaseViewController<MypageViewModel> {
private enum Layout {
static let profileImageViewSize: CGFloat = 80
static let profileImageViewCornerRadius: CGFloat = profileImageViewSize / 2
static let profileImageViewTopSpacing: CGFloat = 32
static let nicknameLabelHeight: CGFloat = 24
static let nicknameLabelTopSpacing: CGFloat = 12
static let divideLineHeight: CGFloat = 6
static let divideLineTopSpacing: CGFloat = 28
static let tableViewCellHeight: CGFloat = 48
}
private let titleLabel = UILabel()
private let settingButton = UIBarButtonItem()
private let profileImageView = UIImageView()
private let nicknameLabel = UILabel()
private let dividerView = UIView()
private let tableView = UITableView()
private var cancellables: Set<AnyCancellable>
override init(viewModel: MypageViewModel) {
cancellables = []
super.init(viewModel: viewModel)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .white
appearance.shadowColor = .clear
navigationController?.navigationBar.standardAppearance = appearance
navigationController?.navigationBar.scrollEdgeAppearance = appearance
navigationController?.navigationBar.compactAppearance = appearance
}
override func configureAttribute() {
view.backgroundColor = .white
navigationItem.rightBarButtonItem = settingButton
title = "마이페이지"
settingButton.action = #selector(settingButtonTapped)
settingButton.target = self
settingButton.tintColor = .black
settingButton.image = BitnagilIcon
.settingIcon?
.withRenderingMode(.alwaysTemplate)
profileImageView.layer.cornerRadius = Layout.profileImageViewCornerRadius
profileImageView.layer.masksToBounds = true
profileImageView.backgroundColor = BitnagilColor.gray40 // 임시
nicknameLabel.font = BitnagilFont(style: .title3, weight: .semiBold).font
nicknameLabel.textColor = .black
nicknameLabel.textAlignment = .center
dividerView.backgroundColor = BitnagilColor.gray99
tableView.register(BitnagilChevronTableViewCell.self, forCellReuseIdentifier: BitnagilChevronTableViewCell.className)
tableView.dataSource = self
tableView.delegate = self
tableView.separatorStyle = .none
tableView.bounces = false
}
override func configureLayout() {
let safeArea = view.safeAreaLayoutGuide
view.addSubview(profileImageView)
view.addSubview(nicknameLabel)
view.addSubview(dividerView)
view.addSubview(tableView)
profileImageView.snp.makeConstraints { make in
make.top.equalTo(safeArea.snp.top).offset(Layout.profileImageViewTopSpacing)
make.centerX.equalToSuperview()
make.size.equalTo(Layout.profileImageViewSize)
}
nicknameLabel.snp.makeConstraints { make in
make.top.equalTo(profileImageView.snp.bottom).offset(Layout.nicknameLabelTopSpacing)
make.centerX.equalToSuperview()
make.height.equalTo(Layout.nicknameLabelHeight)
}
dividerView.snp.makeConstraints { make in
make.top.equalTo(nicknameLabel.snp.bottom).offset(Layout.divideLineTopSpacing)
make.horizontalEdges.equalToSuperview()
make.height.equalTo(Layout.divideLineHeight)
}
tableView.snp.makeConstraints { make in
make.top.equalTo(dividerView.snp.bottom)
make.horizontalEdges.bottom.equalTo(safeArea)
}
}
override func bind() {
viewModel.output.nickNamePublisher
.sink { [weak self] nickname in
self?.nicknameLabel.text = nickname
}
.store(in: &cancellables)
viewModel.output.externalURLPublisher
.sink { [weak self] url in
let safariView = SFSafariViewController(url: url)
self?.present(safariView, animated: true)
}
.store(in: &cancellables)
}
@objc private func settingButtonTapped() {
guard let settingViewModel = Shared.DIContainer.shared.resolve(type: SettingViewModel.self) else { return }
let settingView = SettingView(viewModel: settingViewModel)
navigationController?.pushViewController(settingView, animated: true)
}
}
extension MypageView: UITableViewDelegate {
}
extension MypageView: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return MypageViewModel.MypageMenu.allCases.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return Layout.tableViewCellHeight
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: BitnagilChevronTableViewCell.className) as? BitnagilChevronTableViewCell else {
return .init()
}
let title = MypageViewModel.MypageMenu
.allCases[indexPath.row]
.rawValue
cell.configure(title: title)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
defer { tableView.deselectRow(at: indexPath, animated: true) }
let selectedMenu = MypageViewModel.MypageMenu.allCases[indexPath.row]
guard selectedMenu == .resetGoal else {
viewModel.action(input: .didSelectMenu(menu: selectedMenu))
return
}
guard let onboardingViewModel = DIContainer.shared.resolve(type: OnboardingViewModel.self) else {
fatalError("onboardingViewModel 의존성이 등록되지 않았습니다.")
}
let onboardingView = OnboardingView(
viewModel: onboardingViewModel,
onboarding: .time,
isFromMypage: true)
onboardingView.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(onboardingView, animated: true)
}
}