2020-08-28 19:56:28 +00:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import Kingfisher
|
2020-09-05 02:31:43 +00:00
|
|
|
import UIKit
|
2020-09-01 07:33:49 +00:00
|
|
|
import ViewModels
|
2020-08-28 19:56:28 +00:00
|
|
|
|
2020-09-08 02:35:28 +00:00
|
|
|
final class AttachmentView: UIView {
|
2020-08-28 19:56:28 +00:00
|
|
|
let imageView = AnimatedImageView()
|
|
|
|
let button = UIButton()
|
|
|
|
let viewModel: AttachmentViewModel
|
|
|
|
|
|
|
|
init(viewModel: AttachmentViewModel) {
|
|
|
|
self.viewModel = viewModel
|
|
|
|
|
|
|
|
super.init(frame: .zero)
|
|
|
|
|
|
|
|
layoutMargins = .zero
|
|
|
|
addSubview(imageView)
|
|
|
|
imageView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
imageView.contentMode = .scaleAspectFill
|
|
|
|
imageView.clipsToBounds = true
|
|
|
|
|
|
|
|
addSubview(button)
|
|
|
|
button.translatesAutoresizingMaskIntoConstraints = false
|
2020-09-29 01:32:28 +00:00
|
|
|
button.setBackgroundImage(.highlightedButtonBackground, for: .highlighted)
|
2020-08-28 19:56:28 +00:00
|
|
|
|
|
|
|
switch viewModel.attachment.type {
|
|
|
|
case .image:
|
|
|
|
imageView.kf.setImage(with: viewModel.attachment.previewUrl)
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
2020-09-29 01:32:28 +00:00
|
|
|
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
imageView.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor),
|
|
|
|
imageView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor),
|
|
|
|
imageView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor),
|
|
|
|
imageView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor),
|
|
|
|
button.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor),
|
|
|
|
button.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor),
|
|
|
|
button.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor),
|
|
|
|
button.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor)
|
|
|
|
])
|
2020-08-28 19:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@available(*, unavailable)
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
}
|
|
|
|
}
|