mirror of https://github.com/xaoxuu/ProHUD
优化lazyPush
This commit is contained in:
parent
11d1aeb04d
commit
7e6c87364e
|
@ -70,11 +70,10 @@ public extension Alert {
|
|||
/// - Parameters:
|
||||
/// - identifier: 实例唯一标识符(如果为空,则以代码位置为唯一标识符)
|
||||
/// - handler: 实例创建代码
|
||||
static func lazyPush(identifier: String? = nil, file: String = #file, line: Int = #line, handler: @escaping (_ alert: Alert) -> Void) {
|
||||
static func lazyPush(identifier: String? = nil, file: String = #file, line: Int = #line, handler: @escaping (_ alert: Alert) -> Void, onExists: ((_ alert: Alert) -> Void)? = nil) {
|
||||
let id = identifier ?? (file + "#\(line)")
|
||||
if let vc = AlertWindow.alerts.last(where: { $0.identifier == id }) {
|
||||
handler(vc)
|
||||
vc.reloadData()
|
||||
onExists?(vc)
|
||||
} else {
|
||||
Alert { alert in
|
||||
alert.identifier = id
|
||||
|
|
|
@ -58,14 +58,11 @@ public class ProgressView: UIView {
|
|||
}
|
||||
|
||||
func updateProgress(progress: CGFloat) {
|
||||
if progress <= 1 {
|
||||
// 初始化
|
||||
if progressLayer.superlayer == nil {
|
||||
progressLayer.strokeEnd = 0
|
||||
layer.addSublayer(progressLayer)
|
||||
}
|
||||
progressLayer.strokeEnd = progress
|
||||
}
|
||||
progressLayer.strokeEnd = max(min(progress, 1), 0)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -145,10 +145,12 @@ public extension Sheet {
|
|||
contentStack.addArrangedSubview(lb)
|
||||
if #available(iOS 11.0, *) {
|
||||
let count = contentStack.arrangedSubviews.count
|
||||
if count > 1 {
|
||||
contentStack.setCustomSpacing(config.margin * 3, after: contentStack.arrangedSubviews[count-2])
|
||||
if count > 0 {
|
||||
contentStack.setCustomSpacing(config.margin * 1.5, after: contentStack.arrangedSubviews[count-1])
|
||||
}
|
||||
if count > 1 {
|
||||
contentStack.setCustomSpacing(config.margin * 2, after: contentStack.arrangedSubviews[count-2])
|
||||
}
|
||||
} else {
|
||||
// Fallback on earlier versions
|
||||
}
|
||||
|
|
|
@ -81,16 +81,7 @@ extension Sheet: DefaultLayout {
|
|||
} else {
|
||||
make.top.equalToSuperview().offset(config.padding * 2)
|
||||
}
|
||||
if width < maxWidth {
|
||||
let bottom = screenSafeAreaInsets.bottom
|
||||
if bottom == 0 {
|
||||
make.bottom.equalToSuperview().inset(config.padding * 2)
|
||||
} else {
|
||||
make.bottom.equalToSuperview().inset(bottom - config.padding / 2)
|
||||
}
|
||||
} else {
|
||||
make.bottom.equalToSuperview().inset(config.padding * 2)
|
||||
}
|
||||
if isPortrait {
|
||||
make.left.right.equalToSuperview().inset(config.padding)
|
||||
} else {
|
||||
|
|
|
@ -25,11 +25,10 @@ public extension Sheet {
|
|||
/// - Parameters:
|
||||
/// - identifier: 实例唯一标识符(如果为空,则以代码位置为唯一标识符)
|
||||
/// - handler: 实例创建代码
|
||||
static func lazyPush(identifier: String? = nil, file: String = #file, line: Int = #line, handler: @escaping (_ sheet: Sheet) -> Void) {
|
||||
static func lazyPush(identifier: String? = nil, file: String = #file, line: Int = #line, handler: @escaping (_ sheet: Sheet) -> Void, onExists: ((_ sheet: Sheet) -> Void)? = nil) {
|
||||
let id = identifier ?? (file + "#\(line)")
|
||||
if let vc = find(identifier: id).last {
|
||||
handler(vc)
|
||||
vc.reloadData()
|
||||
onExists?(vc)
|
||||
} else {
|
||||
Sheet { sheet in
|
||||
sheet.identifier = id
|
||||
|
|
|
@ -15,9 +15,14 @@ class SheetWindow: Window {
|
|||
|
||||
init(sheet: Sheet) {
|
||||
self.sheet = sheet
|
||||
super.init(frame: .zero)
|
||||
if #available(iOS 13.0, *) {
|
||||
windowScene = sheet.config.windowScene ?? UIApplication.shared.windows.last?.windowScene
|
||||
if let scene = sheet.config.windowScene ?? UIApplication.shared.windows.last?.windowScene {
|
||||
super.init(windowScene: scene)
|
||||
} else {
|
||||
super.init(frame: UIScreen.main.bounds)
|
||||
}
|
||||
} else {
|
||||
super.init(frame: UIScreen.main.bounds)
|
||||
}
|
||||
sheet.window = self
|
||||
windowLevel = .init(rawValue: UIWindow.Level.alert.rawValue - 2)
|
||||
|
@ -38,7 +43,7 @@ class SheetWindow: Window {
|
|||
window = SheetWindow(sheet: sheet)
|
||||
isNew = true
|
||||
}
|
||||
window.rootViewController = sheet // 此时toast.view.frame.size会自动更新为window.frame.size
|
||||
window.rootViewController = sheet
|
||||
if windows.contains(window) == false {
|
||||
windows.append(window)
|
||||
}
|
||||
|
|
|
@ -25,11 +25,10 @@ public extension Toast {
|
|||
/// - Parameters:
|
||||
/// - identifier: 实例唯一标识符(如果为空,则以代码位置为唯一标识符)
|
||||
/// - handler: 实例创建代码
|
||||
static func lazyPush(identifier: String? = nil, file: String = #file, line: Int = #line, handler: @escaping (_ toast: Toast) -> Void) {
|
||||
static func lazyPush(identifier: String? = nil, file: String = #file, line: Int = #line, handler: @escaping (_ toast: Toast) -> Void, onExists: ((_ toast: Toast) -> Void)? = nil) {
|
||||
let id = identifier ?? (file + "#\(line)")
|
||||
if let vc = find(identifier: id).last {
|
||||
handler(vc)
|
||||
vc.reloadData()
|
||||
onExists?(vc)
|
||||
} else {
|
||||
Toast { toast in
|
||||
toast.identifier = id
|
||||
|
|
Loading…
Reference in New Issue