Skip to content

Commit

Permalink
#297: Share Extension에 드랍하기 버튼 UI 추가
Browse files Browse the repository at this point in the history
- 기존 드랍하기 버튼 이외에, 텍스트뷰 클릭해서 키보드 올라올때, 키보드 바로위에 드랍하기 버튼 추가
  • Loading branch information
joseph704 committed Aug 14, 2024
1 parent f56a538 commit 494c973
Showing 1 changed file with 53 additions and 11 deletions.
64 changes: 53 additions & 11 deletions StreetDrop/ShareExtension/View/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ final class ShareViewController: UIViewController {
return button
}()

private let dropButtonOnKeyBoard: UIButton = {
let button: UIButton = .init(type: .system)
button.setTitle("드랍하기", for: .normal)
button.setTitleColor(.gray900, for: .normal)
button.titleLabel?.font = .pretendard(size: 16, weight: 700)
button.backgroundColor = .primary500
button.isEnabled = false
button.isHidden = true

return button
}()

override func viewDidLoad() {
super.viewDidLoad()
bindAction()
Expand Down Expand Up @@ -252,6 +264,7 @@ private extension ShareViewController {
commentClearButton.rx.tap
.bind { [weak self] in
self?.commentTextView.text = nil
self?.checkAvailableToDrop()
}.disposed(by: disposeBag)

communityGuideButton.rx.tap
Expand Down Expand Up @@ -318,7 +331,9 @@ private extension ShareViewController {
artistNameLabel,
commentView,
communityGuideButton,
communityGuideDetailView
communityGuideDetailView,
dropButton,
dropButtonOnKeyBoard
].forEach {
containerView.addSubview($0)
}
Expand Down Expand Up @@ -402,6 +417,17 @@ private extension ShareViewController {
$0.leading.equalTo(communityGuideButton)
$0.top.equalTo(communityGuideButton.snp.bottom).offset(8+8) // spacing + 말풍선꼬리높이
}

dropButton.snp.makeConstraints {
$0.height.equalTo(56)
$0.horizontalEdges.equalToSuperview().inset(24)
$0.bottom.equalTo(self.view.safeAreaLayoutGuide).inset(16)
}

dropButtonOnKeyBoard.snp.makeConstraints {
$0.height.equalTo(56)
$0.horizontalEdges.equalToSuperview()
}
}
}

Expand Down Expand Up @@ -490,16 +516,20 @@ private extension ShareViewController {
&& commentTextView.text != ""
&& commentTextView.text != placeHolder
) {
dropButton.isEnabled = true
dropButton.backgroundColor = .primary500
dropButton.setTitleColor(.gray900, for: .normal)
[dropButton, dropButtonOnKeyBoard].forEach {
$0.isEnabled = true
$0.backgroundColor = .primary500
$0.setTitleColor(.gray900, for: .normal)
}
} else {
dropButton.isEnabled = false
dropButton.setTitleColor(
.gray400,
for: .normal
)
dropButton.backgroundColor = .gray300
[dropButton, dropButtonOnKeyBoard].forEach {
$0.isEnabled = false
$0.setTitleColor(
.gray400,
for: .normal
)
$0.backgroundColor = .gray300
}
}
}
}
Expand Down Expand Up @@ -545,14 +575,26 @@ private extension ShareViewController {

view.layoutIfNeeded()
}

DispatchQueue.main.asyncAfter(deadline: .now() + 0.35, execute: { [weak self] in
guard let self = self,
let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue
else { return }
// 키보드의 위치에 맞게 버튼 위치 조정
let keyboardHeight = keyboardFrame.cgRectValue.height
dropButtonOnKeyBoard.isHidden = false
checkAvailableToDrop()
dropButtonOnKeyBoard.frame.origin.y = view.frame.height - keyboardHeight - 56
})

}

@objc func keyboardWillHide() {
UIView.animate(withDuration: 0.3) { [weak self] in
self?.containerView.snp.updateConstraints {
let screenHeight = UIScreen.main.bounds.height
$0.height.equalTo(596)
}
self?.dropButtonOnKeyBoard.isHidden = true
self?.view.layoutIfNeeded()
}
}
Expand Down

0 comments on commit 494c973

Please sign in to comment.