Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated height provider code to be a closure #191

Merged
merged 2 commits into from
Sep 27, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions Source/Bricks/Generic/GenericBrick.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ public protocol UpdateFramesListener {
func didUpdateFrames()
}

public protocol CustomHeightProvider {
func customHeight(for view: UIView, constraintedTo width: CGFloat) -> CGFloat
}

open class GenericBrick<T: UIView>: Brick, ViewGenerator {
public typealias ConfigureView = (_ view: T, _ cell: GenericBrickCell) -> Void

Expand Down Expand Up @@ -77,7 +73,7 @@ open class GenericBrickCell: BrickCell {
}
}

open var customHeightProvider: CustomHeightProvider?
open var customHeightProvider: ((_ width: CGFloat) -> CGFloat)?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this in a typealias


internal private(set) var fromNib: Bool = false

Expand Down Expand Up @@ -196,7 +192,7 @@ open class GenericBrickCell: BrickCell {

open override func heightForBrickView(withWidth width: CGFloat) -> CGFloat {
if let heightProvider = customHeightProvider {
let height = heightProvider.customHeight(for: self.genericContentView!, constraintedTo: width)
let height = heightProvider(width)
return height
} else {
return super.heightForBrickView(withWidth: width)
Expand Down
10 changes: 4 additions & 6 deletions Tests/Bricks/GenericBrickTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class GenericBrickTestUILabel: GenericBrickTests {
}
}

class GenericBrickTestHeight: GenericBrickTests, CustomHeightProvider {
class GenericBrickTestHeight: GenericBrickTests {

override func setUp() {
super.setUp()
Expand All @@ -77,13 +77,11 @@ class GenericBrickTestHeight: GenericBrickTests, CustomHeightProvider {

func testHeight() {
XCTAssertEqual(CGFloat(0), cell.heightForBrickView(withWidth: 200))
cell.customHeightProvider = self
cell.customHeightProvider = { width in
return 100
}
XCTAssertEqual(CGFloat(100), cell.heightForBrickView(withWidth: 200))
}

func customHeight(for view: UIView, constraintedTo width: CGFloat) -> CGFloat {
return 100
}
}

class GenericBrickTestUILabelWithEdgeInsets: GenericBrickTests {
Expand Down