metatext/Views/AttachmentUploadView.swift

56 lines
2.1 KiB
Swift
Raw Normal View History

2020-12-17 06:48:06 +00:00
// Copyright © 2020 Metabolist. All rights reserved.
import Combine
import UIKit
import ViewModels
final class AttachmentUploadView: UIView {
2021-01-03 01:22:17 +00:00
let label = UILabel()
2020-12-17 06:48:06 +00:00
let progressView = UIProgressView(progressViewStyle: .default)
private var progressCancellable: AnyCancellable?
2020-12-19 06:30:19 +00:00
var attachmentUpload: AttachmentUpload? {
2020-12-17 06:48:06 +00:00
didSet {
if let attachmentUpload = attachmentUpload {
progressCancellable = attachmentUpload.progress.publisher(for: \.fractionCompleted)
.receive(on: DispatchQueue.main)
.sink { [weak self] in self?.progressView.progress = Float($0) }
isHidden = false
} else {
isHidden = true
}
}
}
init() {
super.init(frame: .zero)
2021-01-03 01:22:17 +00:00
addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false
label.adjustsFontForContentSizeCategory = true
label.font = .preferredFont(forTextStyle: .callout)
label.textAlignment = .center
label.text = NSLocalizedString("compose.attachment.uploading", comment: "")
label.textColor = .secondaryLabel
label.numberOfLines = 0
2020-12-17 06:48:06 +00:00
addSubview(progressView)
progressView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
2021-01-03 01:22:17 +00:00
label.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor),
label.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor),
label.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor),
progressView.topAnchor.constraint(equalTo: label.bottomAnchor, constant: .defaultSpacing),
2020-12-17 06:48:06 +00:00
progressView.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor),
progressView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor),
2021-01-03 01:22:17 +00:00
progressView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor)
2020-12-17 06:48:06 +00:00
])
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}