-
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
BrickCell width provider #162
Conversation
72430f8
to
5aed4fe
Compare
@@ -106,6 +111,15 @@ open class BaseBrickCell: UICollectionViewCell { | |||
open override func layoutSubviews() { | |||
super.layoutSubviews() | |||
brickBackgroundView?.frame = self.bounds | |||
|
|||
if frame.width == requestedWidth { | |||
self.layoutIfNeeded() // This layoutIfNeeded is added to make sure that the subviews are laid out correctly |
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.
Is that called by super.layoutSubviews()
?
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 don't think I understand the question
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.
This is fine
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.
Does calling layoutIfNeeded(), also call layoutSubviews()? or does the "if needed" mean only if self.bounds has changed? Just trying to make sure that there isn't a condition that this can get into an infinite loop.
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 won't. The reason it's there is that when the view is laid out, the subviews aren't at this case. If we remove this line, the unit tests will fail
open override func framesDidLayout() { | ||
super.framesDidLayout() | ||
|
||
guard let genericContentView = genericContentView as? UpdateFramesListener 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.
This would be cleaner as an if let
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.
Agreed. Fixing
On layoutSubviews, the cell will now verify if the width of the frame is equal to the expected width. If so, `framesDidLayout` will be called. This way, the brick can get informed that the frames are set correctly and images etc can be fetched. Fixes #161
5aed4fe
to
d7cfc31
Compare
Codecov Report
@@ Coverage Diff @@
## master #162 +/- ##
=========================================
Coverage ? 93.42%
=========================================
Files ? 39
Lines ? 4107
Branches ? 333
=========================================
Hits ? 3837
Misses ? 269
Partials ? 1
Continue to review full report at Codecov.
|
On layoutSubviews, the cell will now verify if the width of the frame is equal to the expected width. If so,
framesDidLayout
will be called. This way, the brick can get informed that the frames are set correctly and images etc can be fetched.Fixes #161