From b331cfe6975ceef1ce013c40b31225983881299f Mon Sep 17 00:00:00 2001 From: Bryn Bodayle Date: Wed, 21 Feb 2024 10:47:02 -0800 Subject: [PATCH] Updates for self review --- CHANGELOG.md | 2 +- .../LayoutUtilities/MeasuringViewRepresentable.swift | 3 ++- .../LayoutUtilities/SwiftUIMeasurementContainer.swift | 7 ++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf4a64c..1ddcd0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 unexpected dimensions - Made new layout-based SwiftUI cell rendering option the default. - Fixed an issue where a UIKit view bridged to SwiftUI that wraps would always take up the proposed - size instead of it's intrinsic width. + size instead of its intrinsic width. ## [0.10.0](https://github.com/airbnb/epoxy-ios/compare/0.9.0...0.10.0) - 2023-06-29 diff --git a/Sources/EpoxyCore/SwiftUI/LayoutUtilities/MeasuringViewRepresentable.swift b/Sources/EpoxyCore/SwiftUI/LayoutUtilities/MeasuringViewRepresentable.swift index 25b16fc..f8b794a 100644 --- a/Sources/EpoxyCore/SwiftUI/LayoutUtilities/MeasuringViewRepresentable.swift +++ b/Sources/EpoxyCore/SwiftUI/LayoutUtilities/MeasuringViewRepresentable.swift @@ -120,7 +120,8 @@ extension MeasuringViewRepresentable { #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` + /// Creates a size by capping infinite values to a significantly large value and replacing `nil`s + /// with `UIView.noIntrinsicMetric` var viewTypeValue: CGSize { .init( width: width?.constraintSafeValue ?? ViewType.noIntrinsicMetric, diff --git a/Sources/EpoxyCore/SwiftUI/LayoutUtilities/SwiftUIMeasurementContainer.swift b/Sources/EpoxyCore/SwiftUI/LayoutUtilities/SwiftUIMeasurementContainer.swift index 8374d6b..74d75fa 100644 --- a/Sources/EpoxyCore/SwiftUI/LayoutUtilities/SwiftUIMeasurementContainer.swift +++ b/Sources/EpoxyCore/SwiftUI/LayoutUtilities/SwiftUIMeasurementContainer.swift @@ -78,7 +78,6 @@ public final class SwiftUIMeasurementContainer: ViewType { public var proposedSize = CGSize.noIntrinsicMetric { didSet { guard oldValue != proposedSize else { return } - _resolvedStrategy = nil // The proposed size is only used by the measurement, so just re-measure. _measuredFittingSize = nil @@ -296,6 +295,8 @@ public final class SwiftUIMeasurementContainer: ViewType { /// Measures the `uiView`, storing the resulting size in `measuredIntrinsicContentSize`. private func measureView() -> CGSize { + // immediately update constraints to the latest values so that the measurements below take them + // into account updateConstraintsForPlatformIfNeeded() latestMeasurementBoundsSize = bounds.size @@ -354,8 +355,8 @@ public enum SwiftUIMeasurementContainerStrategy { /// Typically used for views that should expand greedily in both axes, e.g. a background view. case proposed - /// The `uiView`'s receives either its intrinsic width or the proposed width, whichever is smaller. The view receives its height based - /// on the chosen width. + /// The `uiView`'s receives either its intrinsic width or the proposed width, whichever is smaller. The view receives its intrinsic height + /// based on the chosen width. /// /// Typically used for views that have a height that's a function of their width, e.g. a row with /// text that can wrap to multiple lines.