Skip to content

Commit

Permalink
[FEAT][#7] 출석체크 코드 입력에 따라 출석버튼 Enabled 변경
Browse files Browse the repository at this point in the history
- Optional+Extension 추가 : isNil, isNotNil, isEmptyOrNil
- textField 입력될 때 마다 버튼 enabled 체크
- 버튼 enabled 값에 따라 configuration 변경
  • Loading branch information
tngusmiso committed Feb 11, 2023
1 parent a430a9b commit 72014c0
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 11 deletions.
24 changes: 16 additions & 8 deletions momoIOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
3ABBF75129975EDA004D4D0B /* AdminSessionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABBF74E29975ED9004D4D0B /* AdminSessionCell.swift */; };
3ABBF75229975EDA004D4D0B /* AdminSessionTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABBF74F29975ED9004D4D0B /* AdminSessionTableViewController.swift */; };
3ABBF75329975EDA004D4D0B /* AddSessionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABBF75029975ED9004D4D0B /* AddSessionViewController.swift */; };
3AE3323229976C2E0024C0C5 /* Collection+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3323029976C2E0024C0C5 /* Collection+Extension.swift */; };
3AE3323329976C2E0024C0C5 /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE3323129976C2E0024C0C5 /* String+Extension.swift */; };
3ABEDB7129976EF100F9BF1C /* UINavigationController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABEDB6F29976EF100F9BF1C /* UINavigationController+Extension.swift */; };
3ABEDB7229976EF100F9BF1C /* Optional+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABEDB7029976EF100F9BF1C /* Optional+Extension.swift */; };
3ABEDB742997719000F9BF1C /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABEDB732997719000F9BF1C /* String+Extension.swift */; };
3ABEDB76299771A900F9BF1C /* Collection+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABEDB75299771A900F9BF1C /* Collection+Extension.swift */; };
BF0408632987B3AA00F1129B /* LoginController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0408622987B3AA00F1129B /* LoginController.swift */; };
BF04086B2987E34800F1129B /* AuthCommonConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF04086A2987E34800F1129B /* AuthCommonConstants.swift */; };
BF04086D2987E38C00F1129B /* RegistrationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF04086C2987E38C00F1129B /* RegistrationController.swift */; };
Expand Down Expand Up @@ -60,8 +62,10 @@
3ABBF74E29975ED9004D4D0B /* AdminSessionCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdminSessionCell.swift; sourceTree = "<group>"; };
3ABBF74F29975ED9004D4D0B /* AdminSessionTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdminSessionTableViewController.swift; sourceTree = "<group>"; };
3ABBF75029975ED9004D4D0B /* AddSessionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddSessionViewController.swift; sourceTree = "<group>"; };
3AE3323029976C2E0024C0C5 /* Collection+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Collection+Extension.swift"; sourceTree = "<group>"; };
3AE3323129976C2E0024C0C5 /* String+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = "<group>"; };
3ABEDB6F29976EF100F9BF1C /* UINavigationController+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UINavigationController+Extension.swift"; sourceTree = "<group>"; };
3ABEDB7029976EF100F9BF1C /* Optional+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Optional+Extension.swift"; sourceTree = "<group>"; };
3ABEDB732997719000F9BF1C /* String+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = "<group>"; };
3ABEDB75299771A900F9BF1C /* Collection+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Collection+Extension.swift"; sourceTree = "<group>"; };
BF0408622987B3AA00F1129B /* LoginController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginController.swift; sourceTree = "<group>"; };
BF04086A2987E34800F1129B /* AuthCommonConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthCommonConstants.swift; sourceTree = "<group>"; };
BF04086C2987E38C00F1129B /* RegistrationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegistrationController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -235,12 +239,14 @@
E8207930298A163400B36FC9 /* Extensions */ = {
isa = PBXGroup;
children = (
3AE3323029976C2E0024C0C5 /* Collection+Extension.swift */,
3ABEDB75299771A900F9BF1C /* Collection+Extension.swift */,
3ABEDB7029976EF100F9BF1C /* Optional+Extension.swift */,
3ABEDB732997719000F9BF1C /* String+Extension.swift */,
3A5AC30F29898B330080323A /* UIButton+Extension.swift */,
3AA713D0298946FF006F922F /* UIColor+Extension.swift */,
3ABEDB6F29976EF100F9BF1C /* UINavigationController+Extension.swift */,
BFB8431E298CFF9200BA11EC /* UIStackView+Extension.swift */,
E8207931298A163400B36FC9 /* UIView+Extension.swift */,
3AE3323129976C2E0024C0C5 /* String+Extension.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -404,17 +410,19 @@
E8207932298A163400B36FC9 /* UIView+Extension.swift in Sources */,
BFB8431F298CFF9200BA11EC /* UIStackView+Extension.swift in Sources */,
3ABBF75129975EDA004D4D0B /* AdminSessionCell.swift in Sources */,
3AE3323229976C2E0024C0C5 /* Collection+Extension.swift in Sources */,
E820792D298A137700B36FC9 /* MainSessionTimeCell.swift in Sources */,
E820792B298A119900B36FC9 /* MainSessionDetailCell.swift in Sources */,
E8207936298A248200B36FC9 /* MainSessionNoInfoCell.swift in Sources */,
BF43B57629951EAF0026DCE3 /* MoimManagementController.swift in Sources */,
3ABEDB742997719000F9BF1C /* String+Extension.swift in Sources */,
3AA713D1298946FF006F922F /* UIColor+Extension.swift in Sources */,
3AA713C929884007006F922F /* MainAttendanceDoneCell.swift in Sources */,
BF43B57A29952AFF0026DCE3 /* MoimSettingCell.swift in Sources */,
E820792F298A138500B36FC9 /* MainSessionAbsentCell.swift in Sources */,
3AE3323329976C2E0024C0C5 /* String+Extension.swift in Sources */,
BF4310FA298C525900270DBF /* AttendanceHistoryCell.swift in Sources */,
3ABEDB76299771A900F9BF1C /* Collection+Extension.swift in Sources */,
3ABEDB7129976EF100F9BF1C /* UINavigationController+Extension.swift in Sources */,
3ABEDB7229976EF100F9BF1C /* Optional+Extension.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
23 changes: 23 additions & 0 deletions momoIOS/Common/Extensions/Optional+Extension.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
21 changes: 21 additions & 0 deletions momoIOS/Common/Extensions/UINavigationController+Extension.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ class AttendanceCodeDetailViewController: 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()
Expand Down Expand Up @@ -51,7 +59,21 @@ class AttendanceCodeDetailViewController: 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() {
Expand Down Expand Up @@ -83,7 +105,8 @@ class AttendanceCodeDetailViewController: 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
Expand Down Expand Up @@ -138,11 +161,39 @@ class AttendanceCodeDetailViewController: 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 AttendanceCodeDetailViewController: 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) ?? ""

Expand Down Expand Up @@ -183,7 +234,7 @@ extension AttendanceCodeDetailViewController: UITextFieldDelegate {
}

// MARK: - TextField Actions
@objc func keyboardWillShow(_ notification: NSNotification) {
@objc private func keyboardWillShow(_ notification: NSNotification) {
if self.isEditingCode {
self.attendButton.moveWithKeyboard(
willShow: true,
Expand All @@ -193,7 +244,7 @@ extension AttendanceCodeDetailViewController: UITextFieldDelegate {
}
}

@objc func keyboardWillHide(_ notification: NSNotification) {
@objc private func keyboardWillHide(_ notification: NSNotification) {
self.attendButton.moveWithKeyboard(
willShow: false,
notification: notification,
Expand Down

0 comments on commit 72014c0

Please sign in to comment.