Skip to content

Commit

Permalink
[Feat] Runnect#139 - 수정 페이지 UI 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
dlwogus0128 committed May 13, 2023
1 parent ad7638c commit 6ac9775
Showing 1 changed file with 100 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ final class ActivityRecordDetailVC: UIViewController {
private var recordId: Int?

private var isEditMode: Bool = false

private let courseTitleMaxLength = 20

// MARK: - UI Components

Expand All @@ -38,11 +40,20 @@ final class ActivityRecordDetailVC: UIViewController {
private let mapImageView = UIImageView()

private let courseTitleLabel = UILabel().then {
$0.text = "제목"
$0.textColor = .g1
$0.font = .h4
}

private let courseTitleTextField = UITextField().then {
$0.attributedPlaceholder = NSAttributedString(
string: String(),
attributes: [.font: UIFont.h4, .foregroundColor: UIColor.g3]
)
$0.font = .h4
$0.textColor = .g1
$0.addLeftPadding(width: 2)
}

private let recordDateInfoView = CourseDetailInfoView(title: "날짜", description: String())

private let recordDepartureInfoView = CourseDetailInfoView(title: "출발지", description: String())
Expand Down Expand Up @@ -103,6 +114,8 @@ final class ActivityRecordDetailVC: UIViewController {
setUI()
setLayout()
setAddTarget()
self.setKeyboardNotification()
self.setTapGesture()
}
}

Expand All @@ -129,6 +142,39 @@ extension ActivityRecordDetailVC {
[ editAction, deleteAction ].forEach { alertController.addAction($0) }
present(alertController, animated: true, completion: nil)
}

@objc private func textFieldTextDidChange() {
guard let text = courseTitleTextField.text else { return }

self.finishEditButton.isEnabled = !text.isEmpty

if text.count > courseTitleMaxLength {
let index = text.index(text.startIndex, offsetBy: courseTitleMaxLength)
let newString = text[text.startIndex..<index]
self.courseTitleTextField.text = String(newString)
}
}

@objc private func keyboardWillShow(_ notification: Notification) {
guard let userInfo = notification.userInfo,
let keyboardFrame = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else {
return
}

let contentInset = UIEdgeInsets(
top: 0.0,
left: 0.0,
bottom: keyboardFrame.size.height,
right: 0.0)
middleScorollView.contentInset = contentInset
middleScorollView.scrollIndicatorInsets = contentInset
}

@objc private func keyboardWillHide() {
let contentInset = UIEdgeInsets.zero
middleScorollView.contentInset = contentInset
middleScorollView.scrollIndicatorInsets = contentInset
}
}

// MARK: - Methods
Expand Down Expand Up @@ -159,6 +205,7 @@ extension ActivityRecordDetailVC {

private func setAddTarget() {
self.moreButton.addTarget(self, action: #selector(moreButtonDidTap), for: .touchUpInside)
self.courseTitleTextField.addTarget(self, action: #selector(textFieldTextDidChange), for: .editingChanged)
}

func setDetailInfoStakcView(title: UIView, value: UIView) -> UIStackView {
Expand Down Expand Up @@ -201,12 +248,33 @@ extension ActivityRecordDetailVC {
label.font = .b4
return label
}

// 키보드가 올라오면 scrollView 위치 조정
private func setKeyboardNotification() {
NotificationCenter.default.addObserver(
self,
selector: #selector(keyboardWillShow),
name: UIResponder.keyboardWillShowNotification,
object: nil)

NotificationCenter.default.addObserver(
self,
selector: #selector(keyboardWillHide),
name: UIResponder.keyboardWillHideNotification,
object: nil)
}

// 화면 터치 시 키보드 내리기
private func setTapGesture() {
let tap = UITapGestureRecognizer(target: view, action: #selector(UIView.endEditing))
tap.cancelsTouchesInView = false
view.addGestureRecognizer(tap)
}
}

// MARK: - Layout Helpers

extension ActivityRecordDetailVC {

private func setUI() {
view.backgroundColor = .w1
middleScorollView.backgroundColor = .w1
Expand Down Expand Up @@ -315,16 +383,39 @@ extension ActivityRecordDetailVC {
make.height.equalTo(middleScorollView.snp.width)
}

self.courseTitleLabel.isHidden = true

self.courseTitleTextField.text = self.courseTitleLabel.text

middleScorollView.addSubview(courseTitleTextField)

courseTitleTextField.snp.makeConstraints { make in
make.top.equalTo(mapImageView.snp.bottom).offset(27)
make.leading.trailing.equalToSuperview().inset(16)
make.height.equalTo(35)
}

self.finishEditButton.isHidden = false

firstHorizontalDivideLine.snp.remakeConstraints { make in
make.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(16)
make.height.equalTo(2)
make.top.equalTo(courseTitleTextField.snp.bottom).offset(5)
}

recordInfoStackView.snp.makeConstraints { make in
make.top.equalTo(firstHorizontalDivideLine.snp.bottom).offset(20)
make.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(16)
}

secondHorizontalDivideLine.snp.remakeConstraints { make in
make.leading.trailing.equalTo(view.safeAreaLayoutGuide)
make.height.equalTo(7)
make.top.equalTo(recordInfoStackView.snp.bottom).offset(11)
make.top.equalTo(recordInfoStackView.snp.bottom).offset(24)
}

self.finishEditButton.isHidden = false

recordSubInfoStackView.snp.remakeConstraints { make in
make.top.equalTo(secondHorizontalDivideLine.snp.bottom).offset(20)
make.top.equalTo(secondHorizontalDivideLine.snp.bottom).offset(22)
make.centerX.equalToSuperview()
}

Expand All @@ -333,7 +424,7 @@ extension ActivityRecordDetailVC {
finishEditButton.snp.makeConstraints { make in
make.bottom.equalToSuperview().inset(30)
make.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(16)
make.top.equalTo(recordSubInfoStackView.snp.bottom).offset(44)
make.top.equalTo(recordSubInfoStackView.snp.bottom).offset(50)
make.height.equalTo(44)
}
}
Expand All @@ -345,7 +436,6 @@ extension ActivityRecordDetailVC {
extension ActivityRecordDetailVC {
private func deleteRecord() {
guard let recordId = self.recordId else { return }
print(recordId)
LoadingIndicator.showLoading()
recordProvider.request(.deleteRecord(recordIdList: [recordId])) { [weak self] response in
LoadingIndicator.hideLoading()
Expand All @@ -371,4 +461,6 @@ extension ActivityRecordDetailVC {
}
}
}


}

0 comments on commit 6ac9775

Please sign in to comment.