-
Notifications
You must be signed in to change notification settings - Fork 76
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
Refine UIKit to SwiftUI Measurement Strategies #162
Refine UIKit to SwiftUI Measurement Strategies #162
Conversation
ae075d7
to
54c3a04
Compare
54c3a04
to
3226ed0
Compare
8519841
to
8a287ff
Compare
8a287ff
to
2ca6dc4
Compare
return nsView.measuredFittingSize | ||
} | ||
#endif | ||
} | ||
#endif | ||
|
||
#if swift(>=5.7.1) // Proxy check for being built with the iOS 15 SDK |
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.
Was getting a build error until I bumped this swift version up
// `UILabel.preferredMaxLayoutWidth`. | ||
let intrinsicSize = content.systemLayoutFittingIntrinsicSize() | ||
|
||
// If the view has a intrinsic width and contains a double layout pass subview, give it the |
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 extra measurement pass didn't seem necessary in theory or in practice
@nonobjc | ||
fileprivate func containsDoubleLayoutPassSubviews() -> Bool { | ||
#if os(macOS) | ||
return false | ||
#else | ||
var contains = false | ||
if let label = self as? UILabel, label.preferredMaxLayoutWidth > 0 { | ||
if let label = self as? UILabel, label.numberOfLines != 1 { |
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 can simply check if the label is configured to show multiple lines. No need depending on an extra layout pass to determine if the label can wrap.
7c76ca3
to
b331cfe
Compare
b331cfe
to
2a355a1
Compare
2a355a1
to
35215ce
Compare
This is ready for review now. Happo diffs look more correct when testing in the Airbnb app. |
/// - If the view contains `UILabel` subviews that require a double layout pass as determined by | ||
/// a `preferredMaxLayoutWidth` that's greater than zero after a layout, then the view will | ||
/// default to `intrinsicHeightProposedWidth` to allow the labels to wrap. | ||
/// - If the view contains `UILabel` subviews that require a double layout pass as determined by support multiple lines of text |
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.
wording is a little messed up
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 stuff is so tricky - thanks for figuring it out!
@@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
approach to resolve an issue that could cause collection view cells to layout with | |||
unexpected dimensions | |||
- Made new layout-based SwiftUI cell rendering option the default. | |||
- Fixed an issue where a UIKit view bridged to SwiftUI that wraps would always take up the proposed |
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 guess we fixed it for AppKit too?
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.
TBD, waiting for some updates from @calda since Epoxy iOS doesn't officially support native macOS, but Lottie iOS pulls in the code and uses it directly for macOS.
extension ProposedViewSize { | ||
/// Creates a size by capping infinite values to a significantly large value and replacing `nil`s | ||
/// with `UIView.noIntrinsicMetric` | ||
var viewTypeValue: CGSize { |
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 really understand the "viewType" part of this name
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 a comment to clarify
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.
awesome work @brynbodayle
Change summary
How was it tested?
How did you verify that this change accomplished what you expected? Add more detail as needed.
Pull request checklist
All items in this checklist must be completed before a pull request will be reviewed.
CollectionViewConfiguration
CHANGELOG.md
entry in the "Unreleased" section for any library changes