ProHUD/Source/HUDConfig.swift

101 lines
2.9 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

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.

//
// HUDConfig.swift
// ProHUD
//
// Created by xaoxuu on 2019/7/29.
// Copyright © 2019 Titan Studio. All rights reserved.
//
import UIKit
public extension ProHUD {
struct Configuration {
/// Debug
public var enableDebugPrint = true
///
public var rootViewController: UIViewController?
/// iOS13
public lazy var dynamicColor: UIColor = {
// if #available(iOS 13.0, *) {
// let color = UIColor { (traitCollection: UITraitCollection) -> UIColor in
// if traitCollection.userInterfaceStyle == .dark {
// return .init(white: 1, alpha: 1)
// } else {
// return .init(white: 0.1, alpha: 1)
// }
// }
// return color
// } else {
// // Fallback on earlier versions
// }
return .init(white: 0.1, alpha: 1)
}()
///
public lazy var primaryLabelColor: UIColor = {
return dynamicColor.withAlphaComponent(0.8)
}()
///
public lazy var secondaryLabelColor: UIColor = {
return dynamicColor.withAlphaComponent(0.66)
}()
public func blurView(_ callback: @escaping () -> UIVisualEffectView) {
createBlurView = callback
}
public var toast = Toast()
public var alert = Alert()
public var `guard` = Guard()
/// Toast
/// - Parameter callback:
public mutating func toast(_ callback: @escaping (inout Toast) -> Void) {
callback(&toast)
}
/// Alert
/// - Parameter callback:
public mutating func alert(_ callback: @escaping (inout Alert) -> Void) {
callback(&alert)
}
/// Guard
/// - Parameter callback:
public mutating func `guard`(_ callback: @escaping (inout Guard) -> Void) {
callback(&`guard`)
}
}
}
///
internal var cfg = ProHUD.Configuration()
public extension ProHUD {
static func config(_ config: (inout Configuration) -> Void) {
config(&cfg)
}
}
internal var createBlurView: () -> UIVisualEffectView = {
return {
let vev = UIVisualEffectView()
if #available(iOS 13.0, *) {
// vev.effect = UIBlurEffect(style: .systemMaterial)
vev.effect = UIBlurEffect(style: .extraLight)
} else if #available(iOS 11.0, *) {
vev.effect = UIBlurEffect(style: .extraLight)
} else {
vev.effect = .none
vev.backgroundColor = .white
}
return vev
}
}()