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