Skip to content

Commit

Permalink
Merge pull request #232 from kyleve/kve/validate-fitting-size
Browse files Browse the repository at this point in the history
Validate fittingSize for ListView.contentSize(in:for:)
  • Loading branch information
kyleve authored Nov 21, 2020
2 parents 42d0198 + ae2ceee commit c307b83
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 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`](https://github.com/kyleve/Listable/pull/232). 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
22 changes: 19 additions & 3 deletions ListableUI/Sources/ListView/ListSizing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ extension ListView
//
// MARK: Measuring Lists
//

public static func contentSize(in fittingSize : CGSize, for properties : ListProperties.Build) -> CGSize {
self.contentSize(in: fittingSize, for: .default(with: properties))
}
Expand All @@ -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 c307b83

Please sign in to comment.