-
Notifications
You must be signed in to change notification settings - Fork 92
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 junction views marshaling support. #425
Conversation
07c6a54
to
9125c6c
Compare
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.
@@ -34,6 +34,8 @@ public extension VisualInstruction { | |||
*/ | |||
case image(image: ImageRepresentation, alternativeText: TextRepresentation) | |||
|
|||
case guidanceView(image: GuidanceViewImageRepresentation, alternativeText: TextRepresentation) |
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.
Add documentation about this case; otherwise it won’t show up in documentation.
@@ -149,13 +151,29 @@ public extension VisualInstruction.Component { | |||
} | |||
} | |||
|
|||
public struct GuidanceViewImageRepresentation: 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.
ImageRepresentation isn’t meant to be limited to the image
case; it just means that it contains the details for rendering an image. So does this struct, but the difference is in how the URL is interpreted. I wonder if we should try to use ImageRepresentation for both cases but genericize it to make sense in both. If we must have a separate struct, we should probably rename the two structs to better reflect the distinction. Perhaps one would be ScalableImageRepresentation or something to that effect. Needs more thought.
/ref #405 (comment)
9125c6c
to
5215e84
Compare
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.
In addition to the feedback below, please describe the changes in CHANGELOG.md, for example:
- Added the
VisualInstructionBanner.quaternaryInstruction
property andVisualInstruction.Component.guidanceView(image:alternativeText:)
enumeration case to represent a detailed image of an upcoming junction. (#425) - Renamed the
VisualInstruction.Component.ImageRepresentation(imageBaseURL:)
initializer toVisualInstruction.Component.ImageRepresentation(imageBaseURL:availableScales:availableFormats:)
and added theVisualInstruction.Component.ImageRepresentation.availableScales
andVisualInstruction.Component.ImageRepresentation.availableFormats
properties. (#425)
@@ -35,7 +35,12 @@ public extension VisualInstruction { | |||
case image(image: ImageRepresentation, alternativeText: TextRepresentation) | |||
|
|||
/** | |||
The compoment contains the localized word for “Exit”. |
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 for fixing this typo. 😄
/// - imageBaseURL: The image's base URL. | ||
/// - availableScales: The image’s available scale factors. If this argument is unspecified, the current screen’s native scale factor is used. | ||
/// - availableFormats: The available file formats of the image. | ||
public init(imageBaseURL: URL?, availableScales: Set<CGFloat>? = nil, availableFormats: Set<Format>) { |
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.
availableScales
doesn’t have to have a default value, since it’s easy enough to pass in nil
in the couple places that would need to have it be nil
. (It would be necessary to define a default value if we were concerned about backwards-incompatibility, but in that case, availableFormats
would also have a default value.)
@@ -195,14 +235,22 @@ extension VisualInstruction.Component: Codable { | |||
if let imageBaseURLString = try container.decodeIfPresent(String.self, forKey: .imageBaseURL) { | |||
imageBaseURL = URL(string: imageBaseURLString) | |||
} | |||
let imageRepresentation = ImageRepresentation(imageBaseURL: imageBaseURL) | |||
let imageRepresentation = ImageRepresentation(imageBaseURL: imageBaseURL, availableFormats: [.png, .svg]) |
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 representation is available at 1×, 2×, and 3× scales.
@@ -124,11 +159,14 @@ public extension VisualInstruction.Component { | |||
- returns: A remote URL to the image. | |||
*/ | |||
public func imageURL(scale: CGFloat? = nil, format: Format = .png) -> URL? { |
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.
Update the scale
documentation to replace:
Only the values 1, 2, and 3 are currently supported.
with:
Only the values in the
availableScales
property are currently supported.
guard let imageBaseURL = imageBaseURL, | ||
self.availableScales.contains(imageScale), | ||
self.availableFormats.contains(format), |
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: it’s OK to omit self.
here, but not a big deal.
let defaultScales: Set<CGFloat> = [ImageRepresentation.currentScale] | ||
self.availableScales = availableScales ?? defaultScales |
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.
Think of availableScales
as the set of scales that can be explicitly part of the URL, rather than the scale that the image happens to be in. So the default here should be an empty set.
/// Initializes an image representation bearing the image at the given URL. | ||
/// - Parameters: | ||
/// - imageURL: The image URL. | ||
/// - availableScales: The image’s available scale factors. If this argument is unspecified, the current screen’s native scale factor is used. |
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.
If this argument is unspecified, the current screen’s native scale factor is used.
This is true of imageURL(scale:format:)
, but I think it would be better for a nil
availableScales
to mean “don’t append a scale to the URL”.
var imageURLComponents = URLComponents(url: imageBaseURL, resolvingAgainstBaseURL: false) else { | ||
return nil | ||
} | ||
imageURLComponents.path += "@\(Int(scale ?? ImageRepresentation.currentScale))x.\(format)" | ||
imageURLComponents.path += "@\(Int(imageScale))x.\(format)" |
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.
Does the Guidance Views API put @1x
etc. and a file extension in the URL? If not, let’s use an empty availableScales
or availableFormats
set to detect that these things should not be added to the path.
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.
It doesn't its a direct URL that's the reason that I consider if you initialized an image with an imageURL you can use the property instead
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 line is unconditionally adding e.g. @1x.png
to the URL. We should either avoid adding it to the URL or remove it from the URL before initializing the component. Let’s add an assertion to VisualInstructionsTests to verify that the caller of this method will get the same URL that the Directions API returned for a guidance view image.
/// The image's available scales. | ||
public let availableScales: Set<CGFloat> | ||
|
||
/// The image's available formats. | ||
public let availableFormats: Set<Format> |
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.
(Note to self: These properties aren’t being encoded, decoded, and compared explicitly because they’re derived from the component type, which is already being encoded, decoded, and compared.)
|
Co-authored-by: Avi Cieplinski <avi@mapbox.com>
bb3cd33
to
d2d66de
Compare
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.
Just a documentation comment to add, but otherwise good to go. Thanks!
@@ -149,13 +154,29 @@ public extension VisualInstruction.Component { | |||
} | |||
} | |||
|
|||
public struct GuidanceViewImageRepresentation: 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.
GuidanceViewImageRepresentation
still needs to be documented. Otherwise it won’t show up in the docset.
Adds marshaling support for guidance views. This is a port from #405 adds marshaling test and fixes a parsing issue.