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

Added Restricted Brick Size #168

Merged
merged 1 commit into from
Aug 8, 2017
Merged

Added Restricted Brick Size #168

merged 1 commit into from
Aug 8, 2017

Conversation

jay18001
Copy link
Contributor

@jay18001 jay18001 commented Jul 31, 2017

Created a way for bricks to be restricted with a minimum size or maximum size

@jay18001 jay18001 changed the title Added RestrictedBrickSize Added Restricted Brick Size Jul 31, 2017
@rubencagnie
Copy link
Contributor

Please add a description on what this PR does

case maximumSize(size: BrickDimension)
}

public struct RestrictedBrickSize {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this a separate struct and not just part of the BrickSize restricted? I'd had expected a new case in the enum indirect case restricted(size: BrickDimension, restriction: RestrictedBrickSize)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

let restrictedSize: RestrictedSize

var isEstimate: Bool {
switch size {
Copy link
Contributor

Choose a reason for hiding this comment

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

The switch should be done on size.dimension(withValue: value), because this could be an indirect size

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

var isEstimate: Bool {
switch size {
case .auto(_): return true
default: return false
Copy link
Contributor

Choose a reason for hiding this comment

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

Not code covered

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thats not really applicable, if you're not using auto there is no point of a restriction

Copy link
Contributor

Choose a reason for hiding this comment

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

We should still write a test to document this

DummyResizableBrick("Brick", height: .restricted(restriction: RestrictedBrickSize(size: .auto(estimate: .fixed(size: 100)), restrictedSize: .minimumSize(size: .fixed(size: 100)))), setHeight: 200)
])

brickCollectionView.setupSectionAndLayout(section)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can also use setupSingleBrickAndLayout. That way you don't have to wrap it in a BrickSection

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


brickCollectionView.setupSectionAndLayout(section)

let cell = brickCollectionView.cellForItem(at: IndexPath(item: 0, section: 1)) as? DummyResizableBrickCell
Copy link
Contributor

Choose a reason for hiding this comment

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

Check the indexpath by calling brickCollectionView.indexPathsForBricksWithIdentifier. It's a safer way to get to the right cell

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

let cell = brickCollectionView.cellForItem(at: IndexPath(item: 0, section: 1)) as? DummyResizableBrickCell
cell?.layoutIfNeeded()
XCTAssertEqual(cell?.frame.size.height, 50)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

As RestrictedBrickSize takes in a BrickDimension for restrictedSize, there should be a check for using other BrickDimensions as well, like Ratio, Fixed + indirect ones (like Size dependent etc)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using anything else will cause a fatalError on BrickDimension.swift:175 fatalError("Only Ratio, Fixed and Fill are allowed") as designed

Copy link
Contributor

Choose a reason for hiding this comment

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

It should still work with indirect dimensions. The error fatalError("Only Ratio, Fixed and Fill are allowed") should never happen

@codecov-io
Copy link

codecov-io commented Jul 31, 2017

Codecov Report

Merging #168 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #168      +/-   ##
==========================================
+ Coverage   93.34%   93.37%   +0.02%     
==========================================
  Files          39       39              
  Lines        4134     4149      +15     
  Branches      335      339       +4     
==========================================
+ Hits         3859     3874      +15     
  Misses        274      274              
  Partials        1        1
Impacted Files Coverage Δ
Source/ViewControllers/BrickCollectionView.swift 95.41% <ø> (ø) ⬆️
Source/Models/BrickDimension.swift 99.33% <100%> (+0.04%) ⬆️
Source/Cells/BrickCell.swift 98.55% <100%> (+0.05%) ⬆️

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 3f7f86a...3025824. Read the comment docs.

return "Basic example of using bricks with a restricted maximum and minimum height"
}

override func viewDidLoad() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also add an example that changes from .restricted > .auto to simulate the expand/collapse behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

internal static func restrictedValue(for cellHeight: CGFloat, width: CGFloat, restrictedSize: RestrictedSize) -> CGFloat {
switch restrictedSize {
case .minimumSize(let minimumDimension):
return max(cellHeight, BrickDimension._rawValue(for: width, startingAt: 0, with: minimumDimension))
Copy link
Contributor

Choose a reason for hiding this comment

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

We should pass the returned size from the dimension-function instead, to support indirect sizes as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could do that but then the user of this would have to know that .auto cannot be used anywhere else

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean?

XCTAssertEqual(cell?.frame.size.height, 100)
}

func testChangeBrickSizeLessThanMaximum() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I want to see more tests where the restrictedSize is not .fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

There should also be indirect-cases (based on orientation, size class etc)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

@jay18001 jay18001 force-pushed the restricted-brick-size branch 5 times, most recently from c018e47 to 5807f71 Compare August 8, 2017 14:43
@jay18001 jay18001 merged commit b304c0d into master Aug 8, 2017
@jay18001 jay18001 deleted the restricted-brick-size branch August 8, 2017 18:22
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.

None yet

3 participants