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:
@ -9,9 +9,6 @@ import UIKit
|
||||
/// 业务 ViewController 基类,提供统一的 UI 搭建流程与通用 UI 能力。
|
||||
class BaseViewController: UIViewController {
|
||||
|
||||
private var loadingOverlay: UIView?
|
||||
private var loadingIndicator: UIActivityIndicatorView?
|
||||
|
||||
// MARK: - Lifecycle
|
||||
|
||||
override func viewDidLoad() {
|
||||
@ -47,36 +44,14 @@ class BaseViewController: UIViewController {
|
||||
|
||||
// MARK: - Loading
|
||||
|
||||
@MainActor
|
||||
func showLoading() {
|
||||
if loadingOverlay == nil {
|
||||
let overlay = UIView()
|
||||
overlay.backgroundColor = UIColor.black.withAlphaComponent(0.1)
|
||||
|
||||
let indicator = UIActivityIndicatorView(style: .large)
|
||||
indicator.hidesWhenStopped = true
|
||||
|
||||
view.addSubview(overlay)
|
||||
overlay.addSubview(indicator)
|
||||
|
||||
overlay.snp.makeConstraints { make in
|
||||
make.edges.equalToSuperview()
|
||||
}
|
||||
indicator.snp.makeConstraints { make in
|
||||
make.center.equalToSuperview()
|
||||
}
|
||||
|
||||
loadingOverlay = overlay
|
||||
loadingIndicator = indicator
|
||||
}
|
||||
|
||||
loadingOverlay?.isHidden = false
|
||||
loadingIndicator?.startAnimating()
|
||||
view.bringSubviewToFront(loadingOverlay!)
|
||||
GlobalLoadingManager.shared.show()
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func hideLoading() {
|
||||
loadingIndicator?.stopAnimating()
|
||||
loadingOverlay?.isHidden = true
|
||||
GlobalLoadingManager.shared.hide()
|
||||
}
|
||||
|
||||
// MARK: - Toast / Alert
|
||||
@ -156,7 +131,7 @@ class BaseViewController: UIViewController {
|
||||
}
|
||||
|
||||
@objc private func handleSessionDidExpireNotification() {
|
||||
hideLoading()
|
||||
GlobalLoadingManager.shared.hideAll()
|
||||
onSessionDidExpire()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user