Skip to content

Commit

Permalink
[Fix] #61 - placeholder 로직 및 레이아웃 수정 + textView 동적높이 버그 수정
Browse files Browse the repository at this point in the history
placeholder를 textView.text에서 UILabel로 수정
댓글 여러줄 작성, 복붙, 한번에 지우기 등에서 생기는 레이아웃 버그 수정
  • Loading branch information
binisnil committed Nov 21, 2024
1 parent 266a690 commit f4accd8
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "01bf7d25d467d41738d67599f9ee5873406b56853331a002e956d05a4c745ef1",
"originHash" : "872b30c821fcd9d5dc671e1e1c3634f0741eb85abdf80456a5fa1596cfb9e63f",
"pins" : [
{
"identity" : "abseil-cpp-binary",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -77,6 +77,7 @@ final class FeedDetailViewController: UIViewController {
}
}

// TODO: - 이놈의 아웃풋 = textField placeholder??(닉네임)
private let replyButtonDidTapSubject = PassthroughSubject<Int?, Never>()

// MARK: - UI Components
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -297,59 +298,79 @@ 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()
}
}

func textViewDidEndEditing(_ textView: UITextView) {
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: "",
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Wable-iOS/Presentation/Home/Views/FeedDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -68,6 +76,7 @@ extension FeedBottomWriteView {
private func setHierarchy() {
self.addSubviews(tabLottieAnimationView,
writeTextView,
placeholderLabel,
uploadButton)
}

Expand All @@ -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 {
Expand All @@ -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)
}
Expand Down

0 comments on commit f4accd8

Please sign in to comment.