Add Lottie global loading overlay and fix stuck loading states.
Replace per-VC activity indicators with a ref-counted GlobalLoadingManager, and resolve duplicate show/hide calls on Profile, Statistics, and Home tabs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
53
suixinkan/UI/Loading/GlobalLoadingOverlayView.swift
Normal file
53
suixinkan/UI/Loading/GlobalLoadingOverlayView.swift
Normal file
@ -0,0 +1,53 @@
|
||||
//
|
||||
// GlobalLoadingOverlayView.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 全局 Loading 遮罩,对齐 Android `LoadingScrim` 样式。
|
||||
final class GlobalLoadingOverlayView: UIView {
|
||||
|
||||
private let cardView = UIView()
|
||||
private let loadingView = LottieLoadingView()
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
backgroundColor = UIColor.black.withAlphaComponent(0.2)
|
||||
isUserInteractionEnabled = true
|
||||
|
||||
cardView.backgroundColor = .white
|
||||
cardView.layer.cornerRadius = 15
|
||||
cardView.clipsToBounds = true
|
||||
|
||||
addSubview(cardView)
|
||||
cardView.addSubview(loadingView)
|
||||
|
||||
cardView.snp.makeConstraints { make in
|
||||
make.center.equalToSuperview()
|
||||
make.width.height.equalTo(100)
|
||||
}
|
||||
loadingView.snp.makeConstraints { make in
|
||||
make.center.equalToSuperview()
|
||||
make.width.height.equalTo(80)
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
/// 显示并开始动画。
|
||||
func present() {
|
||||
isHidden = false
|
||||
loadingView.startAnimating()
|
||||
}
|
||||
|
||||
/// 隐藏并停止动画。
|
||||
func dismiss() {
|
||||
loadingView.stopAnimating()
|
||||
isHidden = true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user