Skip to content

Commit 06d9405

Browse files
authored
Partial Revert "Refine UIKit to SwiftUI Measurement Strategies (#162)" (#164)
This reverts commit fb869c4.
1 parent fb869c4 commit 06d9405

File tree

4 files changed

+104
-174
lines changed

4 files changed

+104
-174
lines changed

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
approach to resolve an issue that could cause collection view cells to layout with
2323
unexpected dimensions
2424
- Made new layout-based SwiftUI cell rendering option the default.
25-
- Fixed an issue where a UIKit view bridged to SwiftUI that wraps would always take up the proposed
26-
size instead of its intrinsic width.
2725

2826
## [0.10.0](https://github.com/airbnb/epoxy-ios/compare/0.9.0...0.10.0) - 2023-06-29
2927

Example/EpoxyExample/ViewControllers/SwiftUI/EpoxyInSwiftUISizingStrategiesViewController.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ extension SwiftUIMeasurementContainerStrategy: Identifiable, CaseIterable {
6464
public static var allCases: [SwiftUIMeasurementContainerStrategy] = [
6565
.automatic,
6666
.proposed,
67-
.intrinsicHeightProposedOrIntrinsicWidth,
6867
.intrinsicHeightProposedWidth,
6968
.intrinsicWidthProposedHeight,
7069
.intrinsic,
@@ -82,8 +81,6 @@ extension SwiftUIMeasurementContainerStrategy: Identifiable, CaseIterable {
8281
return "Automatic"
8382
case .proposed:
8483
return "Proposed"
85-
case .intrinsicHeightProposedOrIntrinsicWidth:
86-
return "Intrinsic Height, Proposed Width or Intrinsic Width"
8784
case .intrinsicHeightProposedWidth:
8885
return "Intrinsic Height, Proposed Width"
8986
case .intrinsicWidthProposedHeight:

Sources/EpoxyCore/SwiftUI/LayoutUtilities/MeasuringViewRepresentable.swift

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,13 @@ extension MeasuringViewRepresentable {
5656

5757
// Creates a `CGSize` by replacing `nil`s with `UIView.noIntrinsicMetric`
5858
uiView.proposedSize = .init(
59-
width: (
60-
children.first { $0.label == "width" }?
61-
.value as? CGFloat ?? ViewType.noIntrinsicMetric).constraintSafeValue,
62-
height: (
63-
children.first { $0.label == "height" }?
64-
.value as? CGFloat ?? ViewType.noIntrinsicMetric).constraintSafeValue)
59+
width: children.first { $0.label == "width" }?.value as? CGFloat ?? ViewType.noIntrinsicMetric,
60+
height: children.first { $0.label == "height" }?.value as? CGFloat ?? ViewType.noIntrinsicMetric)
61+
6562
size = uiView.measuredFittingSize
6663
}
6764

68-
#if swift(>=5.7.1) // Proxy check for being built with the iOS 15 SDK
65+
#if swift(>=5.7) // Proxy check for being built with the iOS 15 SDK
6966
@available(iOS 16.0, tvOS 16.0, macOS 13.0, *)
7067
public func sizeThatFits(
7168
_ proposal: ProposedViewSize,
@@ -74,7 +71,12 @@ extension MeasuringViewRepresentable {
7471
-> CGSize?
7572
{
7673
uiView.strategy = sizing
77-
uiView.proposedSize = proposal.viewTypeValue
74+
75+
// Creates a size by replacing `nil`s with `UIView.noIntrinsicMetric`
76+
uiView.proposedSize = .init(
77+
width: proposal.width ?? ViewType.noIntrinsicMetric,
78+
height: proposal.height ?? ViewType.noIntrinsicMetric)
79+
7880
return uiView.measuredFittingSize
7981
}
8082
#endif
@@ -89,14 +91,14 @@ extension MeasuringViewRepresentable {
8991
nsView: NSViewType)
9092
{
9193
nsView.strategy = sizing
94+
9295
let children = Mirror(reflecting: proposedSize).children
96+
97+
// Creates a `CGSize` by replacing `nil`s with `UIView.noIntrinsicMetric`
9398
nsView.proposedSize = .init(
94-
width: (
95-
children.first { $0.label == "width" }?
96-
.value as? CGFloat ?? ViewType.noIntrinsicMetric).constraintSafeValue,
97-
height: (
98-
children.first { $0.label == "height" }?
99-
.value as? CGFloat ?? ViewType.noIntrinsicMetric).constraintSafeValue)
99+
width: children.first { $0.label == "width" }?.value as? CGFloat ?? ViewType.noIntrinsicMetric,
100+
height: children.first { $0.label == "height" }?.value as? CGFloat ?? ViewType.noIntrinsicMetric)
101+
100102
size = nsView.measuredFittingSize
101103
}
102104

@@ -110,38 +112,14 @@ extension MeasuringViewRepresentable {
110112
-> CGSize?
111113
{
112114
nsView.strategy = sizing
113-
nsView.proposedSize = proposal.viewTypeValue
115+
116+
// Creates a size by replacing `nil`s with `UIView.noIntrinsicMetric`
117+
nsView.proposedSize = .init(
118+
width: proposal.width ?? ViewType.noIntrinsicMetric,
119+
height: proposal.height ?? ViewType.noIntrinsicMetric)
120+
114121
return nsView.measuredFittingSize
115122
}
116123
#endif
117124
}
118125
#endif
119-
120-
#if swift(>=5.7.1) // Proxy check for being built with the iOS 15 SDK
121-
@available(iOS 16.0, tvOS 16.0, macOS 13.0, *)
122-
extension ProposedViewSize {
123-
/// Creates a size suitable for the current platform's view building framework by capping infinite values to a significantly large value and
124-
/// replacing `nil`s with `UIView.noIntrinsicMetric`
125-
var viewTypeValue: CGSize {
126-
.init(
127-
width: width?.constraintSafeValue ?? ViewType.noIntrinsicMetric,
128-
height: height?.constraintSafeValue ?? ViewType.noIntrinsicMetric)
129-
}
130-
}
131-
132-
#endif
133-
134-
extension CGFloat {
135-
static var maxConstraintValue: CGFloat {
136-
// On iOS 15 and below, configuring an auto layout constraint with the constant
137-
// `.greatestFiniteMagnitude` exceeds an internal limit and logs an exception to console. To
138-
// avoid, we use a significantly large value.
139-
1_000_000
140-
}
141-
142-
/// Returns a value suitable for configuring auto layout constraints
143-
var constraintSafeValue: CGFloat {
144-
isInfinite ? .maxConstraintValue : self
145-
}
146-
147-
}

0 commit comments

Comments
 (0)