From 85198415bbd3fbd200774dc49c1e8426d3aab664 Mon Sep 17 00:00:00 2001 From: Bryn Bodayle Date: Tue, 20 Feb 2024 13:32:32 -0800 Subject: [PATCH] CI fixes --- .../MeasuringViewRepresentable.swift | 6 ++--- .../SwiftUIMeasurementContainer.swift | 24 +++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Sources/EpoxyCore/SwiftUI/LayoutUtilities/MeasuringViewRepresentable.swift b/Sources/EpoxyCore/SwiftUI/LayoutUtilities/MeasuringViewRepresentable.swift index 04c54a1..f73db0e 100644 --- a/Sources/EpoxyCore/SwiftUI/LayoutUtilities/MeasuringViewRepresentable.swift +++ b/Sources/EpoxyCore/SwiftUI/LayoutUtilities/MeasuringViewRepresentable.swift @@ -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, @@ -90,7 +90,7 @@ extension MeasuringViewRepresentable { { nsView.strategy = sizing let children = Mirror(reflecting: proposedSize).children - nsView.proposedSize = proposal.viewTypeValue + nsView.proposedSize = proposedSize.viewTypeValue size = nsView.measuredFittingSize } @@ -111,7 +111,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` diff --git a/Sources/EpoxyCore/SwiftUI/LayoutUtilities/SwiftUIMeasurementContainer.swift b/Sources/EpoxyCore/SwiftUI/LayoutUtilities/SwiftUIMeasurementContainer.swift index 2658a5b..8374d6b 100644 --- a/Sources/EpoxyCore/SwiftUI/LayoutUtilities/SwiftUIMeasurementContainer.swift +++ b/Sources/EpoxyCore/SwiftUI/LayoutUtilities/SwiftUIMeasurementContainer.swift @@ -82,7 +82,7 @@ public final class SwiftUIMeasurementContainer: ViewType { // The proposed size is only used by the measurement, so just re-measure. _measuredFittingSize = nil - setNeedsUpdateConstraints() + setNeedsUpdateConstraintsForPlatform() } } @@ -165,7 +165,7 @@ public final class SwiftUIMeasurementContainer: ViewType { /// The cached `measuredFittingSize` to prevent unnecessary re-measurements. private var _measuredFittingSize: CGSize? { didSet { - setNeedsUpdateConstraints() + setNeedsUpdateConstraintsForPlatform() } } @@ -278,9 +278,25 @@ public final class SwiftUIMeasurementContainer: 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 @@ -299,7 +315,7 @@ public final class SwiftUIMeasurementContainer: 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)