Skip to content

Add UIView.later... #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Sources/SwiftUIKit/Extensions/UILabel+SwiftUIKit.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
7 changes: 7 additions & 0 deletions Sources/SwiftUIKit/Extensions/UITextField+SwiftUIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@ public extension UITextField {

return self
}

@discardableResult
func text(_ value: String?) -> Self {
text = value

return self
}
}
7 changes: 7 additions & 0 deletions Sources/SwiftUIKit/Extensions/UITextView+SwiftUIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
87 changes: 87 additions & 0 deletions Sources/SwiftUIKit/Extensions/UIView+Later.swift
Original file line number Diff line number Diff line change
@@ -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>) -> 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>) -> 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>) -> UIView {
let view = UIView()

view.embed(withPadding: padding) {
embeddedLoadingView
}

laterView(Later.self)
.whenSuccess { embeddedView in
Later.main {
view.clear()
.embed {
embeddedView
}
}

}

return view
}
}
15 changes: 11 additions & 4 deletions Sources/SwiftUIKit/Views/Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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?()
}
}
2 changes: 1 addition & 1 deletion Sources/SwiftUIKit/Views/NavButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down