优化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:
/// - 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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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