From a301ddfdbf7c20b536d3b00e64abe9fe0c8e0e40 Mon Sep 17 00:00:00 2001 From: tngusmiso Date: Sat, 11 Feb 2023 11:06:44 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT][#7]=20=EC=B6=9C=EC=84=9D=EC=B2=B4?= =?UTF-8?q?=ED=81=AC=20=EC=BD=94=EB=93=9C=20=EC=9E=85=EB=A0=A5=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=9D=BC=20=EC=B6=9C=EC=84=9D=EB=B2=84=ED=8A=BC=20Ena?= =?UTF-8?q?bled=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Optional+Extension 추가 : isNil, isNotNil, isEmptyOrNil - textField 입력될 때 마다 버튼 enabled 체크 - 버튼 enabled 값에 따라 configuration 변경 --- Extensions/Optional+Extension.swift | 23 ++++++++ .../UINavigationController+Extension.swift | 21 +++++++ momoIOS.xcodeproj/project.pbxproj | 8 +++ .../AttendanceDetailViewController.swift | 57 ++++++++++++++++++- 4 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 Extensions/Optional+Extension.swift create mode 100644 Extensions/UINavigationController+Extension.swift diff --git a/Extensions/Optional+Extension.swift b/Extensions/Optional+Extension.swift new file mode 100644 index 0000000..2be162c --- /dev/null +++ b/Extensions/Optional+Extension.swift @@ -0,0 +1,23 @@ +// +// Optional+Extension.swift +// momoIOS +// +// Created by 임수현 on 2023/02/11. +// + +import Foundation + +extension Optional { + var isNil: Bool { + self == nil + } + var isNotNil: Bool { + self != nil + } +} + +extension String? { + var isEmptyOrNil: Bool { + self?.isEmpty == true || self.isNil + } +} diff --git a/Extensions/UINavigationController+Extension.swift b/Extensions/UINavigationController+Extension.swift new file mode 100644 index 0000000..cc2658b --- /dev/null +++ b/Extensions/UINavigationController+Extension.swift @@ -0,0 +1,21 @@ +// +// UINavigationController+Extension.swift +// momoIOS +// +// Created by 임수현 on 2023/02/11. +// + +import UIKit + +extension UINavigationController: ObservableObject, UIGestureRecognizerDelegate { + override open func viewDidLoad() { + super.viewDidLoad() + + // backButton을 임의로 변경하면 swipe back 동작이 되지 않기 떄문에 gestureRecognizer를 설정하여 동작하도록 함. + interactivePopGestureRecognizer?.delegate = self + } + + public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { + return viewControllers.count > 1 + } +} diff --git a/momoIOS.xcodeproj/project.pbxproj b/momoIOS.xcodeproj/project.pbxproj index 1fee1b7..f3ffa97 100644 --- a/momoIOS.xcodeproj/project.pbxproj +++ b/momoIOS.xcodeproj/project.pbxproj @@ -14,6 +14,8 @@ 3AA713D1298946FF006F922F /* UIColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA713D0298946FF006F922F /* UIColor+Extension.swift */; }; 3ABBF7362996B6C9004D4D0B /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABBF7352996B6C9004D4D0B /* String+Extension.swift */; }; 3ABBF73A2996B8C9004D4D0B /* Collection+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABBF7392996B8C9004D4D0B /* Collection+Extension.swift */; }; + 3ABBF73C2996D48C004D4D0B /* Optional+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABBF73B2996D48C004D4D0B /* Optional+Extension.swift */; }; + 3ABBF73E2997370D004D4D0B /* UINavigationController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABBF73D2997370D004D4D0B /* UINavigationController+Extension.swift */; }; 3ADF66102993F48A00577028 /* AttendanceDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ADF660F2993F48A00577028 /* AttendanceDetailViewController.swift */; }; BF0408632987B3AA00F1129B /* LoginController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0408622987B3AA00F1129B /* LoginController.swift */; }; BF04086B2987E34800F1129B /* AuthCommonConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF04086A2987E34800F1129B /* AuthCommonConstants.swift */; }; @@ -49,6 +51,8 @@ 3AA713D0298946FF006F922F /* UIColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extension.swift"; sourceTree = ""; }; 3ABBF7352996B6C9004D4D0B /* String+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = ""; }; 3ABBF7392996B8C9004D4D0B /* Collection+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Collection+Extension.swift"; sourceTree = ""; }; + 3ABBF73B2996D48C004D4D0B /* Optional+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Optional+Extension.swift"; sourceTree = ""; }; + 3ABBF73D2997370D004D4D0B /* UINavigationController+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationController+Extension.swift"; sourceTree = ""; }; 3ADF660F2993F48A00577028 /* AttendanceDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttendanceDetailViewController.swift; sourceTree = ""; }; BF0408622987B3AA00F1129B /* LoginController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginController.swift; sourceTree = ""; }; BF04086A2987E34800F1129B /* AuthCommonConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthCommonConstants.swift; sourceTree = ""; }; @@ -180,6 +184,8 @@ BFB8431E298CFF9200BA11EC /* UIStackView+Extension.swift */, 3ABBF7352996B6C9004D4D0B /* String+Extension.swift */, 3ABBF7392996B8C9004D4D0B /* Collection+Extension.swift */, + 3ABBF73B2996D48C004D4D0B /* Optional+Extension.swift */, + 3ABBF73D2997370D004D4D0B /* UINavigationController+Extension.swift */, ); path = Extensions; sourceTree = ""; @@ -342,6 +348,7 @@ 3ADF66102993F48A00577028 /* AttendanceDetailViewController.swift in Sources */, E8207934298A22D000B36FC9 /* MainSessionInfoCell.swift in Sources */, E8207932298A163400B36FC9 /* UIView+Extension.swift in Sources */, + 3ABBF73E2997370D004D4D0B /* UINavigationController+Extension.swift in Sources */, BFB8431F298CFF9200BA11EC /* UIStackView+Extension.swift in Sources */, E820792D298A137700B36FC9 /* MainSessionTimeCell.swift in Sources */, E820792B298A119900B36FC9 /* MainSessionDetailCell.swift in Sources */, @@ -349,6 +356,7 @@ 3AA713D1298946FF006F922F /* UIColor+Extension.swift in Sources */, 3AA713C929884007006F922F /* MainAttendanceDoneCell.swift in Sources */, E820792F298A138500B36FC9 /* MainSessionAbsentCell.swift in Sources */, + 3ABBF73C2996D48C004D4D0B /* Optional+Extension.swift in Sources */, 3ABBF73A2996B8C9004D4D0B /* Collection+Extension.swift in Sources */, BF4310FA298C525900270DBF /* AttendanceHistoryCell.swift in Sources */, ); diff --git a/momoIOS/AttendanceDetail/ViewController/AttendanceDetailViewController.swift b/momoIOS/AttendanceDetail/ViewController/AttendanceDetailViewController.swift index 5c1ca4d..194f91d 100644 --- a/momoIOS/AttendanceDetail/ViewController/AttendanceDetailViewController.swift +++ b/momoIOS/AttendanceDetail/ViewController/AttendanceDetailViewController.swift @@ -15,6 +15,14 @@ class AttendanceDetailViewController: UIViewController { private let descriptionLabel: UILabel = UILabel() private let attendButton: UIButton = UIButton() + private var inputCodeString: String { + var string = "" + self.codeTextFields.forEach { textField in + string.append(textField.text ?? " ") + } + return string + } + // MARK: - Lifecycle override func viewDidLoad() { super.viewDidLoad() @@ -51,7 +59,21 @@ class AttendanceDetailViewController: UIViewController { } private func setupNavigation() { + let navigationBar = self.navigationController?.navigationBar + let appearance = navigationBar?.standardAppearance ?? UINavigationBarAppearance() + appearance.shadowColor = .rgba(24, 24, 24, 0.16) + appearance.backgroundColor = .white.withAlphaComponent(0.96) + navigationBar?.standardAppearance = appearance + let backButtonImage = UIImage(systemName: "arrow.left") + let backBarButton = UIBarButtonItem(image: backButtonImage, style: .plain, target: self, action: #selector(popViewController)) + self.navigationItem.leftBarButtonItem = backBarButton + + let titleLabel = UILabel() + titleLabel.text = "서울특별시 강남구 역삼로" + titleLabel.textColor = .black + titleLabel.font = .systemFont(ofSize: 14) + self.navigationItem.titleView = titleLabel } private func setupViews() { @@ -83,7 +105,8 @@ class AttendanceDetailViewController: UIViewController { self.backgroundView.addSubview(self.descriptionLabel) self.attendButton.setTitle("출석하기", size: 16, weight: .bold, color: .white) - self.attendButton.configurate(bgColor: .rgba(56, 56, 56, 1), cornerRadius: 7, padding: 10) + self.configureAttendButtonEnabled() + self.attendButton.addTarget(self, action: #selector(didTapAttendButton), for: .touchUpInside) } // MARK: - Layout @@ -138,11 +161,39 @@ class AttendanceDetailViewController: UIViewController { make.height.equalTo(54) } } + + // MARK: - Actions + @objc private func didTapAttendButton() { + self.popViewController() + } + + private func configureAttendButtonEnabled() { + let isAttendButtonEnabled = { + for textField in self.codeTextFields where textField.text.isEmptyOrNil { + return false + } + return true + }() + + if isAttendButtonEnabled { + self.attendButton.isEnabled = true + self.attendButton.configurate(bgColor: .rgba(56, 56, 56, 1), cornerRadius: 7, padding: 10) + } else { + self.attendButton.isEnabled = false + self.attendButton.configurate(bgColor: .rgba(200, 200, 200, 1), cornerRadius: 7, padding: 10) + } + } + + @objc private func popViewController(animated: Bool = true) { + self.navigationController?.popViewController(animated: true) + } } // MARK: - UITextFieldDelegate extension AttendanceDetailViewController: UITextFieldDelegate { func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { + defer { self.configureAttendButtonEnabled() } + let currentText = textField.text ?? "" let newText = range.lowerBound == 0 ? string : currentText.replaced(string, in: range) ?? "" @@ -183,7 +234,7 @@ extension AttendanceDetailViewController: UITextFieldDelegate { } // MARK: - TextField Actions - @objc func keyboardWillShow(_ notification: NSNotification) { + @objc private func keyboardWillShow(_ notification: NSNotification) { if self.isEditingCode { self.attendButton.moveWithKeyboard( willShow: true, @@ -193,7 +244,7 @@ extension AttendanceDetailViewController: UITextFieldDelegate { } } - @objc func keyboardWillHide(_ notification: NSNotification) { + @objc private func keyboardWillHide(_ notification: NSNotification) { self.attendButton.moveWithKeyboard( willShow: false, notification: notification,