Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleve committed May 6, 2020
1 parent ecb5dae commit be14258
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 16 deletions.
6 changes: 5 additions & 1 deletion BlueprintUI/Sources/Layout/Aligned.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ public extension Element {
/// - vertically: The vertical alignment. Defaults to `.centered`.
/// - horizontally: The horizontal alignment. Defaults to `.centered`.
///
func aligned(vertically: Aligned.VerticalAlignment = .center, horizontally: Aligned.HorizontalAlignment = .center) -> Aligned {
func aligned(
vertically: Aligned.VerticalAlignment,
horizontally: Aligned.HorizontalAlignment
) -> Aligned
{
Aligned(
vertically: vertically,
horizontally: horizontally,
Expand Down
11 changes: 8 additions & 3 deletions BlueprintUI/Sources/Layout/ConstrainedAspectRatio.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,20 @@ public struct ConstrainedAspectRatio: Element {
}


public extension ConstrainedAspectRatio {
/// Initializes with the given properties.
public extension Element {
///
/// Constrains the element to the provided aspect ratio.
///
/// - parameters:
/// - aspectRatio: The aspect ratio that the content size should match.
/// - contentMode: Whether the aspect ratio should be reached by expanding the content
/// element's size to fill its parent or shrinking it to fit.
///
func aspectRatio(with aspectRatio: AspectRatio, contentMode: ContentMode = .fill) -> ConstrainedAspectRatio {
func constrainedTo(
aspectRatio: AspectRatio,
contentMode: ConstrainedAspectRatio.ContentMode = .fill
) -> ConstrainedAspectRatio
{
ConstrainedAspectRatio(aspectRatio: aspectRatio, contentMode: contentMode, wrapping: self)
}
}
2 changes: 1 addition & 1 deletion BlueprintUI/Sources/Layout/ConstrainedSize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extension ConstrainedSize {

public extension Element {

/// Constrains the measured size of the content element.
/// Constrains the measured size of the element to the provided width and height.
func constrainedTo(
width: ConstrainedSize.Constraint = .unconstrained,
height: ConstrainedSize.Constraint = .unconstrained
Expand Down
30 changes: 26 additions & 4 deletions BlueprintUI/Sources/Layout/Inset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,20 @@ public struct Inset: Element {
public extension Element {

/// Insets the element by the given amount on each side.
func inset(top: CGFloat = 0.0, bottom: CGFloat = 0.0, left: CGFloat = 0.0, right: CGFloat = 0.0) -> Inset {
Inset(top: top, bottom: bottom, left: left, right: right, wrapping: self)
func inset(
top: CGFloat = 0.0,
bottom: CGFloat = 0.0,
left: CGFloat = 0.0,
right: CGFloat = 0.0
) -> Inset
{
Inset(
top: top,
bottom: bottom,
left: left,
right: right,
wrapping: self
)
}

/// Insets the element by the given amount on each side.
Expand All @@ -94,8 +106,18 @@ public extension Element {
}

/// Insets the element by the given amount on each side.
func inset(horizontal : CGFloat = 0.0, vertical : CGFloat = 0.0) -> Inset {
Inset(top: vertical, bottom: vertical, left: horizontal, right: horizontal, wrapping: self)
func inset(
horizontal : CGFloat = 0.0,
vertical : CGFloat = 0.0
) -> Inset
{
Inset(
top: vertical,
bottom: vertical,
left: horizontal,
right: horizontal,
wrapping: self
)
}
}

Expand Down
13 changes: 13 additions & 0 deletions BlueprintUICommonControls/Sources/AccessibilityBlocker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ import BlueprintUI
import UIKit


/// Blocks all accessibility on the element, so that it is
/// is no longer an accessibility element, and its children are
/// hidden from the accessibility system.
public struct AccessibilityBlocker: Element {

public var wrapped: Element

/// Creates a new `AccessibilityBlocker` wrapping the provided element.
public init(wrapping element: Element) {
self.wrapped = element
}

//
// MARK: Element
//

public var content: ElementContent {
return ElementContent(child: wrapped)
Expand All @@ -22,7 +30,12 @@ public struct AccessibilityBlocker: Element {
}
}


public extension Element {

/// Blocks all accessibility on the element, so that it is
/// is no longer an accessibility element, and its children are
/// hidden from the accessibility system.
func blockAccessibility() -> AccessibilityBlocker {
AccessibilityBlocker(wrapping: self)
}
Expand Down
7 changes: 5 additions & 2 deletions BlueprintUICommonControls/Sources/AccessibilityElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,16 @@ public struct AccessibilityElement: Element {
}


public extension AccessibilityElement {
public extension Element {

/// Wraps the element to provide the passed accessibility
/// options to the accessibility system.
func accessibility(
label: String? = nil,
value: String? = nil,
hint: String? = nil,
identifier: String? = nil,
traits: Set<Trait> = []
traits: Set<AccessibilityElement.Trait> = []
) -> AccessibilityElement
{
AccessibilityElement(
Expand Down
2 changes: 1 addition & 1 deletion BlueprintUICommonControls/Sources/Box.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ extension Box {

public extension Element {

/// Wraps the given element in a box to provide basic styling.
/// Wraps the element in a box to provide basic styling.
func box(
background: UIColor = .clear,
corners: Box.CornerStyle = .square,
Expand Down
3 changes: 3 additions & 0 deletions BlueprintUICommonControls/Sources/ScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public struct ScrollView: Element {
}

public extension Element {

/// Wraps the element in a `ScrollView` to allow it to be scrolled
/// if it takes up more space then is available on screen.
func scrollable(
_ contentSize: ScrollView.ContentSize = .fittingHeight,
configure : (inout ScrollView) -> () = { _ in }
Expand Down
13 changes: 11 additions & 2 deletions BlueprintUICommonControls/Sources/Tappable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import UIKit
public struct Tappable: Element {

public var wrappedElement: Element
public var onTap: ()->Void
public var onTap: () -> Void

public init(onTap: @escaping ()->Void, wrapping element: Element) {
public init(onTap: @escaping () -> Void, wrapping element: Element) {
self.wrappedElement = element
self.onTap = onTap
}
Expand All @@ -26,6 +26,15 @@ public struct Tappable: Element {
}


public extension Element {

/// Wraps the element and calls the provided closure when tapped.
func tappable(onTap: @escaping () -> Void) -> Tappable {
Tappable(onTap: onTap, wrapping: self)
}
}


fileprivate final class TappableView: UIView {

var onTap: (()->Void)? = nil
Expand Down
35 changes: 34 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,39 @@

### Added

- [Added support](https://github.com/square/Blueprint/pull/88) for `SwiftUI`-style element building within `BlueprintUI` and `BlueprintUICommonControls`.

This allows you to replace this code:

```
ScrollView(.fittingHeight) (
wrapping: Box(
backgroundColor .lightGrey,
wrapping: Inset(
uniformInset: 10.0,
wrapping: ConstrainedSize(
height: .atLeast(20.0),
wrapping: Label(
text: "Hello, world!"
)
)
)
)
)
```

With this code:

```
Label(text: "Hello, World!")
.constrainedTo(height: .atLeast(20.0))
.inset(by: 20.0)
.box(background: .lightGrey)
.scrollable(.fittingHeight)
```

Improving readability and conciseness of your elements.

### Removed

### Changed
Expand All @@ -24,7 +57,7 @@

### Fixed

- Only support `SwiftUI` previews on 32 bit ARM devices.
- [Don't try to build](https://github.com/square/Blueprint/pull/89) `SwiftUI` previews on 32 bit ARM devices – `SwiftUI` does not exist on these devices.

## 0.9.1

Expand Down
2 changes: 1 addition & 1 deletion SampleApp/Sources/XcodePreviewDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct TestElement : ProxyElement {
$0.verticalUnderflow = .justifyToStart

for index in 1...12 {
$0.add(growPriority: 0.0, shrinkPriority: 00, child: Label(text: "Hello, World") {
$0.add(child: Label(text: "Hello, World") {
$0.font = .boldSystemFont(ofSize: 10.0 + CGFloat(index * 4))
$0.color = .init(
red: CGFloat.random(in: 0...1),
Expand Down

0 comments on commit be14258

Please sign in to comment.