Skip to content

Commit

Permalink
Merge pull request #177 from 0xLeif/develop
Browse files Browse the repository at this point in the history
Release 3.0.0
  • Loading branch information
0xLeif authored Mar 17, 2021
2 parents b21d725 + 6a20875 commit 14185d6
Show file tree
Hide file tree
Showing 87 changed files with 3,858 additions and 887 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ jobs:
runs-on: macOS-latest
strategy:
matrix:
destination: ['platform=iOS Simulator,OS=13.1,name=iPhone 8']
xcode: ['/Applications/Xcode_11.6.app/Contents/Developer']
destination: ['platform=iOS Simulator,OS=13.1,name=iPhone 11']
xcode: ['/Applications/Xcode_12.app/Contents/Developer']
steps:
- uses: actions/checkout@v1
# Github Actions' machines do in fact have recent versions of Xcode,
# but you may have to explicitly switch to them. We explicitly want
# to use Xcode 11, so we use xcode-select to switch to it.
- name: Switch to Xcode 11
run: sudo xcode-select --switch /Applications/Xcode_11.6.app
# to use Xcode 12, so we use xcode-select to switch to it.
- name: Switch to Xcode 12
run: sudo xcode-select --switch /Applications/Xcode_12.app
# Since we want to be running our tests from Xcode, we need to
# generate an .xcodeproj file. Luckly, Swift Package Manager has
# build in functionality to do so.
Expand Down
6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ let package = Package(
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/0xLeif/Later", from: "0.3.1")
.package(url: "https://github.com/0xLeif/Observation", from: "0.0.2"),
.package(url: "https://github.com/0xLeif/DataObject", from: "0.2.1")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "SwiftUIKit",
dependencies: [
"Later"
"Observation",
"DataObject"
]),
.testTarget(
name: "SwiftUIKitTests",
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

UIKit code that is fun to write.

## [Documentation](documentation/Home.md) (WIP)


## Example Code
```Swift
import UIKit
Expand Down Expand Up @@ -38,7 +41,7 @@ class ViewController: UIViewController {

Spacer(),

Field(value: "SwiftUIKit",
TextField(value: "SwiftUIKit",
placeholder: "Some Name",
keyboardType: .default)
.inputHandler { print("New Name: \($0)") }
Expand Down
6 changes: 4 additions & 2 deletions Sources/SwiftUIKit/Containers/HScroll.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import UIKit
@available(iOS 9.0, *)
public class HScroll: UIView {

public init(withPadding padding: Float = 0,
_ closure: () -> UIView) {
public init(
withPadding padding: Float = 0,
_ closure: () -> UIView
) {
super.init(frame: .zero)

let scrollableView = closure()
Expand Down
26 changes: 15 additions & 11 deletions Sources/SwiftUIKit/Containers/HStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ public class HStack: UIView {
/// - alignment: The layout of arranged views perpendicular to the stack view’s axis (source: UIStackView.Alignment)
/// - distribution: The layout that defines the size and position of the arranged views along the stack view’s axis (source: UIStackView.Distribution)
/// - closure: A trailing closure that accepts an array of views
public init(withSpacing spacing: Float = 0,
padding: Float = 0,
alignment: UIStackView.Alignment = .fill,
distribution: UIStackView.Distribution = .fill,
_ closure: () -> [UIView]) {
public init(
withSpacing spacing: Float = 0,
padding: Float = 0,
alignment: UIStackView.Alignment = .fill,
distribution: UIStackView.Distribution = .fill,
_ closure: () -> [UIView]
) {
self.spacing = spacing
self.padding = padding
self.alignment = alignment
Expand All @@ -45,11 +47,13 @@ public class HStack: UIView {
/// - alignment: The layout of arranged views perpendicular to the stack view’s axis (source: UIStackView.Alignment)
/// - distribution: The layout that defines the size and position of the arranged views along the stack view’s axis (source: UIStackView.Distribution)
/// - closure: A trailing closure that accepts an array of optional views
public init(withSpacing spacing: Float = 0,
padding: Float = 0,
alignment: UIStackView.Alignment = .fill,
distribution: UIStackView.Distribution = .fill,
_ closure: () -> [UIView?]) {
public init(
withSpacing spacing: Float = 0,
padding: Float = 0,
alignment: UIStackView.Alignment = .fill,
distribution: UIStackView.Distribution = .fill,
_ closure: () -> [UIView?]
) {
self.spacing = spacing
self.padding = padding
self.alignment = alignment
Expand All @@ -70,7 +74,7 @@ public class HStack: UIView {
padding: padding,
alignment: alignment,
distribution: distribution)
{ views }
{ views }
}

public func update(views closure: (inout [UIView]) -> Void) -> Self {
Expand Down
6 changes: 4 additions & 2 deletions Sources/SwiftUIKit/Containers/VScroll.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import UIKit
@available(iOS 9.0, *)
public class VScroll: UIView {

public init(withPadding padding: Float = 0,
_ closure: () -> UIView) {
public init(
withPadding padding: Float = 0,
_ closure: () -> UIView
) {
super.init(frame: .zero)

let scrollableView = closure()
Expand Down
27 changes: 15 additions & 12 deletions Sources/SwiftUIKit/Containers/VStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import UIKit
import Later

/// Vertical StackView
@available(iOS 9.0, *)
Expand All @@ -25,11 +24,13 @@ public class VStack: UIView {
/// - alignment: The layout of arranged views perpendicular to the stack view’s axis (source: UIStackView.Alignment)
/// - distribution: The layout that defines the size and position of the arranged views along the stack view’s axis (source: UIStackView.Distribution)
/// - closure: A trailing closure that accepts an array of views
public init(withSpacing spacing: Float = 0,
padding: Float = 0,
alignment: UIStackView.Alignment = .fill,
distribution: UIStackView.Distribution = .fill,
_ closure: () -> [UIView]) {
public init(
withSpacing spacing: Float = 0,
padding: Float = 0,
alignment: UIStackView.Alignment = .fill,
distribution: UIStackView.Distribution = .fill,
_ closure: () -> [UIView]
) {
self.spacing = spacing
self.padding = padding
self.alignment = alignment
Expand All @@ -46,11 +47,13 @@ public class VStack: UIView {
/// - alignment: The layout of arranged views perpendicular to the stack view’s axis (source: UIStackView.Alignment)
/// - distribution: The layout that defines the size and position of the arranged views along the stack view’s axis (source: UIStackView.Distribution)
/// - closure: A trailing closure that accepts an array of optional views
public init(withSpacing spacing: Float = 0,
padding: Float = 0,
alignment: UIStackView.Alignment = .fill,
distribution: UIStackView.Distribution = .fill,
_ closure: () -> [UIView?]) {
public init(
withSpacing spacing: Float = 0,
padding: Float = 0,
alignment: UIStackView.Alignment = .fill,
distribution: UIStackView.Distribution = .fill,
_ closure: () -> [UIView?]
) {
self.spacing = spacing
self.padding = padding
self.alignment = alignment
Expand All @@ -71,7 +74,7 @@ public class VStack: UIView {
padding: padding,
alignment: alignment,
distribution: distribution)
{ views }
{ views }
}

@discardableResult
Expand Down
14 changes: 14 additions & 0 deletions Sources/SwiftUIKit/Extensions/NSLayoutConstraint+SwiftUIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,18 @@ public extension UIView {
constraint.isConnected(toAnchor: bottomAnchor)
}
}

/// The height constraints held by the view
var heightConstraints: [NSLayoutConstraint] {
constraints.filter { (constraint) -> Bool in
constraint.isConnected(toAnchor: heightAnchor)
}
}

/// The width constraints held by the view
var widthConstraints: [NSLayoutConstraint] {
constraints.filter { (constraint) -> Bool in
constraint.isConnected(toAnchor: widthAnchor)
}
}
}
21 changes: 0 additions & 21 deletions Sources/SwiftUIKit/Extensions/NSObjectProtocol+SwiftUIKit.swift

This file was deleted.

8 changes: 8 additions & 0 deletions Sources/SwiftUIKit/Extensions/SwiftFu+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// SwiftFu+.swift
//
//
// Created by Leif on 3/16/21.
//

import SwiftFu
12 changes: 7 additions & 5 deletions Sources/SwiftUIKit/Extensions/UIAppearance+SwiftUIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
//

import UIKit
import Later

@available(iOS 9.0, *)
public extension UIAppearance where Self: UIView {
func contract<Value>(_ closure: (Self) -> Contract<Value>) -> ContractView<Self, Value> {
ContractView(view: self) { view in
closure(view)
}
func observed<Value>(
initialValue: Value,
onChangeHandler: @escaping (_ newValue: Value?, _ view: Self) -> Void
) -> ObservedView<Self, Value> {
ObservedView(view: self,
initialValue: initialValue,
onChangeHandler: onChangeHandler)
}
}
114 changes: 114 additions & 0 deletions Sources/SwiftUIKit/Extensions/UIView+Chain.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
//
// UIView+Chain.swift
// SwiftUIKit
//
// Created by Zach Eriksen on 8/26/20.
//

import E
import UIKit
import Chain

@available(iOS 9.0, *)
private extension UIView {
static func chain(
link: Chain,
update: @escaping (UIView) -> Void,
shouldBackground: Bool = false,
centeredLoadingView: UIView? = nil,
embeddedLoadingView: UIView? = nil
) -> UIView {
let view = UIView()

if let embeddedLoadingView = embeddedLoadingView {
view.embed {
embeddedLoadingView
}
} else {
view.center {
centeredLoadingView ?? LoadingView().start()
}
}

let chainEnd: Chain = .complete(
.void {
update(view)
}
)

var output = Variable.void

if shouldBackground {
output = Chain.background(
.out {
link.run()
},
chainEnd
)
.run()
} else {
output = Chain.link(
.out {
link.run()
},
chainEnd
)
.run()
}

print("\(#function): \(output)")

return view
}
}

@available(iOS 9.0, *)
public extension UIView {
static func chain(
link: Chain,
update: @escaping (UIView) -> Void,
centeredLoadingView: UIView? = nil
) -> UIView {
chain(link: link,
update: update,
shouldBackground: false,
centeredLoadingView: centeredLoadingView,
embeddedLoadingView: nil)
}

static func chain(
link: Chain,
update: @escaping (UIView) -> Void,
embeddedLoadingView: UIView
) -> UIView {
chain(link: link,
update: update,
shouldBackground: false,
centeredLoadingView: nil,
embeddedLoadingView: embeddedLoadingView)
}

static func background(
link: Chain,
update: @escaping (UIView) -> Void,
centeredLoadingView: UIView? = nil
) -> UIView {
chain(link: link,
update: update,
shouldBackground: true,
centeredLoadingView: centeredLoadingView,
embeddedLoadingView: nil)
}

static func background(
link: Chain,
update: @escaping (UIView) -> Void,
embeddedLoadingView: UIView
) -> UIView {
chain(link: link,
update: update,
shouldBackground: true,
centeredLoadingView: nil,
embeddedLoadingView: embeddedLoadingView)
}
}
Loading

0 comments on commit 14185d6

Please sign in to comment.