Visual_Novel_iOS/crush/Crush/Src/Components/UI/Hud/Hud.swift

75 lines
2.3 KiB
Swift
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Hud.swift
// Crush
//
// Created by Leon on 2025/7/13.
//
import Foundation
import UIKit
/// View使(eg: IAPCore)使Hud.showIndicator() and view.hideToastActivity
class Hud {
static let shared = Hud()
static func showIndicator(_ blockUserTap: Bool? = true) {
DispatchQueue.main.async {
if let view = UIWindow.key {
view.makeToastActivity(.center, blockUserInteraction: blockUserTap ?? true)
} else if let view = UIWindow.getTopViewController()?.view {
view.makeToastActivity(.center, blockUserInteraction: blockUserTap ?? true)
}
}
}
///
/// - Parameter blockUserInteraction: false
// static func showIndicator(blockUserInteraction: Bool = true) {
// DispatchQueue.main.async {
// if let view = UIWindow.key {
// view.makeToastActivity(.center, blockUserInteraction: blockUserInteraction)
// } else if let view = UIWindow.getTopViewController()?.view {
// view.makeToastActivity(.center, blockUserInteraction: blockUserInteraction)
// }
// }
// }
static func hideIndicator() {
DispatchQueue.main.async {
if let view = UIWindow.key {
view.hideToastActivity()
} else if let view = UIWindow.getTopViewController()?.view {
view.hideToastActivity()
}
}
}
static func toast(str: String?, completion: ((Bool)-> Void)? = nil) {
DispatchQueue.main.async {
guard let toast = str, let view = UIWindow.applicationKey else {
return
}
view.makeToast(toast, completion: completion)
}
}
static func hideToast(){
DispatchQueue.main.async {
guard let view = UIWindow.applicationKey else {
return
}
view.hideToast()
}
}
static func comingsoon(){
Hud.toast(str: "Comming soon...")
}
required init() {
//ToastManager.shared.duration = 1.0
ToastManager.shared.isQueueEnabled
}
}