-
Notifications
You must be signed in to change notification settings - Fork 57
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
Conversation
Please add a description on what this PR does |
Source/Models/BrickDimension.swift
Outdated
case maximumSize(size: BrickDimension) | ||
} | ||
|
||
public struct RestrictedBrickSize { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Source/Models/BrickDimension.swift
Outdated
let restrictedSize: RestrictedSize | ||
|
||
var isEstimate: Bool { | ||
switch size { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Source/Models/BrickDimension.swift
Outdated
var isEstimate: Bool { | ||
switch size { | ||
case .auto(_): return true | ||
default: return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not code covered
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) | ||
} |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
41882bd
to
97529c0
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
return "Basic example of using bricks with a restricted maximum and minimum height" | ||
} | ||
|
||
override func viewDidLoad() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Source/Models/BrickDimension.swift
Outdated
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)) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
c018e47
to
5807f71
Compare
5807f71
to
3025824
Compare
Created a way for bricks to be restricted with a minimum size or maximum size