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

Adding generic shield support to instruction banner. #1417

Merged
merged 24 commits into from
May 18, 2018

Conversation

JThramer
Copy link
Contributor

@JThramer JThramer commented May 11, 2018

simulator screen shot - iphone 8 plus - 2018-05-10 at 18 03 09

Adding support for generic shields. Implements #1190. This also has the neat side-effect of rendering normal shields as generic ones until their images load.

To-Do:

  • Fix failing tests
  • Add Testing
  • public-ation
  • revert upstream dependency
  • Changelog entry
  • Document GenericRouteShield
  • Cache GenericRouteShield based upon it's foreground color / text
  • Remove default case from VisualInstructionComponent extension

/cc @mapbox/navigation-ios

@JThramer JThramer self-assigned this May 11, 2018
@JThramer JThramer added feature New feature request. wip labels May 11, 2018
import Foundation
import UIKit

class GenericRouteShield: StylableView {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this class be public, so that developers can customize the colors or roundedness?

} else if let genericShieldString = attributedString(forGenericShield: component, dataSource: dataSource) {
build(component, [joinString, genericShieldString])
} else {
fallthrough
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a clever use of a switch statement, but do you think the fallthroughs inside conditionals make the code flow a little more difficult to keep track of?

Copy link
Contributor Author

@JThramer JThramer May 11, 2018

Choose a reason for hiding this comment

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

@1ec5 It's certainly a complex switch, but I'd make the case that it's a heck of a lot easier to follow than the mess of if statements before it.

I like to think that the fallthrough statements enforce the idea that everything falls-back to text.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to factor this switch out into it's own function? This is function is getting boarder-line large.

@JThramer JThramer force-pushed the jerrad/generic-route-shields branch from 690494f to b2b96ca Compare May 11, 2018 22:03
@bsudekum
Copy link
Contributor

This is looking great!

@JThramer JThramer force-pushed the jerrad/generic-route-shields branch from f637ffb to b2b96ca Compare May 15, 2018 20:16
@JThramer
Copy link
Contributor Author

Posterity: determined that test failures are not due to machine. Bisected work on this branch to find root-cause of test issues. First bad commit found to be fd2a57b37b6d0ce8504dc8468e464de35b5a7cbc. Not super-helpful (lots of stuff happened in that commit), but it's the first step in helping me narrow down the bad behavior.

@JThramer JThramer force-pushed the jerrad/generic-route-shields branch from 5fba7a6 to 5a1f541 Compare May 16, 2018 18:12
Jerrad Thramer added 6 commits May 16, 2018 15:36
…cted, and that they are replaced by actual images as we receive them.

This exposes a bug where we're having cache key issues for generic shields, as the cache is storing the generated generic attachment image as the loaded attachment image's key-value.
Also: Tightening up the timeout values now that things are looking pretty stable.
…are always represented by generic cache keys.
@JThramer JThramer force-pushed the jerrad/generic-route-shields branch from 66a364a to 218f133 Compare May 18, 2018 00:33
view.frame.size = size
FBSnapshotVerifyView(view, tolerance: 0.01)
FBSnapshotVerifyView(view, suffixes: ["_64"], tolerance: tolerance)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks suspect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The suffixes: ["_64"]? That just tells the snapshot framework that we only have reference images in the ReferenceImages_64 folder, so it doesn't try to look in the ReferenceImages_32 folder as a fallback. (Default Behavior)

This basically removes unneeded (since we don't do 32-bit testing) noise from the output log.

import Foundation
import UIKit

public class GenericRouteShield: StylableView {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add documentation for this public class.

import Foundation
import UIKit

public class GenericRouteShield: StylableView {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this class also suffer from #1392 until a hashKey is exposed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. We should also be hashing off the foregroundColor of the GenericRouteShield.

return nil
}
}

var genericCacheKey: String {
return "generic-" + (text ?? "nil")
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there cases we could end up with different shields that have the same cache key, ie generic- because text is nil?

Copy link
Contributor

Choose a reason for hiding this comment

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

A good test case might be, two different steps where the number is given but no text associated with it? Maybe it can't happen but worth checking out.

Copy link
Contributor Author

@JThramer JThramer May 18, 2018

Choose a reason for hiding this comment

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

@bsudekum The InstructionPresenter doesn't try to render Generic Shields with no text, as they would be an empty box. Even so, this code works because one empty box is equal to another.

return "\(imageURL.absoluteString)-\(VisualInstructionComponent.scale)"
case .delimiter:
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

It might make more sense to keep .delimiter here and remove default so as new cases are added, the compiler will yell at us to handle them.

GenericRouteShield.appearance().backgroundColor = .clear
GenericRouteShield.appearance().borderWidth = 1.0
GenericRouteShield.appearance().cornerRadius = 5.0
GenericRouteShield.appearance().foregroundColor = .black
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this look for the night style?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pretty good, all we end up having to do is needing to change the foregroundColor: Line

Example

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh i missed that, 👍

Jerrad Thramer added 3 commits May 18, 2018 16:00
@JThramer JThramer merged commit 6cd26dc into master May 18, 2018
@JThramer JThramer deleted the jerrad/generic-route-shields branch May 18, 2018 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants