@@ -56,16 +56,13 @@ extension MeasuringViewRepresentable {
56
56
57
57
// Creates a `CGSize` by replacing `nil`s with `UIView.noIntrinsicMetric`
58
58
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
+
65
62
size = uiView. measuredFittingSize
66
63
}
67
64
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
69
66
@available ( iOS 16 . 0 , tvOS 16 . 0 , macOS 13 . 0 , * )
70
67
public func sizeThatFits(
71
68
_ proposal: ProposedViewSize ,
@@ -74,7 +71,12 @@ extension MeasuringViewRepresentable {
74
71
-> CGSize ?
75
72
{
76
73
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
+
78
80
return uiView. measuredFittingSize
79
81
}
80
82
#endif
@@ -89,14 +91,14 @@ extension MeasuringViewRepresentable {
89
91
nsView: NSViewType )
90
92
{
91
93
nsView. strategy = sizing
94
+
92
95
let children = Mirror ( reflecting: proposedSize) . children
96
+
97
+ // Creates a `CGSize` by replacing `nil`s with `UIView.noIntrinsicMetric`
93
98
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
+
100
102
size = nsView. measuredFittingSize
101
103
}
102
104
@@ -110,38 +112,14 @@ extension MeasuringViewRepresentable {
110
112
-> CGSize ?
111
113
{
112
114
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
+
114
121
return nsView. measuredFittingSize
115
122
}
116
123
#endif
117
124
}
118
125
#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