Skip to content

Commit

Permalink
VStack line spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
tevelee committed Aug 14, 2024
1 parent e19b92c commit 9798fa5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Flow/Internal/Layout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct FlowLayout: Sendable {
var size = lines
.map(\.size)
.reduce(.zero, breadth: max, depth: +)
size[.vertical] += lines.sum(of: \.leadingSpace)
size.depth += lines.sum(of: \.leadingSpace)
return CGSize(size: size, axis: axis)
}

Expand Down
22 changes: 22 additions & 0 deletions Tests/FlowTests/FlowTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,28 @@ final class FlowTests: XCTestCase {
""")
}

func test_VFlow_size_singleElement() throws {
// Given
let sut: FlowLayout = .vertical(alignment: .center, itemSpacing: 10, lineSpacing: 20)

// When
let size = sut.sizeThatFits(proposal: 100×100, subviews: [50×50])

// Then
XCTAssertEqual(size, 50×50)
}

func test_VFlow_size_multipleElements() throws {
// Given
let sut: FlowLayout = .vertical(alignment: .center, itemSpacing: 10, lineSpacing: 20)

// When
let size = sut.sizeThatFits(proposal: 130×130, subviews: repeated(50×50, times: 3))

// Then
XCTAssertEqual(size, 120×110)
}

func test_VFlow_layout_leading() {
// Given
let sut: FlowLayout = .vertical(alignment: .leading, itemSpacing: 1, lineSpacing: 1)
Expand Down

0 comments on commit 9798fa5

Please sign in to comment.