metatext/Views/WebfingerIndicatorView.swift

62 lines
1.9 KiB
Swift
Raw Normal View History

2020-09-26 06:37:30 +00:00
// Copyright © 2020 Metabolist. All rights reserved.
import UIKit
2020-11-09 06:22:20 +00:00
final class WebfingerIndicatorView: UIVisualEffectView {
2020-09-26 06:37:30 +00:00
private let activityIndicatorView = UIActivityIndicatorView()
init() {
super.init(effect: nil)
clipsToBounds = true
2020-09-29 01:32:28 +00:00
layer.cornerRadius = .defaultCornerRadius
2020-09-26 06:37:30 +00:00
contentView.addSubview(activityIndicatorView)
activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false
activityIndicatorView.style = .large
NSLayoutConstraint.activate([
trailingAnchor.constraint(
2020-09-29 01:32:28 +00:00
equalTo: activityIndicatorView.trailingAnchor, constant: .defaultSpacing),
2020-09-26 06:37:30 +00:00
bottomAnchor.constraint(
2020-09-29 01:32:28 +00:00
equalTo: activityIndicatorView.bottomAnchor, constant: .defaultSpacing),
2020-09-26 06:37:30 +00:00
activityIndicatorView.topAnchor.constraint(
2020-09-29 01:32:28 +00:00
equalTo: topAnchor, constant: .defaultSpacing),
2020-09-26 06:37:30 +00:00
activityIndicatorView.leadingAnchor.constraint(
2020-09-29 01:32:28 +00:00
equalTo: leadingAnchor, constant: .defaultSpacing),
2020-09-26 06:37:30 +00:00
activityIndicatorView.centerXAnchor.constraint(
equalTo: contentView.safeAreaLayoutGuide.centerXAnchor),
activityIndicatorView.centerYAnchor.constraint(
equalTo: contentView.safeAreaLayoutGuide.centerYAnchor)
])
isHidden = true
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension WebfingerIndicatorView {
func startAnimating() {
isHidden = false
activityIndicatorView.startAnimating()
2020-09-29 01:32:28 +00:00
UIView.animate(withDuration: .defaultAnimationDuration) {
self.effect = UIBlurEffect(style: .systemChromeMaterial)
2020-09-26 06:37:30 +00:00
}
}
func stopAnimating() {
activityIndicatorView.stopAnimating()
2020-09-29 01:32:28 +00:00
UIView.animate(withDuration: .defaultAnimationDuration) {
2020-09-26 06:37:30 +00:00
self.effect = nil
} completion: { _ in
self.isHidden = true
}
}
}