Skip to content

Commit

Permalink
[Design] #319 - 주소 2줄일 경우 레이아웃 업데이트
Browse files Browse the repository at this point in the history
  • Loading branch information
EunsuSeo01 committed Dec 30, 2024
1 parent 5c8f7c9 commit 3c0e69b
Showing 1 changed file with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,7 @@ final class DetailMapView: BaseView {

addressGuideLabel.snp.makeConstraints {
$0.leading.equalToSuperview().inset(10)
$0.centerY.equalToSuperview()
}

addressLabel.snp.makeConstraints {
$0.leading.equalTo(addressGuideLabel.snp.trailing).offset(8)
$0.centerY.equalTo(addressGuideLabel)
$0.top.equalToSuperview().inset(11.5)
}

copyButton.snp.makeConstraints {
Expand All @@ -72,6 +67,12 @@ final class DetailMapView: BaseView {
$0.width.equalTo(36)
$0.height.equalTo(25)
}

addressLabel.snp.makeConstraints {
$0.leading.equalTo(addressGuideLabel.snp.trailing).offset(8)
$0.trailing.equalTo(copyButton.snp.leading).offset(-6)
$0.centerY.equalToSuperview()
}
}

override func setupStyle() {
Expand Down Expand Up @@ -130,6 +131,8 @@ extension DetailMapView {

func bindData(latitude: Double, longitude: Double, address: String) {
addressLabel.text = address

updateAddressViewLayout()
addMapMarker(latitude: latitude, longitude: longitude)
moveMapCamera(latitude: latitude, longitude: longitude)
}
Expand All @@ -143,6 +146,23 @@ private extension DetailMapView {
copyButton.addTarget(self, action: #selector(copyButtonDidTap), for: .touchUpInside)
}

func updateAddressViewLayout() {
let maxSize: CGSize = CGSize(width: addressLabel.bounds.width, height: CGFloat.greatestFiniteMagnitude)
let expectedSize: CGSize = addressLabel.sizeThatFits(maxSize)
let spacing: CGFloat = expectedSize.height > 18 ? 8 : 11.5 // 줄 수를 기준으로

addressView.snp.updateConstraints {
$0.top.equalTo(mapView.snp.bottom).offset(-1)
$0.leading.trailing.equalTo(mapView)
$0.height.equalTo(spacing + expectedSize.height + spacing)
}

addressGuideLabel.snp.updateConstraints {
$0.leading.equalToSuperview().inset(10)
$0.top.equalToSuperview().inset(spacing)
}
}

func copyAddressToClipboard() {
UIPasteboard.general.string = addressLabel.text
}
Expand Down

0 comments on commit 3c0e69b

Please sign in to comment.