From f4accd8635d965dea443636095182f8a179c96fb Mon Sep 17 00:00:00 2001 From: binisnull Date: Fri, 22 Nov 2024 02:58:09 +0900 Subject: [PATCH] =?UTF-8?q?[Fix]=20#61=20-=20placeholder=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B0=8F=20=EB=A0=88=EC=9D=B4=EC=95=84=EC=9B=83=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20+=20textView=20=EB=8F=99=EC=A0=81=EB=86=92?= =?UTF-8?q?=EC=9D=B4=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit placeholder를 textView.text에서 UILabel로 수정 댓글 여러줄 작성, 복붙, 한번에 지우기 등에서 생기는 레이아웃 버그 수정 --- .../xcshareddata/swiftpm/Package.resolved | 2 +- .../FeedDetailViewController.swift | 110 ++++++++++++------ .../Home/Views/FeedDetailView.swift | 2 +- .../Views/Subviews/FeedBottomWriteView.swift | 25 +++- 4 files changed, 96 insertions(+), 43 deletions(-) diff --git a/Wable-iOS.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Wable-iOS.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index d67d471..6b60e72 100644 --- a/Wable-iOS.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Wable-iOS.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "01bf7d25d467d41738d67599f9ee5873406b56853331a002e956d05a4c745ef1", + "originHash" : "872b30c821fcd9d5dc671e1e1c3634f0741eb85abdf80456a5fa1596cfb9e63f", "pins" : [ { "identity" : "abseil-cpp-binary", diff --git a/Wable-iOS/Presentation/Home/ViewController/FeedDetailViewController.swift b/Wable-iOS/Presentation/Home/ViewController/FeedDetailViewController.swift index adc4e29..2139364 100644 --- a/Wable-iOS/Presentation/Home/ViewController/FeedDetailViewController.swift +++ b/Wable-iOS/Presentation/Home/ViewController/FeedDetailViewController.swift @@ -62,7 +62,7 @@ final class FeedDetailViewController: UIViewController { var relateText: String = "" let warnUserURL = URL(string: StringLiterals.Network.warnUserGoogleFormURL) private let placeholder = StringLiterals.Home.placeholder - + var nowShowingPopup: String = "" let refreshControl = UIRefreshControl() @@ -77,6 +77,7 @@ final class FeedDetailViewController: UIViewController { } } + // TODO: - 이놈의 아웃풋 = textField placeholder??(닉네임) private let replyButtonDidTapSubject = PassthroughSubject() // MARK: - UI Components @@ -143,7 +144,7 @@ extension FeedDetailViewController { self.view.backgroundColor = .wableWhite feedDetailView.feedDetailTableView.rowHeight = UITableView.automaticDimension feedDetailView.feedDetailTableView.estimatedRowHeight = 100 - feedDetailView.bottomWriteView.writeTextView.text = (self.feedData?.memberNickname ?? "") + self.placeholder + feedDetailView.bottomWriteView.setPlaceholder(nickname: self.feedData?.memberNickname ?? "") feedDetailView.bottomWriteView.writeTextView.textContainerInset = UIEdgeInsets(top: 10.adjusted, left: 10.adjusted, bottom: 10.adjusted, @@ -264,8 +265,8 @@ extension FeedDetailViewController { DispatchQueue.main.async { self.didPullToRefresh() self.feedDetailView.bottomWriteView.uploadButton.isEnabled = false - self.feedDetailView.bottomWriteView.writeTextView.textColor = .gray700 - self.feedDetailView.bottomWriteView.writeTextView.text = (self.feedData?.memberNickname ?? "") + self.placeholder + self.feedDetailView.bottomWriteView.writeTextView.text = nil + self.feedDetailView.bottomWriteView.setPlaceholder(nickname: self.feedData?.memberNickname ?? "") self.feedDetailView.bottomWriteView.writeTextView.textContainerInset = UIEdgeInsets(top: 10.adjusted, left: 10.adjusted, bottom: 10.adjusted, @@ -297,45 +298,34 @@ extension FeedDetailViewController { extension FeedDetailViewController: UITextViewDelegate { - func textViewDidBeginEditing(_ textView: UITextView) { - guard textView.textColor == .gray700 else { return } - textView.textColor = .wableBlack - textView.text = nil - print("textViewDidBeginEditing") + func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { + // 전체 텍스트 삭제를 확인 + let isDeletingAllText = range == NSRange(location: 0, length: textView.text.count) && text.isEmpty + + if isDeletingAllText { + setTextViewHeight(textView, isDeletingAllText: isDeletingAllText) + } + + return true } func textViewDidChange(_ textView: UITextView) { - let size = CGSize(width: view.frame.width, height: .infinity) - let estimatedSize = textView.sizeThatFits(size) + // 텍스트뷰 크기 조정 로직 + setTextViewHeight(textView, isDeletingAllText: false) - if estimatedSize.height > 86 { - textView.isScrollEnabled = true + guard !textView.text.isEmpty else { + // TODO: - 여기 닉네임 받는 부분 변경. vc 프로퍼티 아니도록 + feedDetailView.bottomWriteView.setPlaceholder(nickname: feedData?.memberNickname ?? String()) return - } else { - // textView.isScrollEnabled = false - textView.isScrollEnabled = true - - // 레이아웃 중 height 수정 - textView.snp.remakeConstraints { - $0.height.equalTo(estimatedSize) - $0.leading.equalToSuperview().inset(16.adjusted) - $0.trailing.equalTo(feedDetailView.bottomWriteView.uploadButton.snp.leading).offset(-6.adjusted) - $0.centerY.equalToSuperview() - } - - feedDetailView.bottomWriteView.snp.remakeConstraints { - $0.leading.trailing.equalToSuperview() - $0.height.equalTo(estimatedSize.height + 20) - } } + feedDetailView.bottomWriteView.placeholderLabel.isHidden = true + if !textView.text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { - feedDetailView.bottomWriteView.uploadButton.setImage(ImageLiterals.Button.btnRipplePress, for: .normal) - feedDetailView.bottomWriteView.uploadButton.isEnabled = true + makeUploadButtonActivate() } else { - feedDetailView.bottomWriteView.uploadButton.setImage(ImageLiterals.Button.btnRippleDefault, for: .normal) - feedDetailView.bottomWriteView.uploadButton.isEnabled = false + makeUploadButtonDeactivate() } } @@ -343,13 +333,44 @@ extension FeedDetailViewController: UITextViewDelegate { print("textViewDidEndEditing") if textView.text.isEmpty { - textView.text = (feedData?.memberNickname ?? String()) + StringLiterals.Home.placeholder - textView.textColor = .gray700 - feedDetailView.bottomWriteView.uploadButton.setImage(ImageLiterals.Button.btnRippleDefault, for: .normal) - feedDetailView.bottomWriteView.uploadButton.isEnabled = false + feedDetailView.bottomWriteView.setPlaceholder(nickname: feedData?.memberNickname ?? String()) + makeUploadButtonDeactivate() } } + // 댓글 작성 중 텍스트뷰 높이 조정 + func setTextViewHeight(_ textView: UITextView, isDeletingAllText: Bool) { + let size = CGSize(width: textView.frame.width, height: .infinity) + let estimatedSize = textView.sizeThatFits(size) + + textView.isScrollEnabled = !isDeletingAllText && estimatedSize.height >= 95.adjusted + + feedDetailView.bottomWriteView.writeTextView.snp.updateConstraints { + $0.height.lessThanOrEqualTo(100.adjusted) + } + + feedDetailView.bottomWriteView.snp.updateConstraints { + $0.height.lessThanOrEqualTo(120.adjusted) + } + + UIView.animate(withDuration: 0.2) { + self.view.layoutIfNeeded() + } + } + + // 댓글 업로드 버튼 활성화 + private func makeUploadButtonActivate() { + feedDetailView.bottomWriteView.uploadButton.setImage(ImageLiterals.Button.btnRipplePress, for: .normal) + feedDetailView.bottomWriteView.uploadButton.isEnabled = true + } + + // 댓글 업로드 버튼 비활성화 + private func makeUploadButtonDeactivate() { + feedDetailView.bottomWriteView.uploadButton.setImage(ImageLiterals.Button.btnRippleDefault, for: .normal) + feedDetailView.bottomWriteView.uploadButton.isEnabled = false + } + + private func showGhostPopupView() { self.ghostPopupView = WablePopupView(popupTitle: StringLiterals.Home.ghostPopupTitle, popupContent: "", @@ -611,6 +632,14 @@ extension FeedDetailViewController: UITableViewDataSource { } } + // 게시글에 대한 댓글 달기 버튼이 눌렸을 때는 nil로 보내기 + // 기존에 있었던 댓글 삭제해야함 + cell.bottomView.commentButtonTapped = { [weak self] in + self?.feedDetailView.bottomWriteView.writeTextView.becomeFirstResponder() + self?.replyButtonDidTapSubject.send(nil) + + } + return cell case .reply: @@ -698,8 +727,13 @@ extension FeedDetailViewController: UITableViewDataSource { } cell.bottomView.replyButtonTapped = { [weak self] in - self?.feedDetailView.bottomWriteView.writeTextView.becomeFirstResponder() + self?.feedDetailView.bottomWriteView.writeTextView.resignFirstResponder() + + // MARK: - 여기서 인덱스로 유저 닉네임, 댓글작성자 ID, 댓글ID 찾아서 다시 VC로 전달 self?.replyButtonDidTapSubject.send(indexPath.row) + + self?.feedDetailView.bottomWriteView.writeTextView.becomeFirstResponder() + } return cell diff --git a/Wable-iOS/Presentation/Home/Views/FeedDetailView.swift b/Wable-iOS/Presentation/Home/Views/FeedDetailView.swift index 314b228..e3558b9 100644 --- a/Wable-iOS/Presentation/Home/Views/FeedDetailView.swift +++ b/Wable-iOS/Presentation/Home/Views/FeedDetailView.swift @@ -65,7 +65,7 @@ extension FeedDetailView { bottomWriteView.snp.makeConstraints { $0.leading.trailing.equalToSuperview() - $0.height.equalTo(62.adjusted) + $0.height.lessThanOrEqualTo(120.adjusted) } keyboardLayoutGuide.topAnchor.constraint(equalToSystemSpacingBelow: bottomWriteView.bottomAnchor, multiplier: 1.0).isActive = true diff --git a/Wable-iOS/Presentation/Home/Views/Subviews/FeedBottomWriteView.swift b/Wable-iOS/Presentation/Home/Views/Subviews/FeedBottomWriteView.swift index f19f263..39841f4 100644 --- a/Wable-iOS/Presentation/Home/Views/Subviews/FeedBottomWriteView.swift +++ b/Wable-iOS/Presentation/Home/Views/Subviews/FeedBottomWriteView.swift @@ -31,10 +31,18 @@ final class FeedBottomWriteView: UIView { textView.layer.cornerRadius = 16.adjusted textView.backgroundColor = .gray100 textView.font = .body4 - textView.textColor = .gray700 + textView.textColor = .wableBlack return textView }() + var placeholderLabel: UILabel = { + let label = UILabel() + label.font = .body4 + label.textColor = .gray700 + label.backgroundColor = .clear + return label + }() + var uploadButton: UIButton = { let button = UIButton() button.setImage(ImageLiterals.Button.btnRippleDefault, for: .disabled) @@ -68,6 +76,7 @@ extension FeedBottomWriteView { private func setHierarchy() { self.addSubviews(tabLottieAnimationView, writeTextView, + placeholderLabel, uploadButton) } @@ -78,10 +87,15 @@ extension FeedBottomWriteView { } writeTextView.snp.makeConstraints { - $0.height.equalTo(42.adjusted) + $0.height.lessThanOrEqualTo(100.adjusted) $0.leading.equalToSuperview().inset(16.adjusted) $0.trailing.equalTo(uploadButton.snp.leading).offset(-6.adjusted) - $0.centerY.equalToSuperview() + $0.top.bottom.equalToSuperview().inset(10.adjusted) + } + + placeholderLabel.snp.makeConstraints { + $0.top.equalTo(writeTextView).inset(10.adjusted) + $0.leading.equalTo(writeTextView).inset(14.adjusted) } uploadButton.snp.makeConstraints { @@ -91,6 +105,11 @@ extension FeedBottomWriteView { } } + func setPlaceholder(nickname: String) { + placeholderLabel.isHidden = false + placeholderLabel.text = nickname + StringLiterals.Home.placeholder + } + private func setAddTarget() { uploadButton.addTarget(self, action: #selector(postButtonDidTapped), for: .touchUpInside) }