diff --git a/Sources/SwiftUIKit/Extensions/UILabel+SwiftUIKit.swift b/Sources/SwiftUIKit/Extensions/UILabel+SwiftUIKit.swift new file mode 100644 index 0000000..ac1c28a --- /dev/null +++ b/Sources/SwiftUIKit/Extensions/UILabel+SwiftUIKit.swift @@ -0,0 +1,24 @@ +// +// UILabel+SwiftUIKit.swift +// SwiftUIKit +// +// Created by Zach Eriksen on 7/7/20. +// + +import UIKit + +public extension UILabel { + @discardableResult + func text(color: UIColor?) -> Self { + textColor = color + + return self + } + + @discardableResult + func text(_ value: String?) -> Self { + text = value + + return self + } +} diff --git a/Sources/SwiftUIKit/Extensions/UITextField+SwiftUIKit.swift b/Sources/SwiftUIKit/Extensions/UITextField+SwiftUIKit.swift index 06a6043..d458de4 100644 --- a/Sources/SwiftUIKit/Extensions/UITextField+SwiftUIKit.swift +++ b/Sources/SwiftUIKit/Extensions/UITextField+SwiftUIKit.swift @@ -14,4 +14,11 @@ public extension UITextField { return self } + + @discardableResult + func text(_ value: String?) -> Self { + text = value + + return self + } } diff --git a/Sources/SwiftUIKit/Extensions/UITextView+SwiftUIKit.swift b/Sources/SwiftUIKit/Extensions/UITextView+SwiftUIKit.swift index 41f3b14..c788848 100644 --- a/Sources/SwiftUIKit/Extensions/UITextView+SwiftUIKit.swift +++ b/Sources/SwiftUIKit/Extensions/UITextView+SwiftUIKit.swift @@ -15,6 +15,13 @@ public extension UITextView { return self } + @discardableResult + func text(_ value: String?) -> Self { + text = value + + return self + } + @discardableResult func tint(color: UIColor?) -> Self { tintColor = color diff --git a/Sources/SwiftUIKit/Extensions/UIView+Later.swift b/Sources/SwiftUIKit/Extensions/UIView+Later.swift new file mode 100644 index 0000000..9b43ae6 --- /dev/null +++ b/Sources/SwiftUIKit/Extensions/UIView+Later.swift @@ -0,0 +1,87 @@ +// +// UIView+Later.swift +// SwiftUIKit +// +// Created by Zach Eriksen on 8/26/20. +// + +import UIKit +import Later + +@available(iOS 9.0, *) +public extension UIView { + static func later(_ laterView: (Later.Type) -> LaterValue) -> UIView { + let view = UIView() + + view.center { + LoadingView() + .start() + } + + laterView(Later.self) + .whenSuccess { embeddedView in + Later.main { + view.clear() + .embed { + embeddedView + } + } + + } + + return view + } + + static func later(centeredLoadingView: UIView, + withSize size: CGSize? = nil, + _ laterView: (Later.Type) -> LaterValue) -> UIView { + + let view = UIView() + + view.center { + centeredLoadingView + .configure { + if let size = size { + $0.frame(height: Float(size.height), + width: Float(size.width)) + } + } + } + + laterView(Later.self) + .whenSuccess { embeddedView in + Later.main { + view.clear() + .embed { + embeddedView + } + } + + } + + return view + } + + static func later(embeddedLoadingView: UIView, + withPadding padding: Float = 0, + _ laterView: (Later.Type) -> LaterValue) -> UIView { + let view = UIView() + + view.embed(withPadding: padding) { + embeddedLoadingView + } + + laterView(Later.self) + .whenSuccess { embeddedView in + Later.main { + view.clear() + .embed { + embeddedView + } + } + + } + + return view + } +} diff --git a/Sources/SwiftUIKit/Views/Button.swift b/Sources/SwiftUIKit/Views/Button.swift index dba3077..d6ae60f 100644 --- a/Sources/SwiftUIKit/Views/Button.swift +++ b/Sources/SwiftUIKit/Views/Button.swift @@ -9,13 +9,13 @@ import UIKit @available(iOS 9.0, *) public class Button: UIButton { - private var action: () -> Void + private var action: (() -> Void)? public init(_ title: String, titleColor: UIColor? = nil, backgroundColor: UIColor? = nil, forEvent event: UIControl.Event = .touchUpInside, - _ action: @escaping () -> Void) { + _ action: (() -> Void)? = nil) { self.action = action super.init(frame: .zero) @@ -27,7 +27,7 @@ public class Button: UIButton { accessibility(label: title, traits: .button) } - public init(_ action: @escaping () -> Void, + public init(action: (() -> Void)? = nil, forEvent event: UIControl.Event = .touchUpInside, _ closure: () -> UIView) { self.action = action @@ -41,11 +41,18 @@ public class Button: UIButton { self.addTarget(self, action: #selector(handleButtonTap), for: event) } + @discardableResult + public func setAction(_ action: (() -> Void)?) -> Self { + self.action = action + + return self + } + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } @objc private func handleButtonTap() { - action() + action?() } } diff --git a/Sources/SwiftUIKit/Views/NavButton.swift b/Sources/SwiftUIKit/Views/NavButton.swift index 71590c4..67eca07 100644 --- a/Sources/SwiftUIKit/Views/NavButton.swift +++ b/Sources/SwiftUIKit/Views/NavButton.swift @@ -40,7 +40,7 @@ public class NavButton: Button { self.destination = destination self.style = style - super.init({ + super.init(action: { tapHandler?() Navigate.shared.go(destination(), style: style)