Skip to content

Commit

Permalink
[Feat/#288] 캐릭터 선톡 채팅창이 1줄일 경우 chevron 버튼 숨기도록 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanMinsung committed Nov 18, 2024
1 parent e5885d9 commit 8b6e9ca
Showing 1 changed file with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ extension ORBCharacterChatViewController {
)
}

private func calculateLabelSize(text: String, font: UIFont, maxSize: CGSize) -> CGSize {
let label = UILabel()
label.numberOfLines = 0
label.font = font
label.text = text

// 너비를 제한한 크기 계산
let fittingSize = label.sizeThatFits(CGSize(width: maxSize.width, height: maxSize.height))

// 결과 출력
return fittingSize
}

private func bindData() {
rootView.characterChatBox.chevronImageButton.rx.tap.bind { [weak self] in
guard let self else { return }
Expand Down Expand Up @@ -147,14 +160,16 @@ extension ORBCharacterChatViewController {
.now() + 2,
.now() + 2.5
]
self.configureCharacterChatBox(character: "노바", message: randomResponseList.randomElement()!, mode: .withoutReplyButtonShrinked, animated: true)
rootView.characterChatBox.messageLabel.isHidden = true
rootView.characterChatBox.loadingAnimationView.isHidden = false
rootView.characterChatBox.loadingAnimationView.play()
// rootView.characterChatBox.messageLabel.isHidden = true
// rootView.characterChatBox.loadingAnimationView.isHidden = false
// rootView.characterChatBox.loadingAnimationView.play()
self.configureCharacterChatBox(character: "노바", message: "", mode: .withoutReplyButtonShrinked, animated: true)
self.showCharacterChatBox()

DispatchQueue.main.asyncAfter(deadline: randomResponseTimeList.randomElement()!) { [weak self] in
guard let self else { return }
self.changeChatBoxMode(to: .withoutReplyButtonExpanded, animated: true)
self.configureCharacterChatBox(character: "노바", message: randomResponseList.randomElement()!, mode: .withoutReplyButtonExpanded, animated: true)
// self.changeChatBoxMode(to: .withoutReplyButtonExpanded, animated: true)
}

self.rootView.userChatDisplayView.text = self.rootView.userChatInputView.text.trimmingCharacters(in: .whitespacesAndNewlines)
Expand Down Expand Up @@ -299,6 +314,15 @@ extension ORBCharacterChatViewController {
rootView.characterChatBox.characterNameLabel.text = name + " :"
rootView.characterChatBox.messageLabel.text = message
changeChatBoxMode(to: mode, animated: animated)
let labelFrameWidth = rootView.characterChatBox.messageLabel.frame.width
let labelFrameHeight = rootView.characterChatBox.messageLabel.frame.height
let calculatedLabelSize = calculateLabelSize(
text: message,
font: rootView.characterChatBox.messageLabel.font,
maxSize: .init(width: labelFrameWidth, height: CGFloat.greatestFiniteMagnitude)
)
rootView.characterChatBox.chevronImageButton.isHidden
= (calculatedLabelSize.height > labelFrameHeight) ? false : true
}

func changeChatBoxMode(to mode: ChatBoxMode, animated: Bool) {
Expand Down

0 comments on commit 8b6e9ca

Please sign in to comment.