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

Fixed a bug that prevented the SnapToPointLayoutBehavior from filteri… #83

Merged
merged 1 commit into from
Feb 17, 2017
Merged

Fixed a bug that prevented the SnapToPointLayoutBehavior from filteri… #83

merged 1 commit into from
Feb 17, 2017

Conversation

willspurgeon
Copy link
Contributor

…ng out the enclosing CollectionBrick layout attribute before calculating offsets. Fixes #82

@codecov-io
Copy link

codecov-io commented Feb 16, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@37e1596). Click here to learn what that means.
The diff coverage is 84.61%.

@@            Coverage Diff            @@
##             master      #83   +/-   ##
=========================================
  Coverage          ?   93.76%           
=========================================
  Files             ?       38           
  Lines             ?     2997           
  Branches          ?        0           
=========================================
  Hits              ?     2810           
  Misses            ?      187           
  Partials          ?        0
Impacted Files Coverage Δ
Source/Behaviors/SnapToPointLayoutBehavior.swift 90.76% <84.61%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 37e1596...750742d. Read the comment docs.

return !self.sectionsToIgnore.contains($0.indexPath.section)
}

guard !filteredAttributes.isEmpty else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this check needed? Just returning filteredAttributes should be fine

@@ -95,40 +95,58 @@ public class SnapToPointLayoutBehavior: BrickLayoutBehavior {
resetCollectionViewContentInset(collectionViewLayout)
}

internal func getFilteredAttributes(layout collectionViewLayout: UICollectionViewLayout, frame: CGRect) -> [BrickLayoutAttributes] {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like the get prefix. That's very java-like
Please rename to
filteredAttributes(layout collectionViewLayout: UICollectionViewLayout, frame: CGRect) -> [BrickLayoutAttributes]

return
}

originalTopContentInset = collectionViewLayout.collectionView!.contentInset.top

switch scrollDirection {
case .Horizontal(let scrollLocation):
let firstAttributes = attributes.minElement {
let firstAttribute = filteredAttributes.minElement {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to rename firstAttributes to firstAttribute. The object contains BrickLayoutAttributes (with a S)



let collection = CollectionViewController()
Copy link
Contributor

Choose a reason for hiding this comment

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

This test can be much simpeler by not using a CollectionViewController

Checkout BrickCollectionViewTests:testWithImageInCollectionBrick

        let section1 = BrickSection(bricks: [
            ImageBrick(width: .Ratio(ratio: 1/4), height: .Ratio(ratio: 1), dataSource: ImageBrickModel(image: image, contentMode: .ScaleAspectFill)),
            ])

        let section = BrickSection(backgroundColor: .whiteColor(), bricks: [
            CollectionBrick("Collection 1", backgroundColor: .orangeColor(), scrollDirection: .Horizontal, dataSource: CollectionBrickCellModel(section: section1), brickTypes: [ImageBrick.self]),
            ])
        brickView.setupSectionAndLayout(section)

        let cell1 = brickView.cellForItemAtIndexPath(NSIndexPath(forItem: 0, inSection: 1))
        XCTAssertEqual(cell1?.frame, CGRect(x: 0, y: 0, width: 320, height: 80))

Copy link
Contributor

Choose a reason for hiding this comment

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

There is also in CollectionBrickCellModel a configureHandler that you can use to add the behavior

…ng out the enclosing CollectionBrick layout attribute before calculating offsets. Fixes #82
@rubencagnie rubencagnie merged commit 16f3783 into wayfair-archive:master Feb 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants