Skip to content

Commit a1baae9

Browse files
committed
Fix justified layout
Only compute flexibility using dimension(in:) when justified.
1 parent f5db134 commit a1baae9

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Sources/Flow/Internal/Layout.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,15 @@ struct FlowLayout {
134134
var lines: Lines = []
135135
let proposedBreadth = proposedSize.replacingUnspecifiedDimensions().value(on: axis)
136136
for (index, subview) in subviews.enumerated() {
137-
let min = subview.dimensions(.zero).size(on: axis)
138-
let ideal = subview.dimensions(.unspecified).size(on: axis)
139-
let max = subview.dimensions(.infinity).size(on: axis)
140-
let size = min.breadth == 0 ? ideal.breadth == 0 ? max : ideal : min
137+
var size = subview.sizeThatFits(proposedSize).size(on: axis)
138+
if case .stretchItems = justification {
139+
let ideal = subview.dimensions(.unspecified).size(on: axis).breadth
140+
let max = subview.dimensions(.infinity).size(on: axis).breadth
141+
let isFlexible = max - ideal > 0
142+
if isFlexible {
143+
size.breadth = ideal
144+
}
145+
}
141146
if let lastIndex = lines.indices.last {
142147
let spacing = self.itemSpacing(toPrevious: index, subviews: subviews)
143148
let additionalBreadth = spacing + size.breadth

0 commit comments

Comments
 (0)