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
Remove sizeToFit() from SizeCalculable protocol #164
Conversation
# Conflicts: # Podfile.lock # Sources/PinLayout+Size.swift
sizeToFit()
from SizeCalculable protocol@@ -278,6 +278,8 @@ import AppKit | |||
@discardableResult func aspectRatio() -> PinLayoutObjC | |||
#endif | |||
|
|||
@discardableResult func sizeToFit() -> PinLayoutObjC |
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.
Good catch 👍 We should eventually add more unit tests for objective-c.
} else { | ||
size.width = sizeThatFits.width | ||
} | ||
if case .fitTypeContent = adjustSizeType {} 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.
Icchh if case .fitTypeContent = adjustSizeType {} else {
😬. I would prefer a switch
case here, even if it is longer, it is cleaner.
@antoinelamy does this match also the size computed by UILabel.sizeToFit()? |
# Conflicts: # README.md # Sources/Impl/PinLayout+Layouting.swift # Sources/PinLayout+Size.swift
@lucdion sorry it took forever but I finally got the chance to make the requested changes. About your question wether or not it match the size computed by |
Thanks @antoinelamy 🙂 |
As per the documentation, we should not directly override
sizeToFit()
but rather always only implementsizeThatFits(_:)
for auto-sizing needs. This PR aim to remove thesizeToFit()
requirement in theSizeCalculable
protocol.Internally, UIView has a very basic implementation of the
sizeToFit()
method which is the equivalent of callingsizeThatFits
with the view bounds so instead of calling it directly, we replicate its behaviour inside PinLayout (the implementation is not gonna change anytime soon anyway).The original class look like this in assembly pseudo-code:
Once converted into a more human readable form, the implementation source code look like this: