Skip to content
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

Merged
merged 9 commits into from
Jul 12, 2021
Merged

Add aspectRatio modifier #422

merged 9 commits into from
Jul 12, 2021

Conversation

carson-katri
Copy link
Member

@carson-katri carson-katri commented Jul 8, 2021

This adds the aspectRatio, scaledToFill, and scaledToFit modifiers and the ContentMode enum.

I also added the resizable modifier to Image, and made it respect the specified aspectRatio.

@carson-katri carson-katri changed the base branch from main to custom-font July 8, 2021 16:08
@carson-katri carson-katri added SwiftUI compatibility Tokamak API differences with SwiftUI DOM/HTML renderer Tokamak in the browser and removed DOM/HTML renderer Tokamak in the browser labels Jul 8, 2021
Base automatically changed from custom-font to main July 12, 2021 16:10
@carson-katri carson-katri force-pushed the aspect-ratio branch 2 times, most recently from d91dacf to 1f0c8f6 Compare July 12, 2021 16:33
@carson-katri carson-katri requested a review from a team July 12, 2021 16:54

@inlinable
public init(aspectRatio: CGFloat?, contentMode: ContentMode) {
(self.aspectRatio, self.contentMode) = (aspectRatio, contentMode)
Copy link
Collaborator

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 {
Copy link
Collaborator

@MaxDesiatov MaxDesiatov Jul 12, 2021

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?

Copy link
Member Author

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.

Copy link
Collaborator

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, exactly.

Copy link
Member Author

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 {
Copy link
Collaborator

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?

Suggested change
public class AnyImageProviderBox: AnyTokenBox, Equatable {
public class _AnyImageProviderBox: AnyTokenBox, Equatable {

assertSnapshot(
matching: Ellipse()
.fill(Color.purple)
.aspectRatio(0.75, contentMode: .fit)
Copy link
Collaborator

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?

Copy link
Collaborator

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@carson-katri carson-katri merged commit ff3f81d into main Jul 12, 2021
@carson-katri carson-katri deleted the aspect-ratio branch July 12, 2021 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SwiftUI compatibility Tokamak API differences with SwiftUI
Development

Successfully merging this pull request may close these issues.

2 participants