Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #23 from zenangst/improve/mosaic-layout
Browse files Browse the repository at this point in the history
Improve mosaic layout
  • Loading branch information
zenangst authored Jun 19, 2018
2 parents 75bc430 + caf7c64 commit a0ba950
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Blueprints.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "Blueprints"
s.summary = "A collection of flow layouts that is meant to make your life easier."
s.version = "0.4.1"
s.version = "0.4.2"
s.homepage = "https://github.com/zenangst/Blueprints"
s.license = 'MIT'
s.author = { "Christoffer Winterkvist" => "[email protected]" }
Expand Down
8 changes: 6 additions & 2 deletions Sources/Shared/Mosaic/VerticalMosaicBlueprintLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public class VerticalMosaicBlueprintLayout: BlueprintLayout {
mosaicLayoutAttribute.frame.size.width -= minimumInteritemSpacing
}

if mosaicLayoutAttribute.pattern.amount == 0 {
mosaicLayoutAttribute.frame.size.width = threshold - sectionInset.left - sectionInset.right
}

mosaicLayoutAttribute.frame.size.height = (itemSize.height * pattern.multiplier) - minimumLineSpacing

apply(pattern, to: mosaicLayoutAttribute, with: threshold)
Expand Down Expand Up @@ -125,7 +129,7 @@ public class VerticalMosaicBlueprintLayout: BlueprintLayout {

switch mosaic.pattern.alignment {
case .left:
layoutAttribute.frame.size.width = (width - mosaic.frame.maxX - minimumInteritemSpacing - sectionInset.left - sectionInset.right) / childCount
layoutAttribute.frame.size.width = (width - mosaic.frame.maxX - (minimumInteritemSpacing * childCount) - sectionInset.left) / childCount
case .right:
layoutAttribute.frame.size.width = (width - mosaic.frame.size.width - (minimumInteritemSpacing * childCount) - sectionInset.left - sectionInset.right) / childCount
}
Expand All @@ -141,7 +145,7 @@ public class VerticalMosaicBlueprintLayout: BlueprintLayout {
}
case .vertical:
layoutAttribute.frame.origin.y = mosaic.frame.origin.y
layoutAttribute.frame.size.width = width - mosaic.frame.size.width - minimumInteritemSpacing - sectionInset.right - sectionInset.left
layoutAttribute.frame.size.width = width - mosaic.frame.size.width - (minimumInteritemSpacing * childCount) - sectionInset.right - sectionInset.left
layoutAttribute.frame.size.height = (mosaic.frame.size.height - minimumLineSpacing) / childCount

if childCount > 1 {
Expand Down
8 changes: 4 additions & 4 deletions Tests/Shared/VerticalMosaicBlueprintLayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class VerticalMosaicBlueprintLayoutTests: XCTestCase {
XCTAssertEqual(layout.layoutAttributesForItem(at: IndexPath(item: 0, section: 0))?.frame,
CGRect(origin: .init(x: 2, y: 2), size: CGSize(width: 98, height: 23)))
XCTAssertEqual(layout.layoutAttributesForItem(at: IndexPath(item: 1, section: 0))?.frame,
CGRect(origin: .init(x: 102, y: 2), size: CGSize(width: 96, height: 10)))
CGRect(origin: .init(x: 102, y: 2), size: CGSize(width: 94, height: 10)))
XCTAssertEqual(layout.layoutAttributesForItem(at: IndexPath(item: 2, section: 0))?.frame,
CGRect(origin: .init(x: 102, y: 14), size: CGSize(width: 96, height: 10)))
CGRect(origin: .init(x: 102, y: 14), size: CGSize(width: 94, height: 10)))

XCTAssertEqual(layout.layoutAttributesForItem(at: IndexPath(item: 3, section: 0))?.frame,
CGRect(origin: .init(x: 2, y: 27), size: CGSize(width: 98, height: 23)))
Expand All @@ -34,9 +34,9 @@ class VerticalMosaicBlueprintLayoutTests: XCTestCase {
XCTAssertEqual(layout.layoutAttributesForItem(at: IndexPath(item: 6, section: 0))?.frame,
CGRect(origin: .init(x: 100, y: 52), size: CGSize(width: 98, height: 23)))
XCTAssertEqual(layout.layoutAttributesForItem(at: IndexPath(item: 7, section: 0))?.frame,
CGRect(origin: .init(x: 2, y: 52), size: CGSize(width: 96, height: 10)))
CGRect(origin: .init(x: 2, y: 52), size: CGSize(width: 94, height: 10)))
XCTAssertEqual(layout.layoutAttributesForItem(at: IndexPath(item: 8, section: 0))?.frame,
CGRect(origin: .init(x: 2, y: 64), size: CGSize(width: 96, height: 10)))
CGRect(origin: .init(x: 2, y: 64), size: CGSize(width: 94, height: 10)))


}
Expand Down

0 comments on commit a0ba950

Please sign in to comment.