diff --git a/BlueprintUI/Sources/Blueprint View/BlueprintView.swift b/BlueprintUI/Sources/Blueprint View/BlueprintView.swift index df87e65af..bf1bd1f0d 100755 --- a/BlueprintUI/Sources/Blueprint View/BlueprintView.swift +++ b/BlueprintUI/Sources/Blueprint View/BlueprintView.swift @@ -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 @@ -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 { diff --git a/BlueprintUI/Sources/Layout/Empty.swift b/BlueprintUI/Sources/Layout/Empty.swift index 8099e9fc1..5c57023fa 100644 --- a/BlueprintUI/Sources/Layout/Empty.swift +++ b/BlueprintUI/Sources/Layout/Empty.swift @@ -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? { diff --git a/BlueprintUI/Tests/BlueprintViewTests.swift b/BlueprintUI/Tests/BlueprintViewTests.swift index 318aca579..6b6832c56 100755 --- a/BlueprintUI/Tests/BlueprintViewTests.swift +++ b/BlueprintUI/Tests/BlueprintViewTests.swift @@ -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) } } diff --git a/BlueprintUI/Tests/ConstrainedSizeTests.swift b/BlueprintUI/Tests/ConstrainedSizeTests.swift index bf1444795..fe7edde4c 100644 --- a/BlueprintUI/Tests/ConstrainedSizeTests.swift +++ b/BlueprintUI/Tests/ConstrainedSizeTests.swift @@ -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. @@ -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 diff --git a/BlueprintUI/Tests/StackTests.swift b/BlueprintUI/Tests/StackTests.swift index 5ff4267e1..18f77a594 100644 --- a/BlueprintUI/Tests/StackTests.swift +++ b/BlueprintUI/Tests/StackTests.swift @@ -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)) diff --git a/BlueprintUICommonControls/Sources/TextField.swift b/BlueprintUICommonControls/Sources/TextField.swift index f09fb576c..fa32d09c6 100644 --- a/BlueprintUICommonControls/Sources/TextField.swift +++ b/BlueprintUICommonControls/Sources/TextField.swift @@ -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) diff --git a/CHANGELOG.md b/CHANGELOG.md index d292005c1..cf0f35613 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/SampleApp/Podfile.lock b/SampleApp/Podfile.lock index 0ed5afe69..32b2cb942 100644 --- a/SampleApp/Podfile.lock +++ b/SampleApp/Podfile.lock @@ -21,4 +21,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: bef87f42e48bddbf23595cfa6a16f4bf30ae6893 -COCOAPODS: 1.9.1 +COCOAPODS: 1.9.3