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

Integrated new directions API fields with the tertiary instruction and lane indications #1514

Merged
merged 57 commits into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
352f70b
Updated cartfile file with then branch off Directions
vincethecoder Jun 21, 2018
c73c2a3
Changes made to accommodate the new API changes made in instructions …
vincethecoder Jun 21, 2018
f7e88a1
Filtered instructions for visual instruction components to facilitate…
vincethecoder Jun 21, 2018
61287aa
Updates Lane tests upon changes made in both lane and lanes views.
vincethecoder Jun 21, 2018
18be61f
Added a new test for another maneuver.
vincethecoder Jun 21, 2018
e3d839d
Merge branch 'master' into navigation/tertiary_instructions_lane_update
vincethecoder Jun 21, 2018
3a3fc0d
Updated podspec with directions then branch.
vincethecoder Jun 21, 2018
966ec8a
Merge branch 'master' into navigation/tertiary_instructions_lane_update
vincethecoder Jun 21, 2018
4f450cb
Updates to make routecontroller a class property. Removed the extra c…
vincethecoder Jun 22, 2018
409e2fa
Accommodates multiple lane banner instructions.
vincethecoder Jun 22, 2018
37018f8
[Update] Accommodates multiple lane banner instructions.
vincethecoder Jun 22, 2018
d8a0234
Updates to use visualInstructionIndex for visual instructions. Refact…
vincethecoder Jun 23, 2018
7892bff
Updated podspec to point to then branch.
vincethecoder Jun 25, 2018
fa9f08b
Updates to use a published MapboxDirections.swift dependency
vincethecoder Jun 25, 2018
fa1b32c
Merge branch 'master' into navigation/tertiary_instructions_lane_update
vincethecoder Jun 25, 2018
bff3b2f
Fixed issue where component was not being stored and looked up by sam…
vincethecoder Jun 25, 2018
560c8ba
Removed poorly composed unit test for cache key for exit label.
vincethecoder Jun 26, 2018
0bf61ed
Merge branch 'master' into navigation/tertiary_instructions_lane_update
vincethecoder Jun 26, 2018
6c8806e
Updated directions swift with latest changes.
vincethecoder Jun 26, 2018
f074bdd
WIP - added a placeholder to extract critical hash as a property on g…
vincethecoder Jun 26, 2018
2ebd13b
Merge branch 'master' into navigation/tertiary_instructions_lane_update
vincethecoder Jun 27, 2018
fb56051
Extracted the critical hash logic into static functions within the Ex…
vincethecoder Jun 27, 2018
6dc222c
Ensures both the lane view and then banner do not appear at the same …
vincethecoder Jun 28, 2018
67f0ab5
Added a note to indicate the purpose of the conditional statement for…
vincethecoder Jun 28, 2018
a1d71e4
1514 - Modifications to update lanes and next banner views to be hidd…
vincethecoder Jun 29, 2018
b00f946
Added a new visual instruction extension to detect instructions with …
vincethecoder Jul 2, 2018
bdebc16
[GH-1514] Fixed tautology. Deleted unwarranted function to update the…
vincethecoder Jul 2, 2018
abdb380
[GH-1514] - Updated next banner view to detect tertiary instructions …
vincethecoder Jul 2, 2018
8b13242
[GH-1514] - Updated lanes view to detect tertiary instructions with l…
vincethecoder Jul 2, 2018
8f36366
[GH-1514] - Modified instructions banner view signature to accept a n…
vincethecoder Jul 2, 2018
a241dbb
[GH-1514] - Modified to reflect the new (non-required) field, navigat…
vincethecoder Jul 2, 2018
5e3c16d
Merge branch 'master' into navigation/tertiary_instructions_lane_update
vincethecoder Jul 10, 2018
d555b9a
Merge branch 'master' into navigation/tertiary_instructions_lane_update
vincethecoder Jul 10, 2018
5dcc682
Merge branch 'master' into navigation/tertiary_instructions_lane_update
vincethecoder Jul 10, 2018
d755726
[GH-1532] - changes to update the lanes view and next banner view onl…
vincethecoder Jul 10, 2018
f08eb8e
[GH-1514] - points to the master branch of MapboxDirections.swift
vincethecoder Jul 10, 2018
63af724
[GH-1514] - points to the master branch of MapboxDirections.swift
vincethecoder Jul 11, 2018
1dd33da
[GH-1514] - Minor clean up after code refactor.
vincethecoder Jul 11, 2018
76cb369
[GH-1514] - No need to check for distance along step at this point.
vincethecoder Jul 11, 2018
a2c45ab
[GH-1514] - Refactored method signature.
vincethecoder Jul 11, 2018
6b1be17
[GH-1514] - Minor refactor
vincethecoder Jul 11, 2018
291ef60
[GH-1514] - Revised the signature for the updating the visual instruc…
vincethecoder Jul 11, 2018
6af14a8
[GH-1514] - Fixed broken test cases.
vincethecoder Jul 11, 2018
0e25212
[GH-1514] - Revised podspec to use MapboxDirections.swift's master br…
vincethecoder Jul 11, 2018
ba701e6
[GH-1514] - Updated file with the recently published version of Mapbo…
vincethecoder Jul 11, 2018
b6fdc38
Dont hardcode maneuver view to primary instruction
Jul 13, 2018
436889c
Merge branch 'master' into navigation/tertiary_instructions_lane_update
Jul 13, 2018
4ada71c
right
Jul 13, 2018
890f28f
[GH-1514] - Updates to change log to reflect changes to update instru…
vincethecoder Jul 15, 2018
feaf4d9
[GH-1514] - Exposed update(for:) functions to Objective-C. Minor refa…
vincethecoder Jul 16, 2018
13f2d71
Merge branch 'navigation/tertiary_instructions_lane_update' of github…
vincethecoder Jul 16, 2018
27f91a2
[GH-1514] - Updated function with objective-c friendly signature.
vincethecoder Jul 16, 2018
901e229
[GH-1514] - Updated the change log with a more concise description fo…
vincethecoder Jul 16, 2018
11902ca
[GH-1514] - Updated function with objective-c friendly signature.
vincethecoder Jul 16, 2018
6461783
[GH-1514] - Added documentation for the critical hash function for bo…
vincethecoder Jul 16, 2018
a117366
[GH-1514] - Added the missing documentation in the declared class pro…
vincethecoder Jul 16, 2018
00e211a
[GH-1514] - Minor refactor.
vincethecoder Jul 17, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
* Fixed an issue when selecting a step from the steps list, you could be brought to the wrong step. [#1524](https://github.com/mapbox/mapbox-navigation-ios/pull/1524/)
* `StyleManager.locationFor(styleManager:)` now allows for an optional CLLocation to be returned. [#1523](https://github.com/mapbox/mapbox-navigation-ios/pull/1523)
* NavigationViewController now uses the recommended way `.preferredStatusBarStyle` to set the style of the status bar. [#1535](https://github.com/mapbox/mapbox-navigation-ios/pull/1535)
* Deleted `InstructionsBannerView.update(_:)`, which previously updated the banner instruction and the current distance.
* This is replaced with `InstructionsBannerView.updateDistance(for:)` and `InstructionsBannerView.updateInstruction(_:)`. `InstructionsBannerView.updateDistance(for:)` should be called on every location update, while `InstructionsBannerView.updateInstruction(_:)` should be called when `NSNotification.Name. routeControllerDidPassVisualInstructionPoint` is emitted.
* Replaced `InstructionsBannerView.update(_:)`, which previously updated the banner instruction and the current distance, with `InstructionsBannerView.updateDistance(for:)` and `InstructionsBannerView.update(for:)`. Hence, `InstructionsBannerView.updateDistance(for:)` should be called on every location update, while `InstructionsBannerView.update(for:)` should be called when `NSNotification.Name.routeControllerDidPassVisualInstructionPoint` is emitted. [#1514](https://github.com/mapbox/mapbox-navigation-ios/pull/1514)

## v0.18.1 (June 19, 2018)

Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
binary "https://www.mapbox.com/ios-sdk/Mapbox-iOS-SDK.json" ~> 4.1
github "mapbox/MapboxDirections.swift" ~> 0.21.0
github "mapbox/MapboxDirections.swift" ~> 0.22.0
github "mapbox/turf-swift" ~> 0.2
github "mapbox/mapbox-events-ios" ~> 0.4
github "ceeK/Solar" ~> 2.1.0
Expand Down
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
binary "https://www.mapbox.com/ios-sdk/Mapbox-iOS-SDK.json" "4.1.1"
github "Quick/Nimble" "v7.1.2"
github "Quick/Nimble" "v7.1.3"
github "Quick/Quick" "v1.3.0"
github "ceeK/Solar" "2.1.0"
github "mapbox/MapboxDirections.swift" "v0.21.0"
github "mapbox/MapboxDirections.swift" "v0.22.0"
github "mapbox/mapbox-events-ios" "v0.4.2"
github "mapbox/mapbox-voice-swift" "v0.0.1"
github "mapbox/turf-swift" "v0.2.0"
Expand Down
2 changes: 1 addition & 1 deletion Examples/Swift/CustomViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class CustomViewController: UIViewController, MGLMapViewDelegate {

@objc func updateInstructionsBanner(notification: NSNotification) {
guard let routeProgress = notification.userInfo?[RouteControllerNotificationUserInfoKey.routeProgressKey] as? RouteProgress else { return }
instructionsBannerView.updateInstruction(routeProgress.currentLegProgress.currentStepProgress.currentVisualInstruction)
instructionsBannerView.update(for: routeProgress.currentLegProgress.currentStepProgress.currentVisualInstruction)
}

// Fired when the user is no longer on the route.
Expand Down
2 changes: 1 addition & 1 deletion MapboxCoreNavigation.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Pod::Spec.new do |s|
s.requires_arc = true
s.module_name = "MapboxCoreNavigation"

s.dependency "MapboxDirections.swift", "~> 0.21.0"
s.dependency "MapboxDirections.swift", "~> 0.22.0"
s.dependency "MapboxMobileEvents", "~> 0.4"
s.dependency "Turf", "~> 0.2"

Expand Down
4 changes: 2 additions & 2 deletions MapboxCoreNavigationTests/MapboxCoreNavigationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let jsonRoute = (response["routes"] as! [AnyObject]).first as! [String : Any]
let waypoint1 = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 37.795042, longitude: -122.413165))
let waypoint2 = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 37.7727, longitude: -122.433378))
let directions = Directions(accessToken: "pk.feedCafeDeadBeefBadeBede")
let route = Route(json: jsonRoute, waypoints: [waypoint1, waypoint2], routeOptions: NavigationRouteOptions(waypoints: [waypoint1, waypoint2]))
let route = Route(json: jsonRoute, waypoints: [waypoint1, waypoint2], options: NavigationRouteOptions(waypoints: [waypoint1, waypoint2]))

let waitForInterval: TimeInterval = 5

Expand Down Expand Up @@ -108,7 +108,7 @@ class MapboxCoreNavigationTests: XCTestCase {

func testArrive() {
route.accessToken = "foo"
let locations: [CLLocation] = route.coordinates!.map { CLLocation(latitude: $0.latitude, longitude: $0.longitude) }
let locations: [CLLocation] = route.legs.first!.steps.first!.coordinates!.map { CLLocation(latitude: $0.latitude, longitude: $0.longitude) }
let locationManager = ReplayLocationManager(locations: locations)
locationManager.speedMultiplier = 20

Expand Down
6 changes: 3 additions & 3 deletions MapboxCoreNavigationTests/RouteControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ class RouteControllerTests: XCTestCase {
lazy var initialRoute: Route = {
let waypoint1 = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 37.795042, longitude: -122.413165))
let waypoint2 = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 37.7727, longitude: -122.433378))
let route = Route(json: Constants.jsonRoute, waypoints: [waypoint1, waypoint2], routeOptions: NavigationRouteOptions(waypoints: [waypoint1, waypoint2]))
let route = Route(json: Constants.jsonRoute, waypoints: [waypoint1, waypoint2], options: NavigationRouteOptions(waypoints: [waypoint1, waypoint2]))
route.accessToken = Constants.accessToken
return route
}()

lazy var alternateRoute: Route = {
let waypoint1 = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.893922, longitude: -77.023900))
let waypoint2 = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 38.880727, longitude: -77.024888))
let route = Route(json: Constants.jsonRoute, waypoints: [waypoint1, waypoint2], routeOptions: NavigationRouteOptions(waypoints: [waypoint1, waypoint2]))
let route = Route(json: Constants.jsonRoute, waypoints: [waypoint1, waypoint2], options: NavigationRouteOptions(waypoints: [waypoint1, waypoint2]))
route.accessToken = Constants.accessToken
return route
}()
Expand Down Expand Up @@ -162,7 +162,7 @@ class RouteControllerTests: XCTestCase {
let waypoint1 = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 37.795042, longitude: -122.413165))
let waypoint2 = Waypoint(coordinate: CLLocationCoordinate2D(latitude: 37.7727, longitude: -122.433378))
let directions = Directions(accessToken: "pk.feedCafeDeadBeefBadeBede")
let route = Route(json: jsonRoute, waypoints: [waypoint1, waypoint2], routeOptions: NavigationRouteOptions(waypoints: [waypoint1, waypoint2]))
let route = Route(json: jsonRoute, waypoints: [waypoint1, waypoint2], options: NavigationRouteOptions(waypoints: [waypoint1, waypoint2]))

route.accessToken = "foo"
let navigation = RouteController(along: route, directions: directions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let tunnelResponse = Fixture.JSONFromFileNamed(name: TunnelDetectorTestData.nint
let tunnelJsonRoute = (tunnelResponse[TunnelDetectorTestData.kRouteKey] as! [AnyObject]).first as! [String: Any]
let tunnelWayPoint1 = Waypoint(coordinate: TunnelDetectorTestData.startLocation)
let tunnelWaypoint2 = Waypoint(coordinate: TunnelDetectorTestData.endLocation)
let tunnelRoute = Route(json: tunnelJsonRoute, waypoints: [tunnelWayPoint1, tunnelWaypoint2], routeOptions: NavigationRouteOptions(waypoints: [tunnelWayPoint1, tunnelWaypoint2]))
let tunnelRoute = Route(json: tunnelJsonRoute, waypoints: [tunnelWayPoint1, tunnelWaypoint2], options: NavigationRouteOptions(waypoints: [tunnelWayPoint1, tunnelWaypoint2]))

class TunnelIntersectionManagerTests: XCTestCase {

Expand Down
2 changes: 1 addition & 1 deletion MapboxNavigation-Documentation.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Pod::Spec.new do |s|
s.requires_arc = true
s.module_name = "MapboxNavigation"

s.dependency "MapboxDirections.swift", "~> 0.21.0"
s.dependency "MapboxDirections.swift", "~> 0.22.0"
s.dependency "Mapbox-iOS-SDK", "~> 4.1"
s.dependency "MapboxMobileEvents", "~> 0.4"
s.dependency "Solar", "~> 2.1"
Expand Down
4 changes: 4 additions & 0 deletions MapboxNavigation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
8DF399B21FB257B30034904C /* UIGestureRecognizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DF399B11FB257B30034904C /* UIGestureRecognizer.swift */; };
AE00A73A209A2C38006A3DC7 /* StepsViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE00A739209A2C38006A3DC7 /* StepsViewControllerTests.swift */; };
AE291FFF20975A7E00F23DFC /* NavigationViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AED2156E208F7FEA009AA673 /* NavigationViewControllerTests.swift */; };
AE46F95520EA735B00537AC2 /* VisualInstruction.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE46F95420EA735B00537AC2 /* VisualInstruction.swift */; };
AE5F8771209A082500F58FDB /* route-with-banner-instructions.json in Resources */ = {isa = PBXBuildFile; fileRef = AE5F8770209A082500F58FDB /* route-with-banner-instructions.json */; };
AE8B1B95207BFAEF003050F6 /* TunnelIntersectionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE09EC13207BD88200782A33 /* TunnelIntersectionManager.swift */; };
AE8B1B97207D2B2B003050F6 /* TunnelIntersectionManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE8B1B96207D2B2B003050F6 /* TunnelIntersectionManagerTests.swift */; };
Expand Down Expand Up @@ -605,6 +606,7 @@
8DF399B11FB257B30034904C /* UIGestureRecognizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIGestureRecognizer.swift; sourceTree = "<group>"; };
AE00A739209A2C38006A3DC7 /* StepsViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StepsViewControllerTests.swift; sourceTree = "<group>"; };
AE09EC13207BD88200782A33 /* TunnelIntersectionManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelIntersectionManager.swift; sourceTree = "<group>"; };
AE46F95420EA735B00537AC2 /* VisualInstruction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VisualInstruction.swift; sourceTree = "<group>"; };
AE5F8770209A082500F58FDB /* route-with-banner-instructions.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "route-with-banner-instructions.json"; sourceTree = "<group>"; };
AE8B1B96207D2B2B003050F6 /* TunnelIntersectionManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelIntersectionManagerTests.swift; sourceTree = "<group>"; };
AED2156E208F7FEA009AA673 /* NavigationViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationViewControllerTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1134,6 +1136,7 @@
351BEBF01E5BCC63006FE110 /* UIView.swift */,
3512C7C71FB0A0C100CDD2A3 /* UIViewController.swift */,
C5A7EC5B1FD610A80008B9BA /* VisualInstructionComponent.swift */,
AE46F95420EA735B00537AC2 /* VisualInstruction.swift */,
8D391CE11FD71E78006BB91F /* Waypoint.swift */,
35ECAF2C2092275100DC3BC3 /* UIImage.swift */,
353E3C8E20A3501C00FD1789 /* MGLStyle.swift */,
Expand Down Expand Up @@ -1849,6 +1852,7 @@
3531C2701F9E095400D92F9A /* InstructionsBannerView.swift in Sources */,
C5F2DCA1206DBF5E002F99F6 /* Sequence.swift in Sources */,
35DA85791FC45787004092EC /* StatusView.swift in Sources */,
AE46F95520EA735B00537AC2 /* VisualInstruction.swift in Sources */,
35025F3F1F051DD2002BA3EA /* DialogViewController.swift in Sources */,
359A8AEF1FA7B25B00BDB486 /* LanesStyleKit.swift in Sources */,
355ED3701FAB724F00BCE1B8 /* BottomBannerViewLayout.swift in Sources */,
Expand Down
9 changes: 9 additions & 0 deletions MapboxNavigation/ExitView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,13 @@ class ExitView: StylableView {
let labelTrailing = trailingAnchor.constraint(equalTo: exitNumberLabel.trailingAnchor, constant: 8)
return [imageLeading, imageLabelSpacing, labelTrailing]
}

/**
This generates the cache key needed to hold the `ExitView`'s `imageRepresentation` in the `ImageCache` caching engine.
*/
static func criticalHash(side: ExitSide, dataSource: DataSource) -> String {
let proxy = ExitView.appearance()
let criticalProperties: [AnyHashable?] = [side, dataSource.font.pointSize, proxy.backgroundColor, proxy.foregroundColor, proxy.borderWidth, proxy.cornerRadius]
return String(describing: criticalProperties.reduce(0, { $0 ^ ($1?.hashValue ?? 0)}))
}
}
9 changes: 9 additions & 0 deletions MapboxNavigation/GenericRouteShield.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,13 @@ public class GenericRouteShield: StylableView {

addConstraints(constraints)
}

/**
This generates the cache key needed to hold the `GenericRouteShield`'s `imageRepresentation` in the `ImageCache` caching engine.
*/
static func criticalHash(dataSource: DataSource) -> String {
let proxy = GenericRouteShield.appearance()
let criticalProperties: [AnyHashable?] = [dataSource.font.pointSize, proxy.backgroundColor, proxy.foregroundColor, proxy.borderWidth, proxy.cornerRadius]
return String(describing: criticalProperties.reduce(0, { $0 ^ ($1?.hashValue ?? 0)}))
}
}
30 changes: 16 additions & 14 deletions MapboxNavigation/InstructionPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ protocol InstructionPresenterDataSource: class {
var shieldHeight: CGFloat { get }
}

typealias DataSource = InstructionPresenterDataSource

class InstructionPresenter {
typealias DataSource = InstructionPresenterDataSource

private let instruction: VisualInstruction
private weak var dataSource: DataSource?
Expand Down Expand Up @@ -66,7 +67,7 @@ class InstructionPresenter {
typealias AttributedInstructionComponents = (components: [VisualInstructionComponent], attributedStrings: [NSAttributedString])

func attributedPairs(for instruction: VisualInstruction, dataSource: DataSource, imageRepository: ImageRepository, onImageDownload: @escaping ImageDownloadCompletion) -> AttributedInstructionComponents {
let components = instruction.textComponents
let components = instruction.components.compactMap { $0 as? VisualInstructionComponent }
var strings: [NSAttributedString] = []
var processedComponents: [VisualInstructionComponent] = []

Expand Down Expand Up @@ -134,7 +135,7 @@ class InstructionPresenter {

func attributedString(forGenericShield component: VisualInstructionComponent, dataSource: DataSource) -> NSAttributedString? {
guard component.type == .image, let text = component.text else { return nil }
return genericShield(text: text, cacheKey: component.genericCacheKey, dataSource: dataSource)
return genericShield(text: text, component: component, dataSource: dataSource)
}

func attributedString(forShieldComponent shield: VisualInstructionComponent, repository:ImageRepository, dataSource: DataSource, onImageDownload: @escaping ImageDownloadCompletion) -> NSAttributedString? {
Expand Down Expand Up @@ -166,7 +167,10 @@ class InstructionPresenter {
}

private func instructionHasDownloadedAllShields() -> Bool {
for component in instruction.textComponents {
let textComponents = instruction.components.compactMap { $0 as? VisualInstructionComponent }
guard !textComponents.isEmpty else { return false }
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be written more succinctly as:

guard let _ = instruction.components.contains(where: { $0 is VisualInstructionComponent }) else { return false }

Copy link
Contributor

Choose a reason for hiding this comment

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

guard instruction.components.contains(where: { $0 is VisualInstructionComponent }) else { return false } 😏

Copy link
Contributor Author

@vincethecoder vincethecoder Jul 16, 2018

Choose a reason for hiding this comment

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

@1ec5 Indeed that is succinct. However, for the purpose of this function scope, we need the variable and also an early exit if it's empty. Essentially, we need the contents of textComponent to iterate at this line

https://github.com/mapbox/mapbox-navigation-ios/pull/1514/files/13f2d71321b7d5e320721e611c983e6411a2d904#diff-af48d70309ee195e34cc5e6cc6b27caaR173


for component in textComponents {
guard let key = component.cacheKey else {
continue
}
Expand All @@ -189,11 +193,10 @@ class InstructionPresenter {
return NSAttributedString(attachment: attachment)
}

private func genericShield(text: String, cacheKey: String, dataSource: DataSource) -> NSAttributedString? {
let proxy = GenericRouteShield.appearance()
let criticalProperties: [AnyHashable?] = [dataSource.font.pointSize, proxy.backgroundColor, proxy.foregroundColor, proxy.borderWidth, proxy.cornerRadius]
let additionalKey = String(describing: criticalProperties.reduce(0, { $0 ^ ($1?.hashValue ?? 0)}))
private func genericShield(text: String, component: VisualInstructionComponent, dataSource: DataSource) -> NSAttributedString? {
guard let cacheKey = component.cacheKey else { return nil }

let additionalKey = GenericRouteShield.criticalHash(dataSource: dataSource)
let attachment = GenericShieldAttachment()

let key = [cacheKey, additionalKey].joined(separator: "-")
Expand All @@ -212,19 +215,18 @@ class InstructionPresenter {
}

private func exitShield(side: ExitSide = .right, text: String, component: VisualInstructionComponent, dataSource: DataSource) -> NSAttributedString? {
guard let cacheKey = component.cacheKey else { return nil }

let proxy = ExitView.appearance()
let criticalProperties: [AnyHashable?] = [side, dataSource.font.pointSize, proxy.backgroundColor, proxy.foregroundColor, proxy.borderWidth, proxy.cornerRadius]
let additionalKey = String(describing: criticalProperties.reduce(0, { $0 ^ ($1?.hashValue ?? 0)}))
let additionalKey = ExitView.criticalHash(side: side, dataSource: dataSource)
let attachment = ExitAttachment()
guard let cacheKey = component.cacheKey else { return nil }

if let image = imageRepository.cachedImageForKey(cacheKey) {
let key = [cacheKey, additionalKey].joined(separator: "-")
if let image = imageRepository.cachedImageForKey(key) {
attachment.image = image
} else {
let view = ExitView(pointSize: dataSource.font.pointSize, side: side, text: text)
guard let image = takeSnapshot(on: view) else { return nil }
imageRepository.storeImage(image, forKey: [cacheKey, additionalKey].joined(separator: "-"), toDisk: false)
imageRepository.storeImage(image, forKey: key, toDisk: false)
attachment.image = image
}

Expand Down
8 changes: 5 additions & 3 deletions MapboxNavigation/InstructionsBannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ open class BaseInstructionsBannerView: UIControl {
/**
Updates the instructions banner info with a given `VisualInstructionBanner`.
*/
public func updateInstruction(_ instruction: VisualInstructionBanner?) {
@objc(updateForVisualInstructionBanner:)
public func update(for instruction: VisualInstructionBanner?) {
let secondaryInstruction = instruction?.secondaryInstruction
primaryLabel.numberOfLines = secondaryInstruction == nil ? 2 : 1

Expand All @@ -104,15 +105,16 @@ open class BaseInstructionsBannerView: UIControl {
}

primaryLabel.instruction = instruction?.primaryInstruction
maneuverView.visualInstruction = instruction?.primaryInstruction
maneuverView.drivingSide = instruction?.drivingSide ?? .right
secondaryLabel.instruction = secondaryInstruction
maneuverView.visualInstruction = instruction
}

override open func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
maneuverView.isStart = true
let component = VisualInstructionComponent(type: .text, text: "Primary text label", imageURL: nil, abbreviation: nil, abbreviationPriority: NSNotFound)
let instruction = VisualInstruction(text: nil, maneuverType: .none, maneuverDirection: .none, textComponents: [component])
let instruction = VisualInstruction(text: nil, maneuverType: .none, maneuverDirection: .none, components: [component])
primaryLabel.instruction = instruction

distance = 100
Expand Down
10 changes: 10 additions & 0 deletions MapboxNavigation/LaneView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ open class LaneView: UIView {
return isValid ? primaryColor : secondaryColor
}

static let defaultFrame: CGRect = CGRect(origin: .zero, size: 30.0)

convenience init(component: LaneIndicationComponent) {
self.init(frame: LaneView.defaultFrame)
backgroundColor = .clear
lane = Lane(indications: component.indications)
maneuverDirection = ManeuverDirection(description: component.indications.description)
isValid = component.isUsable
}

override open func draw(_ rect: CGRect) {
super.draw(rect)
if let lane = lane {
Expand Down
Loading