Skip to content

Commit

Permalink
Merge pull request #107 from square/kve/use-env-in-size-that-fits
Browse files Browse the repository at this point in the history
Fixes to get POS working for 0.12.0
  • Loading branch information
kyleve committed Jun 5, 2020
2 parents 8ed78b8 + a1eddfc commit 51ffde6
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 12 deletions.
11 changes: 9 additions & 2 deletions BlueprintUI/Sources/Blueprint View/BlueprintView.swift
Expand Up @@ -111,7 +111,10 @@ public final class BlueprintView: UIView {
)
}

return element.content.measure(in: measurementConstraint(with: size), environment: .empty)
return element.content.measure(
in: measurementConstraint(with: size),
environment: self.makeEnvironment()
)
}

/// Returns the size of the element bound to the current width (mimicking
Expand All @@ -131,7 +134,11 @@ public final class BlueprintView: UIView {
} else {
constraint = SizeConstraint(width: bounds.width)
}
return element.content.measure(in: constraint, environment: .empty)

return element.content.measure(
in: constraint,
environment: self.makeEnvironment()
)
}

public override var semanticContentAttribute: UISemanticContentAttribute {
Expand Down
4 changes: 1 addition & 3 deletions BlueprintUI/Sources/Layout/Empty.swift
Expand Up @@ -16,9 +16,7 @@ public struct Empty : Element {
public init() {}

public var content: ElementContent {
ElementContent { _ in
.zero
}
ElementContent(intrinsicSize: .zero)
}

public func backingViewDescription(bounds: CGRect, subtreeExtent: CGRect?) -> ViewDescription? {
Expand Down
4 changes: 2 additions & 2 deletions BlueprintUI/Tests/BlueprintViewTests.swift
Expand Up @@ -148,8 +148,8 @@ fileprivate struct MeasurableElement : Element {
var validate : (SizeConstraint) -> CGSize

var content: ElementContent {
ElementContent {
self.validate($0)
ElementContent { constraint -> CGSize in
self.validate(constraint)
}
}

Expand Down
4 changes: 2 additions & 2 deletions BlueprintUI/Tests/ConstrainedSizeTests.swift
Expand Up @@ -323,7 +323,7 @@ class ConstrainedSizeTests: XCTestCase {
fileprivate struct FixedElement: Element {

var content: ElementContent {
return ElementContent { _ in
ElementContent { constraint -> CGSize in
// Using different sizes for width and height in case
// any internal calculations mix up x and y; we'll catch that.

Expand All @@ -340,7 +340,7 @@ fileprivate struct FixedElement: Element {
fileprivate struct FlexibleElement: Element {

var content: ElementContent {
return ElementContent { constraint -> CGSize in
ElementContent { constraint -> CGSize in
let totalArea : CGFloat = 100 * 110

let width : CGFloat
Expand Down
2 changes: 1 addition & 1 deletion BlueprintUI/Tests/StackTests.swift
Expand Up @@ -901,7 +901,7 @@ class StackTests: XCTestCase {
var axis: StackLayout.Axis

var content: ElementContent {
return ElementContent { (constraint) -> CGSize in
ElementContent { constraint -> CGSize in
switch self.axis {
case .horizontal:
let itemsPerLine = max(1, Int(constraint.width.maximum / self.itemSize.width))
Expand Down
2 changes: 1 addition & 1 deletion BlueprintUICommonControls/Sources/TextField.swift
Expand Up @@ -65,7 +65,7 @@ public struct TextField: Element {
}

public var content: ElementContent {
return ElementContent { constraint in
ElementContent { constraint -> CGSize in
return CGSize(
width: max(constraint.maximum.width, 44),
height: 44.0)
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Use default environment when [measuring `BlueprintView`](https://github.com/square/Blueprint/pull/107).

### Added

### Removed
Expand Down
2 changes: 1 addition & 1 deletion SampleApp/Podfile.lock
Expand Up @@ -21,4 +21,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: bef87f42e48bddbf23595cfa6a16f4bf30ae6893

COCOAPODS: 1.9.1
COCOAPODS: 1.9.3

0 comments on commit 51ffde6

Please sign in to comment.