-
Notifications
You must be signed in to change notification settings - Fork 45
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
8) Infinite size elements #450
Conversation
|
||
extension CGSize { | ||
/// A size with `infinity` in both dimensions. | ||
public static let infinity = CGSize(width: CGFloat.infinity, height: .infinity) |
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.
One has to love it.
case .legacy: | ||
mode = .useImageSize | ||
case .caffeinated: | ||
mode = .infinite |
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.
Could you unpack this a bit for me?
Given an unconstrained measurement space, Image
now requests infinite layout space. Does that not change the layout behavior of images in these contexts, and therefore any container of these images?
Or is it that .infinite
opts them out of caffeinated layout in a way that leads to the restoration of existing 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.
Given an unconstrained measurement space,
Image
now requests infinite layout space. Does that not change the layout behavior of images in these contexts, and therefore any container of these images?
It does! Practically speaking, there's not that much impact, because the need to measure an element fully unconstrained is somewhat rare.
There's perhaps a semantic change — if you were counting on unconstrained measurement to get you something like an intrinsic size, or SwiftUI's concept of "ideal size", that's no longer possible. But it was never guaranteed to work that way, and would be inconsistent depending on what you measured.
Or is it that
.infinite
opts them out of caffeinated layout in a way that leads to the restoration of existing behavior?
Nope, there's no way to opt out at the element level.
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 this because of the cache hinting optimizations? I guess I would expect for the measurement modes that don't stretch the image, I'd expect to return the size of image, even in an infinite constraint.
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 this because of the cache hinting optimizations?
It's required by the new layout contract, yeah.
I guess I would expect for the measurement modes that don't stretch the image, I'd expect to return the size of image, even in an infinite constraint.
Well, the aspect fit & fill modes already fill space today, even under finite constraints. Given one finite constraint, they'll fill it, no matter how large. So the reasoning is that if the size grows continuously with the constraint, why wouldn't it grow to infinity when the constraint grows to infinity?
We could change the behavior of these modes to return the size of the image without filling space, and that would be compliant too, but it would be a much bigger breaking change to existing layouts.
This is PR 8 in a stack targeting
feature/caffeinated-layout
. See #447.This PR updates existing elements that don't fully adhere to the Caffeinated Layout contract,
Image
andTextField
.Additionally,
ScrollView
has been updated to protect against placing elements into infinite bounds.ScrollView
is uniquely vulnerable to this because it introducesunconstrained
constraints to its subelements. Most elements don't need to worry about this, but for any that do, a new convenience for replacing infinite values onCGSize
can help.