Skip to content

Commit e7eabfc

Browse files
authored
Use the singleton of SpriteRepository for instructions and road name label. (#3864)
1 parent 0f516df commit e7eabfc

28 files changed

+333
-253
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* `UserPuckCourseView` no longer desaturates its color based on the age of the last location update. `RouteController` simulates location updates whenever Location Services is unable to receive real location updates. To ensure a steady stream of location updates outside of turn-by-turn navigation, install a `PassiveLocationManager`. ([#3836](https://github.com/mapbox/mapbox-navigation-ios/pull/3836))
2020
* Fixed an issue where shields disappeared after the application returns to the foreground. ([#3840](https://github.com/mapbox/mapbox-navigation-ios/pull/3840))
2121
* Fixed an issue where `EndOfRouteCommentView` is using dark style when only light style is allowed. ([#3845](https://github.com/mapbox/mapbox-navigation-ios/pull/3845))
22+
* Fixed an issue where exit views and generic shields in top banner don't get updated when style changes in active navigation. ([#3864](https://github.com/mapbox/mapbox-navigation-ios/pull/3864))
2223

2324
### CarPlay
2425

Sources/MapboxNavigation/CarPlayNavigationViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ open class CarPlayNavigationViewController: UIViewController, BuildingHighlighti
398398
setupStyleManager()
399399

400400
observeNotifications(navigationService)
401-
updateManeuvers(navigationService.routeProgress)
402401
navigationService.start()
403402
carPlayManager.delegate?.carPlayManager(carPlayManager, didBeginNavigationWith: navigationService)
404403
currentLegIndexMapped = navigationService.router.routeProgress.legIndex
@@ -838,6 +837,7 @@ extension CarPlayNavigationViewController: StyleManagerDelegate {
838837
mapboxMapStyle?.uri = styleURI
839838
// Update the sprite repository of wayNameView when map style changes.
840839
wayNameView?.label.updateStyle(styleURI: styleURI)
840+
updateManeuvers(navigationService.routeProgress)
841841
}
842842
}
843843

Sources/MapboxNavigation/DayStyle.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,14 @@ open class DayStyle: Style {
245245
FeedbackStyleView.appearance(whenContainedInInstancesOf: [FeedbackViewController.self]).backgroundColor = .white
246246
FeedbackCollectionView.appearance().backgroundColor = .white
247247
FeedbackCollectionView.appearance().cellColor = .black
248+
InstructionLabel.appearance().roadShieldBlackColor = .roadShieldBlackColor
249+
InstructionLabel.appearance().roadShieldBlueColor = .roadShieldBlueColor
250+
InstructionLabel.appearance().roadShieldGreenColor = .roadShieldGreenColor
251+
InstructionLabel.appearance().roadShieldRedColor = .roadShieldRedColor
252+
InstructionLabel.appearance().roadShieldWhiteColor = .roadShieldWhiteColor
253+
InstructionLabel.appearance().roadShieldYellowColor = .roadShieldYellowColor
254+
InstructionLabel.appearance().roadShieldOrangeColor = .roadShieldOrangeColor
255+
InstructionLabel.appearance().roadShieldDefaultColor = .roadShieldDefaultColor
248256

249257
#if swift(>=5.5)
250258
if #available(iOS 15.0, *) {

Sources/MapboxNavigation/ExitView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public class ExitView: StylableView {
145145
This generates the cache key needed to hold the `ExitView`'s `imageRepresentation` in the `ImageCache` caching engine.
146146
*/
147147
static func criticalHash(side: ExitSide,
148+
styleID: String?,
148149
dataSource: DataSource,
149150
traitCollection: UITraitCollection) -> String {
150151
var appearance = ExitView.appearance()
@@ -163,6 +164,7 @@ public class ExitView: StylableView {
163164

164165
var criticalProperties: [AnyHashable?] = [
165166
side,
167+
styleID,
166168
dataSource.font.pointSize,
167169
appearance.backgroundColor,
168170
appearance.foregroundColor,

Sources/MapboxNavigation/GenericRouteShield.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public class GenericRouteShield: StylableView {
9494
/**
9595
This generates the cache key needed to hold the `GenericRouteShield`'s `imageRepresentation` in the `ImageCache` caching engine.
9696
*/
97-
static func criticalHash(dataSource: DataSource, traitCollection: UITraitCollection) -> String {
97+
static func criticalHash(styleID: String?, dataSource: DataSource, traitCollection: UITraitCollection) -> String {
9898
var appearance = GenericRouteShield.appearance()
9999
if traitCollection.userInterfaceIdiom == .carPlay {
100100
if #available(iOS 12.0, *) {
@@ -110,6 +110,7 @@ public class GenericRouteShield: StylableView {
110110
}
111111

112112
var criticalProperties: [AnyHashable?] = [
113+
styleID,
113114
dataSource.font.pointSize,
114115
appearance.backgroundColor,
115116
appearance.foregroundColor,

Sources/MapboxNavigation/InstructionLabel.swift

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import MapboxDirections
44

55
/// :nodoc:
66
open class InstructionLabel: StylableLabel, InstructionPresenterDataSource {
7+
@objc dynamic var roadShieldBlackColor: UIColor = .roadShieldBlackColor
8+
@objc dynamic var roadShieldBlueColor: UIColor = .roadShieldBlueColor
9+
@objc dynamic var roadShieldGreenColor: UIColor = .roadShieldGreenColor
10+
@objc dynamic var roadShieldRedColor: UIColor = .roadShieldRedColor
11+
@objc dynamic var roadShieldWhiteColor: UIColor = .roadShieldWhiteColor
12+
@objc dynamic var roadShieldYellowColor: UIColor = .roadShieldYellowColor
13+
@objc dynamic var roadShieldOrangeColor: UIColor = .roadShieldOrangeColor
14+
@objc dynamic var roadShieldDefaultColor: UIColor = .roadShieldDefaultColor
715

816
typealias AvailableBoundsHandler = () -> (CGRect)
917
var availableBounds: AvailableBoundsHandler!
@@ -12,48 +20,66 @@ open class InstructionLabel: StylableLabel, InstructionPresenterDataSource {
1220
// displayed. The bounds of `InstructionLabel` will be used if this view is unset.
1321
weak var viewForAvailableBoundsCalculation: UIView?
1422
var shieldHeight: CGFloat = 30
15-
var imageRepository: ImageRepository = .shared
1623
var imageDownloadCompletion: (() -> Void)?
1724
weak var instructionDelegate: VisualInstructionDelegate?
1825

1926
var instruction: VisualInstruction? {
2027
didSet {
21-
guard let instruction = instruction else {
22-
text = nil
23-
instructionPresenter = nil
24-
return
25-
}
26-
let update: InstructionPresenter.ShieldDownloadCompletion = { [weak self] (attributedText) in
27-
guard let self = self else { return }
28-
self.attributedText = attributedText
29-
self.imageDownloadCompletion?()
30-
}
31-
32-
let presenter = InstructionPresenter(instruction,
33-
dataSource: self,
34-
imageRepository: imageRepository,
35-
traitCollection: traitCollection,
36-
downloadCompletion: update)
37-
38-
let attributed = presenter.attributedText()
39-
attributedText = instructionDelegate?.label(self, willPresent: instruction, as: attributed) ?? attributed
40-
instructionPresenter = presenter
28+
updateLabelAttributedText()
4129
}
4230
}
31+
32+
private func updateLabelAttributedText() {
33+
guard let instruction = instruction else {
34+
text = nil
35+
return
36+
}
37+
38+
let update: InstructionPresenter.ShieldDownloadCompletion = { [weak self] (attributedText) in
39+
guard let self = self else { return }
40+
self.attributedText = attributedText
41+
self.imageDownloadCompletion?()
42+
}
43+
44+
let presenter = InstructionPresenter(instruction,
45+
dataSource: self,
46+
traitCollection: traitCollection,
47+
downloadCompletion: update)
48+
49+
let attributed = presenter.attributedText()
50+
attributedText = instructionDelegate?.label(self, willPresent: instruction, as: attributed) ?? attributed
51+
}
4352

4453
open override func update() {
45-
let previousInstruction = instruction
46-
instruction = previousInstruction
54+
updateLabelAttributedText()
4755
super.update()
4856
}
4957

5058
open override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
5159
super.traitCollectionDidChange(previousTraitCollection)
5260
update()
53-
imageRepository.resetImageCache(nil)
5461
}
5562

56-
private var instructionPresenter: InstructionPresenter?
63+
func shieldColor(from textColor: String) -> UIColor {
64+
switch textColor {
65+
case "black":
66+
return roadShieldBlackColor
67+
case "blue":
68+
return roadShieldBlueColor
69+
case "green":
70+
return roadShieldGreenColor
71+
case "red":
72+
return roadShieldRedColor
73+
case "white":
74+
return roadShieldWhiteColor
75+
case "yellow":
76+
return roadShieldYellowColor
77+
case "orange":
78+
return roadShieldOrangeColor
79+
default:
80+
return roadShieldDefaultColor
81+
}
82+
}
5783
}
5884

5985
/// :nodoc:

0 commit comments

Comments
 (0)