Skip to content

Commit

Permalink
Renamed Remainder to Fill
Browse files Browse the repository at this point in the history
  • Loading branch information
rubencagnie committed Dec 6, 2016
1 parent 1d49898 commit b394495
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 39 deletions.
24 changes: 20 additions & 4 deletions Docs/BRICK_DIMENSION.md
Expand Up @@ -136,12 +136,28 @@ let section = BrickSection(bricks: [
# BrickDimension - Advanced
A dimension can also be complex and defined by "rules". This approach allows us to be extendable in the future

## Fill

The value of the dimension is the remainder of the row

In this example, there will be an ImageBrick with a size of 50px. The width of the LabelBrick will be the remainder of the width.
So if the screen is 320px, the LabelBrick will have a width of 270px

```swift
let section = BrickSection(bricks: [
ImageBrick(width: .Fixed(size: 50)),
LabelBrick(width: .Fill)
])
```

> Fill is only supported for `width`
## Orientation(landscape: BrickDimension, portrait: BrickDimension)
The value of the dimension is determined by the orientation of the device.

In this example, there will be 2 bricks per row in portrait and 3 bricks per row in landscape

```
```swift
let width: BrickDimension = .Orientation(landscape: .Ratio(ratio: 1/3), portrait: .Ratio(ratio: 1/2))
```

Expand All @@ -150,7 +166,7 @@ The value of the dimension is determined by the horizontal size class of the vie

In this example, there will be 2 bricks per row in a regular trait class and 1 brick per row in a compact trait class

```
```swift
let width: BrickDimension = .HorizontalSizeClass(regular: .Ratio(ratio: 1/2), compact: .Ratio(ratio: 1))
```

Expand All @@ -159,7 +175,7 @@ The value of the dimension is determined by the vertical size class of the view.

In this example, there will be 2 bricks per row in a regular trait class and 1 brick per row in a compact trait class

```
```swift
let width: BrickDimension = . VerticalSizeClass(regular: .Ratio(ratio: 1/2), compact: .Ratio(ratio: 1))
```

Expand All @@ -168,7 +184,7 @@ It's possible to mix and match the different type of BrickDimensions.

In this example, the width depends on the size class. If it's regular and landscape, there will be 3 bricks per row and in portrait, 2 per row. If the size class is compact, it always shows just 1 brick per row

```
```swift
let width: BrickDimension =
.HorizontalSizeClass(
regular: .Orientation(
Expand Down
8 changes: 4 additions & 4 deletions Example/BrickKit-Example.xcodeproj/project.pbxproj
Expand Up @@ -165,7 +165,7 @@
4E3BD8ED1DB521C200541900 /* CoverFlowViewScrollingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3BD8EB1DB521C200541900 /* CoverFlowViewScrollingController.swift */; };
4E8E10F41DB569E100B5BD90 /* EmbeddedSpotlightSnapScrollingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E8E10F31DB569E100B5BD90 /* EmbeddedSpotlightSnapScrollingViewController.swift */; };
4E8E10F51DB569E100B5BD90 /* EmbeddedSpotlightSnapScrollingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E8E10F31DB569E100B5BD90 /* EmbeddedSpotlightSnapScrollingViewController.swift */; };
932365671DF449A500BE5183 /* RemainderBrickViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 932365661DF449A500BE5183 /* RemainderBrickViewController.swift */; };
932365671DF449A500BE5183 /* FillBrickViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 932365661DF449A500BE5183 /* FillBrickViewController.swift */; };
9327D03E1DB94A9500D65BCB /* NibLessViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9327D03D1DB94A9500D65BCB /* NibLessViewController.swift */; };
9327D03F1DB94A9500D65BCB /* NibLessViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9327D03D1DB94A9500D65BCB /* NibLessViewController.swift */; };
9327D0431DB94AB300D65BCB /* NiblessBrick.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9327D0421DB94AB300D65BCB /* NiblessBrick.swift */; };
Expand Down Expand Up @@ -351,7 +351,7 @@
4E3BD8E61DB51E1200541900 /* BrickIdentifiers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BrickIdentifiers.swift; sourceTree = "<group>"; };
4E3BD8EB1DB521C200541900 /* CoverFlowViewScrollingController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoverFlowViewScrollingController.swift; sourceTree = "<group>"; };
4E8E10F31DB569E100B5BD90 /* EmbeddedSpotlightSnapScrollingViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmbeddedSpotlightSnapScrollingViewController.swift; sourceTree = "<group>"; };
932365661DF449A500BE5183 /* RemainderBrickViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemainderBrickViewController.swift; sourceTree = "<group>"; };
932365661DF449A500BE5183 /* FillBrickViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FillBrickViewController.swift; sourceTree = "<group>"; };
9327D03D1DB94A9500D65BCB /* NibLessViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NibLessViewController.swift; sourceTree = "<group>"; };
9327D0421DB94AB300D65BCB /* NiblessBrick.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NiblessBrick.swift; sourceTree = "<group>"; };
935D488F1DB7CCC70091AA39 /* ImagesInCollectionBrickViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImagesInCollectionBrickViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -626,7 +626,7 @@
4E3BD7A91DB1316400541900 /* SimpleRepeatFixedWidthViewController.swift */,
4E3BD7AA1DB1316400541900 /* SimpleRepeatHeightRatioViewController.swift */,
9327D03D1DB94A9500D65BCB /* NibLessViewController.swift */,
932365661DF449A500BE5183 /* RemainderBrickViewController.swift */,
932365661DF449A500BE5183 /* FillBrickViewController.swift */,
);
path = Simple;
sourceTree = "<group>";
Expand Down Expand Up @@ -1005,7 +1005,7 @@
4E15F92C1DBA570600BBD363 /* MockTwitterViewController.swift in Sources */,
4E3BD7DE1DB1316400541900 /* SegmentHeaderBrick.swift in Sources */,
4E3BD8261DB1316400541900 /* HideSectionsViewController.swift in Sources */,
932365671DF449A500BE5183 /* RemainderBrickViewController.swift in Sources */,
932365671DF449A500BE5183 /* FillBrickViewController.swift in Sources */,
4E3BD8241DB1316400541900 /* HideBrickViewController.swift in Sources */,
93EAFE2F1DB57D680036331C /* NavigationTransition.swift in Sources */,
4E3BD7D81DB1316400541900 /* PostBrick.swift in Sources */,
Expand Down
@@ -1,5 +1,5 @@
//
// RemainderBrickViewController.swift
// FillBrickViewController.swift
// BrickKit-Example
//
// Created by Ruben Cagnie on 12/4/16.
Expand All @@ -9,13 +9,13 @@
import UIKit
import BrickKit

class RemainderBrickViewController: BrickViewController {
class FillBrickViewController: BrickViewController {
override class var title: String {
return "Remainder Example"
return "Fill Example"
}

override class var subTitle: String {
return "Example of using the Remainder BrickDimension"
return "Example of using the Fill BrickDimension"
}

override func viewDidLoad() {
Expand All @@ -31,12 +31,12 @@ class RemainderBrickViewController: BrickViewController {

let section = BrickSection(bricks: [
LabelBrick(width: .Fixed(size: 50), backgroundColor: .brickGray1, text: "BRICK", configureCellBlock: configureCell),
LabelBrick(width: .Remainder, backgroundColor: .brickGray3, text: "BRICK", configureCellBlock: configureCell),
LabelBrick(width: .Remainder, backgroundColor: .brickGray5, text: "BRICK", configureCellBlock: configureCell),
LabelBrick(width: .Fill, backgroundColor: .brickGray3, text: "BRICK", configureCellBlock: configureCell),
LabelBrick(width: .Fill, backgroundColor: .brickGray5, text: "BRICK", configureCellBlock: configureCell),
LabelBrick(width: .Fixed(size: 50), backgroundColor: .brickGray2, text: "BRICK", configureCellBlock: configureCell),
BrickSection(width: .Remainder, backgroundColor: .brickGray4, bricks: [
BrickSection(width: .Fill, backgroundColor: .brickGray4, bricks: [
LabelBrick(width: .Ratio(ratio: 0.25), backgroundColor: .brickGray1, text: "BRICK", configureCellBlock: configureCell),
LabelBrick(width: .Remainder, backgroundColor: .brickGray3, text: "BRICK", configureCellBlock: configureCell),
LabelBrick(width: .Fill, backgroundColor: .brickGray3, text: "BRICK", configureCellBlock: configureCell),
])
], inset: 10, edgeInsets: UIEdgeInsets(top: 20, left: 10, bottom: 20, right: 10))

Expand Down
2 changes: 1 addition & 1 deletion Example/Source/Navigation/NavigationDataSource.swift
Expand Up @@ -49,7 +49,7 @@ class NavigationDataSource {
SimpleRepeatFixedWidthViewController.self,
SimpleRepeatFixedHeightViewController.self,
SimpleRepeatHeightRatioViewController.self,
RemainderBrickViewController.self,
FillBrickViewController.self,
MultiSectionBrickViewController.self,
MultiDimensionBrickViewController.self,
]),
Expand Down
10 changes: 5 additions & 5 deletions Source/Models/BrickDimension.swift
Expand Up @@ -27,7 +27,7 @@ extension UIView {
public indirect enum BrickDimension {
case Ratio(ratio: CGFloat)
case Fixed(size: CGFloat)
case Remainder
case Fill

case Auto(estimate: BrickDimension)
case Orientation(landscape: BrickDimension, portrait: BrickDimension)
Expand Down Expand Up @@ -65,18 +65,18 @@ public indirect enum BrickDimension {
}
}

/// Function that gets the raw value of a BrickDimension. As of right now, only Ratio and Fixed are allowed
/// Function that gets the raw value of a BrickDimension. As of right now, only Ratio, Fixed and Fill are allowed
static func _rawValue(for otherDimension: CGFloat, startingAt origin: CGFloat, in view: UIView, with dimension: BrickDimension) -> CGFloat {
switch dimension {
case .Ratio(let ratio): return ratio * otherDimension
case .Fixed(let size): return size
case .Remainder:
case .Fill:
guard otherDimension > origin else {
// If the origin is bigger than the actual dimension, just return the whole dimension
return otherDimension
}
return otherDimension - origin
default: fatalError("Only Ratio and Fixed are allowed")
default: fatalError("Only Ratio, Fixed and Fill are allowed")
}
}
}
Expand Down Expand Up @@ -104,7 +104,7 @@ public func ==(lhs: BrickDimension, rhs: BrickDimension) -> Bool {
case (let .VerticalSizeClass(regular1, compact1), let .VerticalSizeClass(regular2, compact2)):
return regular1 == regular2 && compact1 == compact2

case (.Remainder, .Remainder):
case (.Fill, .Fill):
return true

default:
Expand Down
18 changes: 9 additions & 9 deletions Tests/Models/BrickDimensionTests.swift
Expand Up @@ -63,30 +63,30 @@ class BrickDimensionTests: XCTestCase {
XCTAssertNotEqual(ratio, BrickDimension.Fixed(size: 100))
}

func testRemainder() {
let ratio = BrickDimension.Remainder
func testFill() {
let ratio = BrickDimension.Fill
XCTAssertEqual(ratio.value(for: 1000, startingAt: 0, in: UIView()), 1000)
XCTAssertEqual(ratio.dimension(in: UIView()), ratio)
XCTAssertFalse(ratio.isEstimate(in: UIView()))
XCTAssertEqual(ratio, BrickDimension.Remainder)
XCTAssertEqual(ratio, BrickDimension.Fill)
XCTAssertNotEqual(ratio, BrickDimension.Fixed(size: 100))
}

func testRemainderWithStartingOrigin() {
let ratio = BrickDimension.Remainder
func testFillWithStartingOrigin() {
let ratio = BrickDimension.Fill
XCTAssertEqual(ratio.value(for: 1000, startingAt: 500, in: UIView()), 500)
XCTAssertEqual(ratio.dimension(in: UIView()), ratio)
XCTAssertFalse(ratio.isEstimate(in: UIView()))
XCTAssertEqual(ratio, BrickDimension.Remainder)
XCTAssertEqual(ratio, BrickDimension.Fill)
XCTAssertNotEqual(ratio, BrickDimension.Fixed(size: 100))
}

func testRemainderWithStartingOriginThatIsTooBig() {
let ratio = BrickDimension.Remainder
func testFillWithStartingOriginThatIsTooBig() {
let ratio = BrickDimension.Fill
XCTAssertEqual(ratio.value(for: 1000, startingAt: 1001, in: UIView()), 1000)
XCTAssertEqual(ratio.dimension(in: UIView()), ratio)
XCTAssertFalse(ratio.isEstimate(in: UIView()))
XCTAssertEqual(ratio, BrickDimension.Remainder)
XCTAssertEqual(ratio, BrickDimension.Fill)
XCTAssertNotEqual(ratio, BrickDimension.Fixed(size: 100))
}

Expand Down
16 changes: 8 additions & 8 deletions Tests/ViewControllers/BrickCollectionViewTests.swift
Expand Up @@ -494,12 +494,12 @@ class BrickCollectionViewTests: XCTestCase {
XCTAssertEqual(cell3?.frame, CGRect(x: 0, y: 125, width: 320, height: 25))
}

func testThatRemainderBrickDimensionIgnoresEdgeInsets() {
func testThatFillBrickDimensionIgnoresEdgeInsets() {

brickView.registerBrickClass(DummyBrick.self)
let section = BrickSection("TestSection", bricks:[
DummyBrick(width: .Fixed(size: 50), height: .Fixed(size: 25)),
DummyBrick(width: .Remainder, height: .Fixed(size: 25))
DummyBrick(width: .Fill, height: .Fixed(size: 25))
], inset: 5, edgeInsets: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
brickView.setSection(section)
brickView.layoutSubviews()
Expand All @@ -526,11 +526,11 @@ class BrickCollectionViewTests: XCTestCase {
XCTAssertEqual(cell2?.frame, CGRect(x: 65, y: 10, width: 405, height: 25))
}

func testThatSingleRemainderBrickDimensionIsFullWidth() {
func testThatSingleFillBrickDimensionIsFullWidth() {

brickView.registerBrickClass(DummyBrick.self)
let section = BrickSection(bricks:[
DummyBrick(width: .Remainder, height: .Fixed(size: 25))
DummyBrick(width: .Fill, height: .Fixed(size: 25))
], inset: 5, edgeInsets: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
brickView.setSection(section)
brickView.layoutSubviews()
Expand All @@ -553,12 +553,12 @@ class BrickCollectionViewTests: XCTestCase {
XCTAssertEqual(cell1?.frame, CGRect(x: 10, y: 10, width: 460, height: 25))
}

func testThatFullWidthRemainderAsSecondDoesntCrash() {
func testThatFullWidthFillAsSecondDoesntCrash() {

brickView.registerBrickClass(DummyBrick.self)
let section = BrickSection("TestSection", bricks:[
DummyBrick(height: .Fixed(size: 25)),
DummyBrick(width: .Remainder, height: .Fixed(size: 25))
DummyBrick(width: .Fill, height: .Fixed(size: 25))
], inset: 5, edgeInsets: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
brickView.setSection(section)
brickView.layoutSubviews()
Expand All @@ -585,13 +585,13 @@ class BrickCollectionViewTests: XCTestCase {
XCTAssertEqual(cell2?.frame, CGRect(x: 10, y: 40, width: 460, height: 25))
}

func testThatRemainderInSectionTakesOriginIntoAccount() {
func testThatFillInSectionTakesOriginIntoAccount() {

brickView.registerBrickClass(DummyBrick.self)
let section = BrickSection("TestSection", bricks:[
BrickSection(bricks: [
DummyBrick(width: .Fixed(size: 50), height: .Fixed(size: 25)),
DummyBrick(width: .Remainder, height: .Fixed(size: 25))
DummyBrick(width: .Fill, height: .Fixed(size: 25))
])
], inset: 5, edgeInsets: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
brickView.setSection(section)
Expand Down

0 comments on commit b394495

Please sign in to comment.