Skip to content

Commit

Permalink
Merge pull request #1 from KazaiMazai/API-improvements
Browse files Browse the repository at this point in the history
API-improvements
  • Loading branch information
KazaiMazai authored Apr 21, 2022
2 parents 88a0f96 + e384e26 commit af9a22b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 90 deletions.
74 changes: 0 additions & 74 deletions Sources/SwiftyUIKit/DisclosureView.swift

This file was deleted.

9 changes: 7 additions & 2 deletions Sources/SwiftyUIKit/HStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@

import UIKit

extension HStackView {
public convenience init(spacing: CGFloat = 0, @ViewContentBuilder content: () -> [UIView]) {
public extension HStackView {
convenience init(spacing: CGFloat = 0, @ViewContentBuilder content: () -> [UIView]) {
self.init(spacing: spacing, content: content())
}

convenience init(spacing: CGFloat = 0, @OptionalViewContentBuilder optionalContent: () -> [UIView]) {
self.init(spacing: spacing, content: optionalContent())
}

}

public final class HStackView: UIView {
Expand Down
12 changes: 2 additions & 10 deletions Sources/SwiftyUIKit/UIView+Padding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,12 @@ public extension UIView {
bottomConstant: bottom)
}

func padding(vertical: CGFloat = 0) -> UIView {
func padding(vertical: CGFloat = 0, horizontal: CGFloat = 0) -> UIView {
PaddingViewDecorator(decorated: self,
topConstant: vertical,
leftConstant: 0,
rightConstant: 0,
bottomConstant: vertical)
}

func padding(horizontal: CGFloat = 0) -> UIView {
PaddingViewDecorator(decorated: self,
topConstant: 0,
leftConstant: horizontal,
rightConstant: horizontal,
bottomConstant: 0)
bottomConstant: vertical)
}
}

Expand Down
8 changes: 6 additions & 2 deletions Sources/SwiftyUIKit/VStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@

import UIKit

extension VStackView {
public convenience init(spacing: CGFloat = 0, @ViewContentBuilder content: () -> [UIView]) {
public extension VStackView {
convenience init(spacing: CGFloat = 0, @ViewContentBuilder content: () -> [UIView]) {
self.init(spacing: spacing, content: content())
}

convenience init(spacing: CGFloat = 0, @OptionalViewContentBuilder optionalContent: () -> [UIView]) {
self.init(spacing: spacing, content: optionalContent())
}
}

public final class VStackView: UIView {
Expand Down
7 changes: 7 additions & 0 deletions Sources/SwiftyUIKit/ViewContentBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ public struct ViewContentBuilder {
subviews
}
}

@resultBuilder
public struct OptionalViewContentBuilder {
public static func buildBlock(_ subviews: UIView?...) -> [UIView] {
subviews.compactMap { $0 }
}
}
8 changes: 6 additions & 2 deletions Sources/SwiftyUIKit/ZStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@

import UIKit

extension ZStackView {
public convenience init(alignment: Alignment = .all, @ViewContentBuilder content: () -> [UIView]) {
public extension ZStackView {
convenience init(alignment: Alignment = .all, @ViewContentBuilder content: () -> [UIView]) {
self.init(alignment: alignment, content: content())
}

convenience init(alignment: Alignment = .all, @OptionalViewContentBuilder optionalContent: () -> [UIView]) {
self.init(alignment: alignment, content: optionalContent())
}
}

public final class ZStackView: UIView {
Expand Down

0 comments on commit af9a22b

Please sign in to comment.