Skip to content

Commit a1cab32

Browse files
committed
[#78] 탈퇴하기 버튼 비즈니스 로직 연결
1 parent 71e57d2 commit a1cab32

File tree

4 files changed

+57
-58
lines changed

4 files changed

+57
-58
lines changed

EATSSU_MVC/EATSSU_MVC/Sources/Presentation/MyPage/View/MyPageView/MyPageView.swift

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,16 @@ final class MyPageView: BaseUIView {
7878
label.textColor = EATSSUAsset.Color.GrayScale.gray400.color
7979
}
8080

81-
// "탈퇴하기"
82-
private let withdrawLabel = UILabel().then { label in
83-
label.text = TextLiteral.MyPage.withdraw
84-
label.font = EATSSUFontFamily.Pretendard.regular.font(size: 12)
85-
label.textColor = EATSSUAsset.Color.GrayScale.gray400.color
86-
}
87-
88-
// "탈퇴하기" 옆 아이콘
89-
private let withdrawIconImageView = UIImageView().then { imageView in
90-
imageView.image = EATSSUAsset.Images.Version2.withdrawIcon.image
91-
imageView.tintColor = EATSSUAsset.Color.GrayScale.gray400.color
92-
}
93-
94-
// "탈퇴하기" 레이블과 탈퇴하기 아이콘
95-
private let withdrawStackView: UIStackView = {
96-
let stackView = UIStackView()
97-
stackView.axis = .horizontal
98-
return stackView
81+
/// "탈퇴하기" 레이블과 탈퇴하기 아이콘
82+
internal let userWithdrawButton: UIButton = {
83+
let button = UIButton()
84+
button.setTitle(TextLiteral.MyPage.withdraw, for: .normal)
85+
button.setImage(EATSSUAsset.Images.Version2.withdrawIcon.image, for: .normal)
86+
button.setTitleColor(EATSSUAsset.Color.GrayScale.gray400.color, for: .normal)
87+
button.titleLabel?.font = EATSSUFontFamily.Pretendard.regular.font(size: 12)
88+
return button
9989
}()
100-
90+
10191
// MARK: - Intializer
10292

10393
override init(frame: CGRect) {
@@ -115,9 +105,7 @@ final class MyPageView: BaseUIView {
115105
myPageTableView,
116106
appVersionStringLabel,
117107
appVersionLabel,
118-
withdrawLabel,
119-
withdrawIconImageView,
120-
withdrawStackView
108+
userWithdrawButton
121109
)
122110
}
123111

@@ -157,8 +145,7 @@ final class MyPageView: BaseUIView {
157145
}
158146

159147
// TODO: withdrawStackView를 프로퍼티로 선언할 때, lazy를 사용하면 레이아웃이 한 타임 늦게 잡히는 문제로 인해서 여기에서 스택 안에 들어갈 뷰를 추가함. 개선 방법이 없는지 확인.
160-
withdrawStackView.addArrangedSubviews([withdrawLabel, withdrawIconImageView])
161-
withdrawStackView.snp.makeConstraints { make in
148+
userWithdrawButton.snp.makeConstraints { make in
162149
make.top.equalTo(appVersionLabel.snp.bottom).offset(16)
163150
make.trailing.equalToSuperview().inset(24)
164151
}

EATSSU_MVC/EATSSU_MVC/Sources/Presentation/MyPage/View/UserWithdrawView.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@ final class UserWithdrawView: BaseUIView {
4141
init(nickName: String) {
4242
super.init(frame: CGRect())
4343
self.userNickname = nickName
44-
self.inputNickNameTextField.placeholder = nickName
45-
46-
47-
self.setTextFieldDelegate()
48-
self.setProperties()
49-
self.configureUI()
44+
self.inputNickNameTextField.placeholder = nickName
45+
self.setTextFieldDelegate()
46+
self.setProperties()
47+
self.configureUI()
5048
}
5149

5250
// MARK: - Functions
@@ -136,13 +134,13 @@ final class UserWithdrawView: BaseUIView {
136134
private func setValidationLabel(state: ValidationLabelState) {
137135
switch state {
138136
case .corrected:
139-
nickNameStateGuideLabel.text = TextLiteral.MyPage.validInputMessage
137+
nickNameStateGuideLabel.text = TextLiteral.MyPage.validInputMessage
140138
nickNameStateGuideLabel.textColor = .systemGreen
141139
completeSignOutButton.isEnabled = true
142140
case .unCorrected:
143141
nickNameStateGuideLabel.do {
144-
$0.isHidden = false
145-
$0.text = TextLiteral.MyPage.invalidNicknameMessage
142+
$0.isHidden = false
143+
$0.text = TextLiteral.MyPage.invalidNicknameMessage
146144
$0.textColor = .primary
147145
}
148146
completeSignOutButton.isEnabled = false
@@ -191,7 +189,6 @@ private extension UserWithdrawView {
191189
}
192190

193191
func checkIsNickNameCorrect(_ textField: UITextField) {
194-
195192
if let userNickname = textField.text {
196193
if userNickname == self.userNickname {
197194
setValidationLabel(state: .corrected)

EATSSU_MVC/EATSSU_MVC/Sources/Presentation/MyPage/ViewController/MyPageViewController.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,23 @@ final class MyPageViewController: BaseViewController {
7777

7878
override func setButtonEvent() {
7979
mypageView.userNicknameButton
80-
.addTarget(
81-
self,
82-
action: #selector(didTappedChangeNicknameButton),
83-
for: .touchUpInside)
80+
.addTarget(self, action: #selector(didTappedChangeNicknameButton),for: .touchUpInside)
81+
82+
mypageView.userWithdrawButton
83+
.addTarget(self, action: #selector(userWithdrawButtonTapped), for: .touchUpInside)
8484
}
8585

8686
@objc
8787
private func didTappedChangeNicknameButton() {
8888
let setNickNameVC = SetNickNameViewController()
8989
self.navigationController?.pushViewController(setNickNameVC, animated: true)
9090
}
91+
92+
@objc
93+
private func userWithdrawButtonTapped() {
94+
let userWithdrawViewController = UserWithdrawViewController(nickName: nickName)
95+
self.navigationController?.pushViewController(userWithdrawViewController, animated: true)
96+
}
9197

9298
/// TableViewDelegate & DataSource를 해당 클래스로 할당합니다.
9399
private func setTableViewDelegate() {

EATSSU_MVC/EATSSU_MVC/Sources/Presentation/MyPage/ViewController/UserWithdrawViewController.swift

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class UserWithdrawViewController: BaseViewController {
2323

2424
// MARK: - UI Components
2525

26-
private lazy var deleteAccountView = UserWithdrawView(nickName: nickName)
26+
private lazy var userWithdrawView = UserWithdrawView(nickName: nickName)
2727

2828
// MARK: - Life Cycles
2929

@@ -40,15 +40,27 @@ final class UserWithdrawViewController: BaseViewController {
4040
override func viewWillDisappear(_ animated: Bool) {
4141
self.removeKeyboardNotifications()
4242
}
43+
44+
// MARK: - Initializer
45+
46+
init(nickName: String) {
47+
self.nickName = nickName
48+
49+
super.init(nibName: nil, bundle: nil)
50+
}
51+
52+
required init?(coder: NSCoder) {
53+
fatalError("init(coder:) has not been implemented")
54+
}
4355

4456
// MARK: - Functions
4557

4658
override func configureUI() {
47-
view.addSubviews(deleteAccountView)
59+
view.addSubviews(userWithdrawView)
4860
}
4961

5062
override func setLayout() {
51-
deleteAccountView.snp.makeConstraints {
63+
userWithdrawView.snp.makeConstraints {
5264
$0.edges.equalToSuperview()
5365
}
5466
}
@@ -59,21 +71,17 @@ final class UserWithdrawViewController: BaseViewController {
5971
}
6072

6173
override func setButtonEvent() {
62-
deleteAccountView.completeSignOutButton.addTarget(self, action: #selector(tappedCompleteNickNameButton), for: .touchUpInside)
74+
userWithdrawView.completeSignOutButton.addTarget(self, action: #selector(completeNickNameButtonTapped), for: .touchUpInside)
6375
}
6476

6577
@objc
66-
func tappedCompleteNickNameButton() {
67-
deleteUser()
78+
func completeNickNameButtonTapped() {
79+
deleteUser()
6880
}
81+
82+
// MARK: - 디바이스 키보드 감지
6983

70-
func getUsernickName(nickName: String) {
71-
self.nickName = nickName
72-
}
73-
74-
// MARK: - keyboard 감지
75-
76-
func addKeyboardNotifications() {
84+
private func addKeyboardNotifications() {
7785
NotificationCenter.default.addObserver(self,
7886
selector: #selector(self.keyboardWillShow(_:)),
7987
name: UIResponder.keyboardWillShowNotification,
@@ -83,7 +91,7 @@ final class UserWithdrawViewController: BaseViewController {
8391
object: nil)
8492
}
8593

86-
func removeKeyboardNotifications() {
94+
private func removeKeyboardNotifications() {
8795
NotificationCenter.default.removeObserver(self,
8896
name: UIResponder.keyboardWillShowNotification,
8997
object: nil)
@@ -93,21 +101,22 @@ final class UserWithdrawViewController: BaseViewController {
93101
}
94102

95103
@objc
96-
func keyboardWillShow(_ notification: Notification) {
104+
private func keyboardWillShow(_ notification: Notification) {
97105
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
98106

99107
let updateKeyboardHeight = keyboardSize.height
100108
let difference = updateKeyboardHeight - currentKeyboardHeight
101109

102-
deleteAccountView.completeSignOutButton.frame.origin.y -= difference
110+
userWithdrawView.completeSignOutButton.frame.origin.y -= difference
103111
currentKeyboardHeight = updateKeyboardHeight
104112
}
105113
}
106114

107-
@objc func keyboardWillHide(_ notification: Notification) {
108-
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
109-
110-
deleteAccountView.completeSignOutButton.frame.origin.y += currentKeyboardHeight
115+
@objc
116+
private func keyboardWillHide(_ notification: Notification) {
117+
// TODO: keyboardSize 변수는 사용하지 않아서 _ 로 대체했지만, 해당 로직이 왜 필요한 지 연구
118+
if let _ = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
119+
userWithdrawView.completeSignOutButton.frame.origin.y += currentKeyboardHeight
111120
currentKeyboardHeight = 0.0
112121
}
113122
}

0 commit comments

Comments
 (0)