2020-08-28 19:56:28 +00:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Kingfisher
|
2020-09-01 07:33:49 +00:00
|
|
|
import ViewModels
|
2020-08-28 19:56:28 +00:00
|
|
|
|
|
|
|
class AttachmentView: UIView {
|
|
|
|
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.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true
|
|
|
|
imageView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor).isActive = true
|
|
|
|
imageView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
|
|
|
|
imageView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor).isActive = true
|
|
|
|
imageView.contentMode = .scaleAspectFill
|
|
|
|
imageView.clipsToBounds = true
|
|
|
|
|
|
|
|
addSubview(button)
|
|
|
|
button.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
button.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true
|
|
|
|
button.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor).isActive = true
|
|
|
|
button.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
|
|
|
|
button.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor).isActive = true
|
|
|
|
|
|
|
|
let highlightedButtonBackgroundImage = UIColor(white: 0, alpha: 0.5).image()
|
|
|
|
|
|
|
|
button.setBackgroundImage(highlightedButtonBackgroundImage, for: .highlighted)
|
|
|
|
|
|
|
|
switch viewModel.attachment.type {
|
|
|
|
case .image:
|
|
|
|
imageView.kf.setImage(with: viewModel.attachment.previewUrl)
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@available(*, unavailable)
|
|
|
|
required init?(coder: NSCoder) {
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
}
|
|
|
|
}
|