metatext-app-ios-iphone-ipad/Views/WebfingerIndicatorView.swift

62 lines
1.9 KiB
Swift
Raw Normal View History

2020-09-26 08:37:30 +02:00
// Copyright © 2020 Metabolist. All rights reserved.
import UIKit
2020-11-09 07:22:20 +01:00
final class WebfingerIndicatorView: UIVisualEffectView {
2020-09-26 08:37:30 +02:00
private let activityIndicatorView = UIActivityIndicatorView()
init() {
super.init(effect: nil)
clipsToBounds = true
2020-09-29 03:32:28 +02:00
layer.cornerRadius = .defaultCornerRadius
2020-09-26 08:37:30 +02:00
contentView.addSubview(activityIndicatorView)
activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false
activityIndicatorView.style = .large
NSLayoutConstraint.activate([
trailingAnchor.constraint(
2020-09-29 03:32:28 +02:00
equalTo: activityIndicatorView.trailingAnchor, constant: .defaultSpacing),
2020-09-26 08:37:30 +02:00
bottomAnchor.constraint(
2020-09-29 03:32:28 +02:00
equalTo: activityIndicatorView.bottomAnchor, constant: .defaultSpacing),
2020-09-26 08:37:30 +02:00
activityIndicatorView.topAnchor.constraint(
2020-09-29 03:32:28 +02:00
equalTo: topAnchor, constant: .defaultSpacing),
2020-09-26 08:37:30 +02:00
activityIndicatorView.leadingAnchor.constraint(
2020-09-29 03:32:28 +02:00
equalTo: leadingAnchor, constant: .defaultSpacing),
2020-09-26 08:37:30 +02: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 03:32:28 +02:00
UIView.animate(withDuration: .defaultAnimationDuration) {
self.effect = UIBlurEffect(style: .systemChromeMaterial)
2020-09-26 08:37:30 +02:00
}
}
func stopAnimating() {
activityIndicatorView.stopAnimating()
2020-09-29 03:32:28 +02:00
UIView.animate(withDuration: .defaultAnimationDuration) {
2020-09-26 08:37:30 +02:00
self.effect = nil
} completion: { _ in
self.isHidden = true
}
}
}