优化lazyPush

This commit is contained in:
xaoxuu 2022-09-19 20:30:08 +08:00
parent 11d1aeb04d
commit 7e6c87364e
7 changed files with 23 additions and 31 deletions

View File

@ -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

View File

@ -58,14 +58,11 @@ public class ProgressView: UIView {
} }
func updateProgress(progress: CGFloat) { func updateProgress(progress: CGFloat) {
if progress <= 1 { if progressLayer.superlayer == nil {
// progressLayer.strokeEnd = 0
if progressLayer.superlayer == nil { layer.addSublayer(progressLayer)
progressLayer.strokeEnd = 0
layer.addSublayer(progressLayer)
}
progressLayer.strokeEnd = progress
} }
progressLayer.strokeEnd = max(min(progress, 1), 0)
} }
} }

View File

@ -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
} }

View File

@ -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 { make.bottom.equalToSuperview().inset(config.padding * 2)
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 { if isPortrait {
make.left.right.equalToSuperview().inset(config.padding) make.left.right.equalToSuperview().inset(config.padding)
} else { } else {

View File

@ -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

View File

@ -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.sizewindow.frame.size window.rootViewController = sheet
if windows.contains(window) == false { if windows.contains(window) == false {
windows.append(window) windows.append(window)
} }

View File

@ -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