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

SwiftUI Optimisation #76

Merged
merged 4 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Example/example/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private extension SceneDelegate {
let simulatedLocationManager = SimulatedLocationManager(route: route)
simulatedLocationManager.speedMultiplier = 2

self.viewController.startNavigation(with: route, locationManager: simulatedLocationManager)
self.viewController.startNavigation(with: route, animated: true, locationManager: simulatedLocationManager)
}
}

Expand Down
19 changes: 14 additions & 5 deletions MapboxNavigation/NavigationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@

var currentStatusBarStyle: UIStatusBarStyle = .default {
didSet {
guard oldValue != self.currentStatusBarStyle else { return }

self.mapViewController.instructionsBannerView.backgroundColor = InstructionsBannerView.appearance().backgroundColor
self.mapViewController.instructionsBannerContentView.backgroundColor = InstructionsBannerContentView.appearance().backgroundColor
}
Expand All @@ -228,6 +230,8 @@
*/
public var route: Route? {
didSet {
guard oldValue != self.route else { return }

if let route {
if self.routeController == nil {
let routeController = RouteController(along: route, directions: self.directions, locationManager: self.locationManager)
Expand Down Expand Up @@ -283,6 +287,8 @@
*/
public var routeController: RouteController? {
didSet {
guard oldValue != self.routeController else { return }

self.mapViewController.routeController = self.routeController
}
}
Expand Down Expand Up @@ -313,6 +319,8 @@
*/
public var automaticallyAdjustsStyleForTimeOfDay = true {
didSet {
guard oldValue != self.automaticallyAdjustsStyleForTimeOfDay else { return }

self.styleManager.automaticallyAdjustsStyleForTimeOfDay = self.automaticallyAdjustsStyleForTimeOfDay
}
}
Expand Down Expand Up @@ -427,10 +435,8 @@

// MARK: - NavigationViewController

public func startNavigation(with route: Route, animated: Bool, routeController: RouteController? = nil, locationManager: NavigationLocationManager? = nil) {
if let locationManager {
self.locationManager = locationManager
}
public func startNavigation(with route: Route, animated: Bool, routeController: RouteController? = nil, locationManager: NavigationLocationManager = NavigationLocationManager()) {
self.locationManager = locationManager
if let routeController {
self.routeController = routeController
}
Expand Down Expand Up @@ -467,6 +473,7 @@

self.voiceController = nil
self.route = nil
self.locationManager = NavigationLocationManager()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resets LocationManager in case a SimulatedLocationManager was used


self.mapViewController.navigationView.hideUI(animated: animated)
self.mapView.tracksUserCourse = false
Expand Down Expand Up @@ -649,7 +656,9 @@
guard let self else {
return
}
self.delegate?.navigationViewControllerDidFinishRouting?(self)
self.mapViewController.hideEndOfRoute { _ in
self.delegate?.navigationViewControllerDidFinishRouting?(self)
}
Comment on lines +659 to +661
Copy link
Contributor Author

@Patrick-Kladek Patrick-Kladek Jul 1, 2024

Choose a reason for hiding this comment

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

I've verified that this is called regardless if showsEndOfRouteFeedback is set to true or false.

})
}
return advancesToNextLeg
Expand Down Expand Up @@ -752,14 +761,14 @@
guard UIApplication.shared.applicationState == .background else { return }
guard let text = step.instructionsSpokenAlongStep?.last?.text else { return }

let notification = UILocalNotification()

Check warning on line 764 in MapboxNavigation/NavigationViewController.swift

View workflow job for this annotation

GitHub Actions / Build and Test

'UILocalNotification' was deprecated in iOS 10.0: Use UserNotifications Framework's UNNotificationRequest
notification.alertBody = text
notification.fireDate = Date()

self.clearStaleNotifications()

UIApplication.shared.cancelAllLocalNotifications()

Check warning on line 770 in MapboxNavigation/NavigationViewController.swift

View workflow job for this annotation

GitHub Actions / Build and Test

'cancelAllLocalNotifications()' was deprecated in iOS 10.0: Use UserNotifications Framework's -[UNUserNotificationCenter removeAllPendingNotificationRequests]
UIApplication.shared.scheduleLocalNotification(notification)

Check warning on line 771 in MapboxNavigation/NavigationViewController.swift

View workflow job for this annotation

GitHub Actions / Build and Test

'scheduleLocalNotification' was deprecated in iOS 10.0: Use UserNotifications Framework's -[UNUserNotificationCenter addNotificationRequest:withCompletionHandler:]
}

func clearStaleNotifications() {
Expand Down
Loading