Skip to content

Commit

Permalink
Validate fittingSize for ListView.contentSize(in:for:)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleve committed Nov 21, 2020
1 parent 42d0198 commit cacbead
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

- [`Appearance.backgroundColor` now respects the current `UITraitCollection.userInterfaceStyle`](https://github.com/kyleve/Listable/pull/231). This means that the background color will default to `white` in light mode, and `black` in dark mode.

- [Update `ListView.contentSize(in:for:)` to properly validate the provided `fittingSize`](TODO). This ensures that `.unconstrained` measurements along the wrong axis will now assert; instead of freeze.

### Added

- [Introduce `onSelectionChanged` on `ListStateObserver`](https://github.com/kyleve/Listable/pull/223) to allow observing when the selected rows change.
Expand Down
20 changes: 18 additions & 2 deletions ListableUI/Sources/ListView/ListSizing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,25 @@ extension ListView
/// for the layout. Only the cross-axis of the direction – width for vertical, and height for
/// horizontal.

let unconstrainedValues : Set<CGFloat> = [0.0, .greatestFiniteMagnitude, .infinity]

view.frame.size = view.collectionViewLayout.layout.direction.switch(
vertical: CGSize(width: fittingSize.width, height: 100.0),
horizontal: CGSize(width: 100.0, height: fittingSize.height)
vertical: {
precondition(
unconstrainedValues.contains(fittingSize.width) == false,
"Must provide a valid fitting width to measure vertically laid out lists. Instead, the width was '\(fittingSize.width)'."
)

return CGSize(width: fittingSize.width, height: 100.0)
},
horizontal: {
precondition(
unconstrainedValues.contains(fittingSize.height) == false,
"Must provide a valid fitting height to measure horizontally laid out lists. Instead, the height was '\(fittingSize.height)'."
)

return CGSize(width: 100.0, height: fittingSize.height)
}
)

let size = view.contentSize
Expand Down

0 comments on commit cacbead

Please sign in to comment.