-
Notifications
You must be signed in to change notification settings - Fork 39
Conversation
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.
Just some little suggestions, great job!
} | ||
|
||
private func animateViews(toProgress progress: Double) { | ||
guard cardView != nil else { return } |
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 cardView is implicitly unwrapped optional, if it can be nil here?
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.
Well, I know it looks weird. The reason behind this is that I didn't want the developer to use a custom initializer, so they could use dequeueReusableCell
. So, they need to call configure
function at the start. However, if they don't do that, views can actually be nil.
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.
Yes, but what is the advantage of implicitly unwrapped optional over optional there?
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.
That's perfect that you asked and pointed that out. Actually, here there shouldn't be guard
as well. We have two options:
- Leaving implicitly unwrapped optional and removing guard. So that it will crash if a developer doesn't initialize views.
- Setting it to optional and then adding guards everywhere and simply showing an empty view.
I think both options are fine. What do you think?
Maybe even the first one is better because in that way they know something gone really wrong :D
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 am also rooting for the first option :D
guard let attributes = super.copy(with: zone) as? CarlensLayoutAttributes else { return super.copy(with: zone) } | ||
attributes.progress = progress | ||
return attributes | ||
} |
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 about use of optional chaining here? Because you still want to return the same value even if casting fails. For example:
override func copy(with zone: NSZone?) -> Any {
let attributes = super.copy(with: zone)
(attributes as? CarlensLayoutAttributes)?.progress = progress
return attributes
}
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.
Perfect suggestion, thanks!
/// SeeAlso: UICollectionViewLayoutAttributes | ||
override func isEqual(_ object: Any?) -> Bool { | ||
guard let attributes = object as? CarlensLayoutAttributes else { return false } | ||
guard attributes.progress == progress else { 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.
Maybe make these two guards into one?
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.
For sure, thanks for spotting this out 👍
Ticket
CRAI-365
Task Description
This task contains extracting code from the CarLens application. It was mostly copied from that place and slightly changed so it could be used outside the app too.
It should be used as follows:
CarlensCollectionViewLayout()
and assign it to their collection view layout.CarlensCollectionViewCell
and initialize theretopView
andcardView
on a start. It should be done with the help ofconfigure
method. If he doesn't a view will be simply empty.Aditional Notes (optional)
It is a minimum viable product at the moment. Eventually, more generic features can be added.