Skip to content

Commit

Permalink
[FEAT][#7] 출석체크 코드 입력에 따라 출석버튼 Enabled 변경
Browse files Browse the repository at this point in the history
## Description
- Optional+Extension 추가 : isNil, isNotNil, isEmptyOrNil
- textField 입력될 때 마다 버튼 enabled 체크
- 버튼 enabled 값에 따라 configuration 변경
  • Loading branch information
tngusmiso committed Feb 11, 2023
1 parent 5e696ad commit cca6f56
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
23 changes: 23 additions & 0 deletions 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
}
}
4 changes: 4 additions & 0 deletions momoIOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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 */; };
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 */; };
Expand Down Expand Up @@ -49,6 +50,7 @@
3AA713D0298946FF006F922F /* UIColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extension.swift"; sourceTree = "<group>"; };
3ABBF7352996B6C9004D4D0B /* String+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = "<group>"; };
3ABBF7392996B8C9004D4D0B /* Collection+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Collection+Extension.swift"; sourceTree = "<group>"; };
3ABBF73B2996D48C004D4D0B /* Optional+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Optional+Extension.swift"; sourceTree = "<group>"; };
3ADF660F2993F48A00577028 /* AttendanceDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttendanceDetailViewController.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>"; };
Expand Down Expand Up @@ -180,6 +182,7 @@
BFB8431E298CFF9200BA11EC /* UIStackView+Extension.swift */,
3ABBF7352996B6C9004D4D0B /* String+Extension.swift */,
3ABBF7392996B8C9004D4D0B /* Collection+Extension.swift */,
3ABBF73B2996D48C004D4D0B /* Optional+Extension.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -349,6 +352,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 */,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -83,7 +91,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(didTapAttendanceButton), for: .touchUpInside)
}

// MARK: - Layout
Expand Down Expand Up @@ -138,11 +147,35 @@ class AttendanceDetailViewController: UIViewController {
make.height.equalTo(54)
}
}

// MARK: - Actions
@objc private func didTapAttendanceButton() {
self.navigationController?.popViewController(animated: true)
}

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)
}
}
}

// 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) ?? ""

Expand Down Expand Up @@ -183,7 +216,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,
Expand All @@ -193,7 +226,7 @@ extension AttendanceDetailViewController: 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 cca6f56

Please sign in to comment.