Skip to content

Commit

Permalink
Merge pull request #316 from PLUB2022/feat/302-Comment/Profile
Browse files Browse the repository at this point in the history
댓글 작성란 - 프로필 이미지 UI 구현
  • Loading branch information
WhiteHyun authored Apr 27, 2023
2 parents a4ee924 + 563c190 commit caa8ddd
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions PLUB/Sources/Views/Home/Clipboard/Component/CommentInputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ final class CommentInputView: UIView {

private let profileImageView = UIImageView(image: .init(named: "userDefaultImage")).then {
$0.contentMode = .scaleAspectFit
$0.clipsToBounds = true
$0.layer.cornerRadius = CGFloat(Size.initialStateHeight) * 0.5
}

private let textViewContainerView = UIStackView().then {
Expand Down Expand Up @@ -100,30 +102,42 @@ final class CommentInputView: UIView {
private func setupConstraints() {

commentStackView.snp.makeConstraints {
$0.directionalVerticalEdges.equalToSuperview().inset(8)
$0.directionalHorizontalEdges.equalToSuperview().inset(24)
$0.directionalVerticalEdges.equalToSuperview().inset(Margin.vertical)
$0.directionalHorizontalEdges.equalToSuperview().inset(Margin.horizontal)
}

profileImageView.snp.makeConstraints {
$0.size.equalTo(32)
$0.size.equalTo(Size.initialStateHeight)
}

textView.snp.makeConstraints {
$0.height.greaterThanOrEqualTo(32)
$0.height.greaterThanOrEqualTo(Size.initialStateHeight)
}

uploadButton.snp.makeConstraints {
$0.size.equalTo(32)
$0.size.equalTo(Size.initialStateHeight)
}

commentSeparatorLineView.snp.makeConstraints {
$0.top.equalToSuperview()
$0.directionalHorizontalEdges.equalToSuperview()
$0.height.equalTo(1)
$0.height.equalTo(Size.barHeight)
}
}

private func bind() {
// 프로필 이미지 설정
AccountService.shared.inquireMyInfo()
.compactMap { result -> String? in
guard case let .success(response) = result else { return nil }
return response.data?.profileImage
}
.subscribe(with: self) { owner, profileImage in
owner.profileImageView.kf.setImage(with: URL(string: profileImage))
}
.disposed(by: disposeBag)

// 댓글 작성 버튼 탭
uploadButton.rx.tap
.asDriver()
.drive(with: self) { owner, _ in
Expand All @@ -145,14 +159,16 @@ final class CommentInputView: UIView {
let size = CGSize(width: owner.textView.frame.width, height: .infinity)
let estimatedSize = owner.textView.sizeThatFits(size)
owner.textView.snp.remakeConstraints {
$0.height.greaterThanOrEqualTo(32).priority(.required)
$0.height.greaterThanOrEqualTo(Size.initialStateHeight).priority(.required)
$0.height.equalTo(estimatedSize.height).priority(.high)
}
}
.disposed(by: disposeBag)
}
}

// MARK: - UITextViewDelegate

extension CommentInputView: UITextViewDelegate {
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
let currentText = textView.text ?? ""
Expand All @@ -164,8 +180,20 @@ extension CommentInputView: UITextViewDelegate {
}
}

extension CommentInputView {
// MARK: - Constants

private extension CommentInputView {
enum Constants {
static let placeholder = "댓글을 입력하세요"
}

enum Size {
static let initialStateHeight = 32
static let barHeight = 1
}

enum Margin {
static let vertical = 8
static let horizontal = 16
}
}

0 comments on commit caa8ddd

Please sign in to comment.