Skip to content

Commit

Permalink
CI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
brynbodayle committed Feb 21, 2024
1 parent c0c12cd commit 2ca6dc4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ extension SwiftUIMeasurementContainerStrategy: Identifiable, CaseIterable {
var displayString: String {
switch self {
case .automatic:
"Automatic"
return "Automatic"
case .proposed:
"Proposed"
return "Proposed"
case .intrinsicHeightProposedOrIntrinsicWidth:
"Intrinsic Height, Proposed Width or Intrinsic Width"
return "Intrinsic Height, Proposed Width or Intrinsic Width"
case .intrinsicHeightProposedWidth:
"Intrinsic Height, Proposed Width"
return "Intrinsic Height, Proposed Width"
case .intrinsicWidthProposedHeight:
"Intrinsic Width, Proposed Height"
return "Intrinsic Width, Proposed Height"
case .intrinsic:
"Intrinsic"
return "Intrinsic"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extension MeasuringViewRepresentable {
size = uiView.measuredFittingSize
}

#if swift(>=5.7) // Proxy check for being built with the iOS 15 SDK
#if swift(>=5.7.1) // Proxy check for being built with the iOS 15 SDK
@available(iOS 16.0, tvOS 16.0, macOS 13.0, *)
public func sizeThatFits(
_ proposal: ProposedViewSize,
Expand All @@ -90,7 +90,13 @@ extension MeasuringViewRepresentable {
{
nsView.strategy = sizing
let children = Mirror(reflecting: proposedSize).children
nsView.proposedSize = proposal.viewTypeValue
nsView.proposedSize = .init(
width: (
children.first { $0.label == "width" }?
.value as? CGFloat ?? ViewType.noIntrinsicMetric).constraintSafeValue,
height: (
children.first { $0.label == "height" }?
.value as? CGFloat ?? ViewType.noIntrinsicMetric).constraintSafeValue)
size = nsView.measuredFittingSize
}

Expand All @@ -111,7 +117,7 @@ extension MeasuringViewRepresentable {
}
#endif

#if swift(>=5.7) // Proxy check for being built with the iOS 15 SDK
#if swift(>=5.7.1) // Proxy check for being built with the iOS 15 SDK
@available(iOS 16.0, tvOS 16.0, macOS 13.0, *)
extension ProposedViewSize {
/// Creates a size by replacing `nil`s with `UIView.noIntrinsicMetric`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public final class SwiftUIMeasurementContainer<Content: ViewType>: ViewType {

// The proposed size is only used by the measurement, so just re-measure.
_measuredFittingSize = nil
setNeedsUpdateConstraints()
setNeedsUpdateConstraintsForPlatform()
}
}

Expand Down Expand Up @@ -165,7 +165,7 @@ public final class SwiftUIMeasurementContainer<Content: ViewType>: ViewType {
/// The cached `measuredFittingSize` to prevent unnecessary re-measurements.
private var _measuredFittingSize: CGSize? {
didSet {
setNeedsUpdateConstraints()
setNeedsUpdateConstraintsForPlatform()
}
}

Expand Down Expand Up @@ -278,9 +278,25 @@ public final class SwiftUIMeasurementContainer<Content: ViewType>: ViewType {
}
}

private func setNeedsUpdateConstraintsForPlatform() {
#if os(iOS) || os(tvOS)
setNeedsUpdateConstraints()
#elseif os(macOS)
needsUpdateConstraints = true
#endif
}

private func updateConstraintsForPlatformIfNeeded() {
#if os(iOS) || os(tvOS)
updateConstraintsIfNeeded()
#elseif os(macOS)
updateConstraintsForSubtreeIfNeeded()
#endif
}

/// Measures the `uiView`, storing the resulting size in `measuredIntrinsicContentSize`.
private func measureView() -> CGSize {
updateConstraintsIfNeeded()
updateConstraintsForPlatformIfNeeded()
latestMeasurementBoundsSize = bounds.size

var measuredSize: CGSize
Expand All @@ -299,7 +315,7 @@ public final class SwiftUIMeasurementContainer<Content: ViewType>: ViewType {
measuredSize.height = ViewType.noIntrinsicMetric

case .intrinsicHeightProposedOrIntrinsicWidth:
let fittingSize = content.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
let fittingSize = content.systemLayoutFittingIntrinsicSize()
measuredSize = CGSize(
width: min(fittingSize.width, proposedSize.width > 0 ? proposedSize.width : fittingSize.width),
height: fittingSize.height)
Expand Down

0 comments on commit 2ca6dc4

Please sign in to comment.