Skip to content

Commit a7b037a

Browse files
authored
Add RoutesPreviewViewController, DestinationPreviewViewController and image resources. Update styles. (#4163)
1 parent 664e4f3 commit a7b037a

34 files changed

+937
-101
lines changed

MapboxNavigation.xcodeproj/project.pbxproj

Lines changed: 80 additions & 4 deletions
Large diffs are not rendered by default.

Sources/MapboxNavigation/BannerContainerView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,12 @@ open class BannerContainerView: UIView {
220220
layoutIfNeeded()
221221

222222
if animated {
223+
// TODO: Improve animation for devices with notch.
223224
switch type {
224225
case .top:
225-
expansionConstraint.constant = -frame.height
226+
expansionConstraint.constant = -frame.height //+ self.topSafeAreaInset
226227
case .bottom:
227-
expansionConstraint.constant = frame.height
228+
expansionConstraint.constant = frame.height //- self.bottomSafeAreaInset
228229
}
229230

230231
isHidden = false

Sources/MapboxNavigation/CameraModeFloatingButton.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ class CameraModeFloatingButton: FloatingButton {
2121
let image: UIImage
2222
switch cameraMode {
2323
case .idle:
24-
image = .recenter
24+
image = .recenterImage
2525
case .centered:
26-
image = .follow
26+
image = .followImage
2727
case .following:
28-
image = .northUp
28+
image = .northUpImage
2929
}
3030

3131
setImage(image, for: .normal)

Sources/MapboxNavigation/DayStyle.swift

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ open class DayStyle: Style {
2727
if let color = UIApplication.shared.delegate?.window??.tintColor {
2828
tintColor = color
2929
} else {
30-
tintColor = .defaultTint
30+
tintColor = .defaultTintColor
3131
}
3232

3333
let phoneTraitCollection = UITraitCollection(userInterfaceIdiom: .phone)
@@ -231,28 +231,45 @@ open class DayStyle: Style {
231231
TimeRemainingLabel.appearance(for: compactAndRegularSizeClassTraitCollection).normalFont = UIFont.systemFont(ofSize: 28.0, weight: .medium).adjustedFont
232232
TimeRemainingLabel.appearance(for: compactAndCompactSizeClassTraitCollection).normalFont = UIFont.systemFont(ofSize: 18.0, weight: .medium).adjustedFont
233233
TimeRemainingLabel.appearance(for: traitCollection).normalFont = UIFont.systemFont(ofSize: 28.0, weight: .medium).adjustedFont
234-
TimeRemainingLabel.appearance(for: traitCollection).normalTextColor = .defaultPrimaryText
234+
TimeRemainingLabel.appearance(for: traitCollection).normalTextColor = .defaultPrimaryTextColor
235235
TimeRemainingLabel.appearance(for: traitCollection).trafficHeavyColor = #colorLiteral(red:0.91, green:0.20, blue:0.25, alpha:1.0)
236236
TimeRemainingLabel.appearance(for: traitCollection).trafficLowColor = #colorLiteral(red: 0.4666666687, green: 0.7647058964, blue: 0.2666666806, alpha: 1)
237237
TimeRemainingLabel.appearance(for: traitCollection).trafficModerateColor = #colorLiteral(red:0.95, green:0.65, blue:0.31, alpha:1.0)
238238
TimeRemainingLabel.appearance(for: traitCollection).trafficSevereColor = #colorLiteral(red: 0.7705719471, green: 0.1753477752, blue: 0.1177056804, alpha: 1)
239-
TimeRemainingLabel.appearance(for: traitCollection).trafficUnknownColor = .defaultPrimaryText
239+
TimeRemainingLabel.appearance(for: traitCollection).trafficUnknownColor = .defaultPrimaryTextColor
240+
241+
TimeRemainingLabel.appearance(for: regularAndRegularSizeClassTraitCollection,
242+
whenContainedInInstancesOf: [RoutesPreviewViewController.self]).normalFont = UIFont.systemFont(ofSize: 28.0, weight: .medium).adjustedFont
243+
TimeRemainingLabel.appearance(for: regularAndCompactSizeClassTraitCollection,
244+
whenContainedInInstancesOf: [RoutesPreviewViewController.self]).normalFont = UIFont.systemFont(ofSize: 28.0, weight: .medium).adjustedFont
245+
TimeRemainingLabel.appearance(for: compactAndRegularSizeClassTraitCollection,
246+
whenContainedInInstancesOf: [RoutesPreviewViewController.self]).normalFont = UIFont.systemFont(ofSize: 28.0, weight: .medium).adjustedFont
247+
TimeRemainingLabel.appearance(for: compactAndCompactSizeClassTraitCollection,
248+
whenContainedInInstancesOf: [RoutesPreviewViewController.self]).normalFont = UIFont.systemFont(ofSize: 20.0, weight: .medium).adjustedFont
240249

241250
StepsTableHeaderView.appearance(for: traitCollection).tintColor = #colorLiteral(red: 0.9675388083, green: 0.9675388083, blue: 0.9675388083, alpha: 1)
242251
StepsTableHeaderView.appearance(for: traitCollection).normalTextColor = #colorLiteral(red: 0.09803921569, green: 0.09803921569, blue: 0.09803921569, alpha: 1)
243252

244-
Button.appearance(for: traitCollection).textColor = .defaultPrimaryText
253+
Button.appearance(for: traitCollection).textColor = .defaultPrimaryTextColor
254+
255+
CancelButton.appearance(for: traitCollection).tintColor = .defaultPrimaryTextColor
245256

246-
CancelButton.appearance(for: traitCollection).tintColor = .defaultPrimaryText
257+
PreviewButton.appearance(for: traitCollection).tintColor = .defaultPrimaryTextColor
258+
StartButton.appearance(for: traitCollection).tintColor = .defaultPrimaryTextColor
247259

248260
FloatingButton.appearance(for: traitCollection).backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
249261
FloatingButton.appearance(for: traitCollection).tintColor = tintColor
250262
FloatingButton.appearance(for: traitCollection).borderWidth = Style.defaultBorderWidth
251-
FloatingButton.appearance(for: traitCollection).borderColor = #colorLiteral(red: 0.737254902, green: 0.7960784314, blue: 0.8705882353, alpha: 1)
263+
FloatingButton.appearance(for: traitCollection).borderColor = .defaultBorderColor
252264

253265
DistanceRemainingLabel.appearance(for: traitCollection).normalFont = UIFont.systemFont(ofSize: 18.0, weight: .medium).adjustedFont
254266
DistanceRemainingLabel.appearance(for: traitCollection).normalTextColor = #colorLiteral(red: 0.431372549, green: 0.431372549, blue: 0.431372549, alpha: 1)
255267

268+
DistanceRemainingLabel.appearance(for: traitCollection,
269+
whenContainedInInstancesOf: [RoutesPreviewViewController.self]).normalFont = UIFont.systemFont(ofSize: 15.0, weight: .medium).adjustedFont
270+
DistanceRemainingLabel.appearance(for: traitCollection,
271+
whenContainedInInstancesOf: [RoutesPreviewViewController.self]).normalTextColor = .defaultPrimaryTextColor
272+
256273
NavigationView.appearance(for: traitCollection).backgroundColor = #colorLiteral(red: 0.764706, green: 0.752941, blue: 0.733333, alpha: 1)
257274

258275
SeparatorView.appearance(for: traitCollection).backgroundColor = #colorLiteral(red: 0.737254902, green: 0.7960784314, blue: 0.8705882353, alpha: 1)
@@ -262,11 +279,18 @@ open class DayStyle: Style {
262279
RatingControl.appearance(for: traitCollection).selectedColor = #colorLiteral(red: 0.1205472574, green: 0.2422055006, blue: 0.3489340544, alpha: 1)
263280

264281
ResumeButton.appearance(for: traitCollection).backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
265-
ResumeButton.appearance(for: traitCollection).tintColor = .defaultPrimaryText
282+
ResumeButton.appearance(for: traitCollection).tintColor = .defaultPrimaryTextColor
266283
ResumeButton.appearance(for: traitCollection).borderColor = #colorLiteral(red: 0.737254902, green: 0.7960784314, blue: 0.8705882353, alpha: 1)
267284
ResumeButton.appearance(for: traitCollection).borderWidth = Style.defaultBorderWidth
268285
ResumeButton.appearance(for: traitCollection).cornerRadius = 5.0
269286

287+
BackButton.appearance(for: traitCollection).backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
288+
BackButton.appearance(for: traitCollection).borderColor = #colorLiteral(red: 0.737254902, green: 0.7960784314, blue: 0.8705882353, alpha: 1)
289+
BackButton.appearance(for: traitCollection).borderWidth = Style.defaultBorderWidth
290+
BackButton.appearance(for: traitCollection).cornerRadius = 5.0
291+
BackButton.appearance(for: traitCollection).textFont = UIFont.systemFont(ofSize: 15, weight: .regular)
292+
BackButton.appearance(for: traitCollection).tintColor = .defaultPrimaryTextColor
293+
270294
NextBannerView.appearance(for: traitCollection).backgroundColor = #colorLiteral(red: 0.9675388083, green: 0.9675388083, blue: 0.9675388083, alpha: 1)
271295
NextBannerView.appearance(for: traitCollection, whenContainedInInstancesOf: [InstructionsCardContainerView.self]).backgroundColor = #colorLiteral(red: 0.9675388083, green: 0.9675388083, blue: 0.9675388083, alpha: 1)
272296

@@ -278,7 +302,19 @@ open class DayStyle: Style {
278302
InstructionsBannerView.appearance(for: traitCollection).backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
279303

280304
ArrivalTimeLabel.appearance(for: traitCollection).normalFont = UIFont.systemFont(ofSize: 18.0, weight: .medium).adjustedFont
281-
ArrivalTimeLabel.appearance(for: traitCollection).normalTextColor = .defaultPrimaryText
305+
ArrivalTimeLabel.appearance(for: traitCollection).normalTextColor = .defaultPrimaryTextColor
306+
307+
ArrivalTimeLabel.appearance(for: traitCollection,
308+
whenContainedInInstancesOf: [RoutesPreviewViewController.self]).normalFont = UIFont.systemFont(ofSize: 15.0, weight: .medium).adjustedFont
309+
ArrivalTimeLabel.appearance(for: traitCollection,
310+
whenContainedInInstancesOf: [RoutesPreviewViewController.self]).normalTextColor = .defaultPrimaryTextColor
311+
312+
DestinationLabel.appearance(for: regularAndRegularSizeClassTraitCollection).normalFont = UIFont.systemFont(ofSize: 25.0, weight: .medium).adjustedFont
313+
DestinationLabel.appearance(for: regularAndCompactSizeClassTraitCollection).normalFont = UIFont.systemFont(ofSize: 25.0, weight: .medium).adjustedFont
314+
DestinationLabel.appearance(for: compactAndRegularSizeClassTraitCollection).normalFont = UIFont.systemFont(ofSize: 25.0, weight: .medium).adjustedFont
315+
DestinationLabel.appearance(for: compactAndCompactSizeClassTraitCollection).normalFont = UIFont.systemFont(ofSize: 18.0, weight: .medium).adjustedFont
316+
DestinationLabel.appearance(for: traitCollection).normalTextColor = .defaultPrimaryTextColor
317+
DestinationLabel.appearance(for: traitCollection).numberOfLines = 2
282318

283319
NextInstructionLabel.appearance(for: traitCollection).normalFont = UIFont.systemFont(ofSize: 20.0, weight: .medium).adjustedFont
284320
NextInstructionLabel.appearance(for: traitCollection).normalTextColor = #colorLiteral(red: 0.09803921569, green: 0.09803921569, blue: 0.09803921569, alpha: 1)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import UIKit
2+
3+
// :nodoc:
4+
public typealias DestinationPreviewing = UIViewController & DestinationDataSource
5+
6+
// :nodoc:
7+
public protocol DestinationDataSource: AnyObject {
8+
9+
var destinationOptions: DestinationOptions { get }
10+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import CoreLocation
2+
import MapboxDirections
3+
4+
// :nodoc:
5+
public struct DestinationOptions {
6+
7+
// :nodoc:
8+
public var primaryText: String?
9+
10+
// :nodoc:
11+
public var secondaryText: String?
12+
13+
// :nodoc:
14+
public private(set) var waypoints: [Waypoint]
15+
16+
// :nodoc:
17+
public init(coordinates: [CLLocationCoordinate2D]) {
18+
let waypoints = coordinates.map({ Waypoint(coordinate: $0) })
19+
self.init(waypoints: waypoints)
20+
}
21+
22+
// :nodoc:
23+
public init(waypoints: [Waypoint]) {
24+
self.waypoints = waypoints
25+
26+
if let destinationName = waypoints.last?.name {
27+
primaryText = destinationName
28+
}
29+
30+
if let destinationCoordinate = waypoints.last?.coordinate {
31+
secondaryText = String(format: "(%.5f, %.5f)",
32+
destinationCoordinate.latitude,
33+
destinationCoordinate.longitude)
34+
}
35+
}
36+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import UIKit
2+
import CoreLocation
3+
import MapboxDirections
4+
5+
// :nodoc:
6+
public class DestinationPreviewViewController: DestinationPreviewing {
7+
8+
var bottomBannerView: BottomBannerView!
9+
10+
var bottomPaddingView: BottomPaddingView!
11+
12+
var destinationLabel: DestinationLabel!
13+
14+
var previewButton: PreviewButton!
15+
16+
var startButton: StartButton!
17+
18+
var verticalSeparatorView: SeparatorView!
19+
20+
var horizontalSeparatorView: SeparatorView!
21+
22+
var trailingSeparatorView: SeparatorView!
23+
24+
weak var delegate: DestinationPreviewViewControllerDelegate?
25+
26+
// MARK: - DestinationPreviewing properties
27+
28+
// :nodoc:
29+
public var destinationOptions: DestinationOptions {
30+
didSet {
31+
if let primaryText = destinationOptions.primaryText {
32+
destinationLabel.attributedText = NSAttributedString(string: primaryText)
33+
}
34+
}
35+
}
36+
37+
required init(_ destinationOptions: DestinationOptions) {
38+
self.destinationOptions = destinationOptions
39+
40+
super.init(nibName: nil, bundle: nil)
41+
}
42+
43+
required init?(coder: NSCoder) {
44+
fatalError("init(coder:) has not been implemented")
45+
}
46+
47+
public override func viewDidLoad() {
48+
super.viewDidLoad()
49+
50+
commonInit()
51+
}
52+
53+
func commonInit() {
54+
setupParentView()
55+
setupStartButton()
56+
setupPreviewButton()
57+
setupDestinationLabel()
58+
setupSeparatorViews()
59+
setupConstraints()
60+
}
61+
62+
func setupParentView() {
63+
bottomBannerView = .forAutoLayout()
64+
bottomPaddingView = .forAutoLayout()
65+
66+
let parentViews: [UIView] = [
67+
bottomBannerView,
68+
bottomPaddingView
69+
]
70+
71+
view.addSubviews(parentViews)
72+
}
73+
74+
func setupDestinationLabel() {
75+
let destinationLabel: DestinationLabel = .forAutoLayout()
76+
view.addSubview(destinationLabel)
77+
78+
self.destinationLabel = destinationLabel
79+
}
80+
81+
func setupPreviewButton() {
82+
let previewButton = PreviewButton(type: .system)
83+
previewButton.translatesAutoresizingMaskIntoConstraints = false
84+
previewButton.clipsToBounds = true
85+
previewButton.setImage(.previewOverviewImage, for: .normal)
86+
previewButton.imageView?.contentMode = .scaleAspectFit
87+
previewButton.addTarget(self, action: #selector(didPressPreviewButton), for: .touchUpInside)
88+
view.addSubview(previewButton)
89+
90+
self.previewButton = previewButton
91+
}
92+
93+
func setupStartButton() {
94+
let startButton = StartButton(type: .system)
95+
startButton.translatesAutoresizingMaskIntoConstraints = false
96+
startButton.clipsToBounds = true
97+
startButton.setImage(.previewStartImage, for: .normal)
98+
startButton.imageView?.contentMode = .scaleAspectFit
99+
startButton.addTarget(self, action: #selector(didPressStartButton), for: .touchUpInside)
100+
view.addSubview(startButton)
101+
102+
self.startButton = startButton
103+
}
104+
105+
func setupSeparatorViews() {
106+
let verticalDividerView: SeparatorView = .forAutoLayout()
107+
bottomBannerView.addSubview(verticalDividerView)
108+
self.verticalSeparatorView = verticalDividerView
109+
110+
let horizontalDividerView: SeparatorView = .forAutoLayout()
111+
bottomBannerView.addSubview(horizontalDividerView)
112+
self.horizontalSeparatorView = horizontalDividerView
113+
114+
let trailingSeparatorView: SeparatorView = .forAutoLayout()
115+
bottomBannerView.addSubview(trailingSeparatorView)
116+
self.trailingSeparatorView = trailingSeparatorView
117+
}
118+
119+
@objc func didPressPreviewButton() {
120+
delegate?.willPreviewRoutes(self)
121+
}
122+
123+
@objc func didPressStartButton() {
124+
delegate?.willStartNavigation(self)
125+
}
126+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
protocol DestinationPreviewViewControllerDelegate: AnyObject {
2+
3+
func willPreviewRoutes(_ destinationPreviewViewController: DestinationPreviewViewController)
4+
5+
func willStartNavigation(_ destinationPreviewViewController: DestinationPreviewViewController)
6+
}

0 commit comments

Comments
 (0)