Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

댓글 작성란 - 프로필 이미지 UI 구현 #316

Merged
merged 4 commits into from
Apr 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네트워크 통신 부분은 뷰모델에서 처리하는 것이 좋을 것 같습니다!
내 정보 데이터가 여러 군데에서 쓰일 것 같은데, 추후 로컬에 저장하는 형태로 바꿔봐도 좋을 것 같습니다!!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

내 정보 데이터가 여러 군데에서 쓰일 것 같은데, 추후 로컬에 저장하는 형태로 바꿔봐도 좋을 것 같습니다!!

저도 그걸 고려하고있었어요. 그래서 사용자 정보 데이터를 User라는 객체로 구성해서 UserManager가 갖고있게 하는 것이 어떨까 싶어요.
어떻게 생각하시나요?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은 것 같습니다!! 이거 제가 마이페이지 작업하면서 추가해놓을까요??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵! 부탁드려요 😁

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