Skip to content

Commit

Permalink
Correctly account for zero-width spacers in implied distribution
Browse files Browse the repository at this point in the history
Currently the implied distribution does not behave as documented in cases where the fixed spacers sum to zero (either by using zero-size spacers or by combining positive- and negative-sized spacers). This updates the logic to correctly identify the use of _any_ fixed spacer.

Resolves #126
  • Loading branch information
NickEntin committed Jun 11, 2024
1 parent 420dc31 commit 08b3c9d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Paralayout/ViewDistributionItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public enum ViewDistributionItem: ViewDistributionSpecifying {
var distributionItems = [ViewDistributionItem]()
var totalViewSize: CGFloat = 0
var totalFixedSpace: CGFloat = 0
var hasFixedSpacers: Bool = false
var totalFlexibleSpace: CGFloat = 0

var subviewsToDistribute = Set<UIView>()
Expand All @@ -92,6 +93,7 @@ public enum ViewDistributionItem: ViewDistributionSpecifying {

case .fixed:
totalFixedSpace += layoutSize
hasFixedSpacers = true

case .flexible:
totalFlexibleSpace += layoutSize
Expand All @@ -107,7 +109,7 @@ public enum ViewDistributionItem: ViewDistributionSpecifying {

// Insert flexible space if necessary.
if totalFlexibleSpace == 0 {
if totalFixedSpace == 0 {
if !hasFixedSpacers {
// No spacers at all: insert `1.flexible` between all items.
for i in 0 ..< (distributionItems.count + 1) {
distributionItems.insert(1.flexible, at: i * 2)
Expand Down

0 comments on commit 08b3c9d

Please sign in to comment.