@@ -36,8 +36,10 @@ where Content == Never {
36
36
/// - Returns: Information about the view's size. The ``SwiftCrossUI/ViewSize/size``
37
37
/// property is what frame the view will actually be rendered with if the current layout
38
38
/// pass is not a dry run, while the other properties are used to inform the layout engine
39
- /// how big or small the view can be. Pass `nil` for the maximum width/height if the view
40
- /// has no maximum size (and therefore may occupy the entire screen).
39
+ /// how big or small the view can be. The ``SwiftCrossUI/ViewSize/idealSize`` property
40
+ /// should not vary with the `proposal`, and should only depend on the view's contents.
41
+ /// Pass `nil` for the maximum width/height if the view has no maximum size (and therefore
42
+ /// may occupy the entire screen).
41
43
///
42
44
/// The default implementation uses `uiView.intrinsicContentSize` and `uiView.sizeThatFits(_:)`
43
45
/// to determine the return value.
@@ -70,20 +72,27 @@ extension UIViewRepresentable {
70
72
let intrinsicSize = uiView. intrinsicContentSize
71
73
let sizeThatFits = uiView. sizeThatFits (
72
74
CGSize ( width: CGFloat ( proposal. x) , height: CGFloat ( proposal. y) ) )
73
- let roundedSize = SIMD2 (
75
+
76
+ let roundedSizeThatFits = SIMD2 (
74
77
Int ( sizeThatFits. width. rounded ( . up) ) ,
75
78
Int ( sizeThatFits. height. rounded ( . up) ) )
79
+ let roundedIntrinsicSize = SIMD2 (
80
+ Int ( intrinsicSize. width. rounded ( . awayFromZero) ) ,
81
+ Int ( intrinsicSize. height. rounded ( . awayFromZero) ) )
82
+
76
83
return ViewSize (
77
84
size: SIMD2 (
78
- intrinsicSize. width < 0.0 ? proposal. x : min ( proposal . x , roundedSize . x ) ,
79
- intrinsicSize. height < 0.0 ? proposal. y : min ( proposal . y , roundedSize . y )
85
+ intrinsicSize. width < 0.0 ? proposal. x : roundedSizeThatFits . x ,
86
+ intrinsicSize. height < 0.0 ? proposal. y : roundedSizeThatFits . y
80
87
) ,
88
+ // The 10 here is a somewhat arbitrary constant value so that it's always the same.
89
+ // See also `Color` and `Picker`, which use the same constant.
81
90
idealSize: SIMD2 (
82
- intrinsicSize. width < 0.0 ? proposal . x : roundedSize . x,
83
- intrinsicSize. height < 0.0 ? proposal . y : roundedSize . y
91
+ intrinsicSize. width < 0.0 ? 10 : roundedIntrinsicSize . x,
92
+ intrinsicSize. height < 0.0 ? 10 : roundedIntrinsicSize . y
84
93
) ,
85
- minimumWidth: max ( 0 , Int ( intrinsicSize . width . rounded ( . awayFromZero ) ) ) ,
86
- minimumHeight: max ( 0 , Int ( intrinsicSize . height . rounded ( . awayFromZero ) ) ) ,
94
+ minimumWidth: max ( 0 , roundedIntrinsicSize . x ) ,
95
+ minimumHeight: max ( 0 , roundedIntrinsicSize . x ) ,
87
96
maximumWidth: nil ,
88
97
maximumHeight: nil
89
98
)
0 commit comments