消息列表按实际图片尺寸显示

This commit is contained in:
Fin 2025-05-22 18:03:37 +08:00
parent 8526bf39f7
commit d16b0c8b4f

View File

@ -138,11 +138,6 @@ class MessageItemView: UIView {
make.left.equalTo(12)
make.right.equalTo(-12)
}
imageView.snp.makeConstraints { make in
make.width.equalTo(panel).inset(12).priority(.low)
make.width.lessThanOrEqualTo(500)
make.height.equalTo(imageView.snp.width).multipliedBy(0.55)
}
dateLabel.snp.makeConstraints { make in
make.left.equalTo(contentStackView)
make.top.equalTo(contentStackView.snp.bottom).offset(12)
@ -172,13 +167,28 @@ extension MessageItemView {
if let image = message.image {
imageView.isHidden = false
// loadDiskFileSynchronously
imageView.kf.setImage(with: URL(string: image), options: [.targetCache(imageCache), .keepCurrentImageWhileLoading]) { [weak self] _ in
imageView.kf.setImage(with: URL(string: image), options: [.targetCache(imageCache), .keepCurrentImageWhileLoading, .loadDiskFileSynchronously]) { [weak self] result in
//
let isDarkMode = UIScreen.main.traitCollection.userInterfaceStyle == .dark
self?.imageView.setupImageViewer(options: [.closeIcon(UIImage(named: "back")!), .theme(isDarkMode ? .dark : .light)])
guard let self else { return }
guard let image = try? result.get().image else {
return
}
layoutImageView(image: image)
}
} else {
imageView.isHidden = true
}
}
func layoutImageView(image: UIImage) {
// iPad 500
let panelWidth = min(min(500, UIScreen.main.bounds.width - 32 - 24), image.width)
imageView.snp.remakeConstraints { make in
make.width.equalTo(panelWidth)
make.height.equalTo(self.imageView.snp.width).multipliedBy(image.size.height / image.size.width)
}
}
}