1
0
Fork 0
mirror of https://github.com/metabolist/metatext.git synced 2024-12-23 22:10:29 +00:00
metatext/Views/WebfingerIndicatorView.swift
Justin Mazzocchi eab12976cd
Webfingering
2020-09-25 23:37:30 -07:00

61 lines
1.8 KiB
Swift

// Copyright © 2020 Metabolist. All rights reserved.
import UIKit
class WebfingerIndicatorView: UIVisualEffectView {
private let activityIndicatorView = UIActivityIndicatorView()
init() {
super.init(effect: nil)
clipsToBounds = true
layer.cornerRadius = 8
contentView.addSubview(activityIndicatorView)
activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false
activityIndicatorView.style = .large
NSLayoutConstraint.activate([
trailingAnchor.constraint(
equalTo: activityIndicatorView.trailingAnchor, constant: 8),
bottomAnchor.constraint(
equalTo: activityIndicatorView.bottomAnchor, constant: 8),
activityIndicatorView.topAnchor.constraint(
equalTo: topAnchor, constant: 8),
activityIndicatorView.leadingAnchor.constraint(
equalTo: leadingAnchor, constant: 8),
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()
UIView.animate(withDuration: 0.5) {
self.effect = UIBlurEffect(style: .systemUltraThinMaterial)
}
}
func stopAnimating() {
activityIndicatorView.stopAnimating()
UIView.animate(withDuration: 0.5) {
self.effect = nil
} completion: { _ in
self.isHidden = true
}
}
}