-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Add aspectRatio
modifier
#422
Conversation
d91dacf
to
1f0c8f6
Compare
1f0c8f6
to
3e5568e
Compare
|
||
@inlinable | ||
public init(aspectRatio: CGFloat?, contentMode: ContentMode) { | ||
(self.aspectRatio, self.contentMode) = (aspectRatio, contentMode) |
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.
nit: from coding style perspective I'd prefer it to be on separate lines, just for consistency's sake with the rest of the codebase.
} | ||
} | ||
|
||
private class ResizableProvider: AnyImageProviderBox { |
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.
A bit unsure about this class hierarchy, are we going to have more than one subclass of AnyImageProviderBox
? Maybe we need to document this pattern in our docs? When exactly is the creation of separate box classes is warranted?
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 will likely have something like SystemImageProvider
in the future.
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.
Ah, you mean for something like SF Symbols?
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.
Yeah, exactly.
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.
Those will need to be resolved in the environment so they can access the font and accessibility settings, so I think it makes sense to have it be a token.
@@ -17,27 +17,121 @@ | |||
|
|||
import Foundation | |||
|
|||
public struct Image: _PrimitiveView { | |||
let label: Text? | |||
public class AnyImageProviderBox: AnyTokenBox, Equatable { |
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.
Should this have an underscore prefix to indicate that this shouldn't be re-exported?
public class AnyImageProviderBox: AnyTokenBox, Equatable { | |
public class _AnyImageProviderBox: AnyTokenBox, Equatable { |
assertSnapshot( | ||
matching: Ellipse() | ||
.fill(Color.purple) | ||
.aspectRatio(0.75, contentMode: .fit) |
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.
The PR looks good to me otherwise, but I just noticed that you only test .fit
here, can a case for .fill
also be added?
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.
Thanks!
This adds the
aspectRatio
,scaledToFill
, andscaledToFit
modifiers and theContentMode
enum.I also added the
resizable
modifier toImage
, and made it respect the specifiedaspectRatio
.