From 6fc0a02255e9b1839ab5e804141056f8692e49ef Mon Sep 17 00:00:00 2001 From: Aaron Brethorst Date: Sat, 30 Nov 2024 12:01:24 -0800 Subject: [PATCH 1/4] Fix warnings: No 'async' operations occur within 'await' expression Fixes #765 --- OBAKit/Mapping/MapRegionManager.swift | 2 +- OBAKit/Onboarding/DataMigration/DataMigrationView.swift | 2 +- OBAKit/Orchestration/Application.swift | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/OBAKit/Mapping/MapRegionManager.swift b/OBAKit/Mapping/MapRegionManager.swift index 2517629f2..96b1c35e9 100644 --- a/OBAKit/Mapping/MapRegionManager.swift +++ b/OBAKit/Mapping/MapRegionManager.swift @@ -244,7 +244,7 @@ public class MapRegionManager: NSObject, } } - var mapRegion = await mapView.region + var mapRegion = mapView.region mapRegion.span.latitudeDelta *= preferredLoadDataRegionFudgeFactor mapRegion.span.longitudeDelta *= preferredLoadDataRegionFudgeFactor diff --git a/OBAKit/Onboarding/DataMigration/DataMigrationView.swift b/OBAKit/Onboarding/DataMigration/DataMigrationView.swift index b84d4c0a9..905796d71 100644 --- a/OBAKit/Onboarding/DataMigration/DataMigrationView.swift +++ b/OBAKit/Onboarding/DataMigration/DataMigrationView.swift @@ -105,7 +105,7 @@ public struct DataMigrationView: View, OnboardingView { private func handleReportDismiss() { Task { - await self.dismiss() + self.dismiss() } } diff --git a/OBAKit/Orchestration/Application.swift b/OBAKit/Orchestration/Application.swift index c8c8b9ef6..2dfde5621 100644 --- a/OBAKit/Orchestration/Application.swift +++ b/OBAKit/Orchestration/Application.swift @@ -112,7 +112,7 @@ public class Application: CoreApplication, PushServiceDelegate { } Task(priority: .userInitiated) { - await ProgressHUD.show() + ProgressHUD.show() do { let arrDep = try await apiService.getTripArrivalDepartureAtStop(stopID: deepLink.stopID, tripID: deepLink.tripID, serviceDate: deepLink.serviceDate, vehicleID: deepLink.vehicleID, stopSequence: deepLink.stopSequence).entry @@ -126,7 +126,7 @@ public class Application: CoreApplication, PushServiceDelegate { await self.displayError(error) } - await ProgressHUD.dismiss() + ProgressHUD.dismiss() } } From 5f1d52d408753058b69305e6373b6edf157ad315 Mon Sep 17 00:00:00 2001 From: Aaron Brethorst Date: Sat, 30 Nov 2024 12:19:31 -0800 Subject: [PATCH 2/4] Fix warnings: Main actor-isolated instance method Part of a fix for #764 --- OBAKit/Mapping/MapViewController.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/OBAKit/Mapping/MapViewController.swift b/OBAKit/Mapping/MapViewController.swift index cb53e9948..14ed4adc0 100644 --- a/OBAKit/Mapping/MapViewController.swift +++ b/OBAKit/Mapping/MapViewController.swift @@ -540,13 +540,12 @@ class MapViewController: UIViewController, } } - @MainActor public func mapRegionManager(_ manager: MapRegionManager, showSearchResult response: SearchResponse) { Task { @MainActor [weak self] in guard let self, let result = response.results.first else { return } - + statusOverlay.isHidden = true - + switch result { case let result as MKMapItem: let mapItemController = MapItemViewController(application: application, mapItem: result, delegate: self) From 78ab439f73f301b1a83dae021985ce5b405a45d0 Mon Sep 17 00:00:00 2001 From: Aaron Brethorst Date: Sat, 30 Nov 2024 13:07:32 -0800 Subject: [PATCH 3/4] Fix deprecations: 'traitCollectionDidChange' was deprecated in iOS 17.0 Fixes #761 --- OBAKit/Bookmarks/TripBookmarkCell.swift | 10 +++---- .../VisualEffectsShadow/HoverBar.swift | 28 ++++++++----------- OBAKit/Mapping/PulsingAnnotationView.swift | 14 ++++------ OBAKit/Mapping/StopAnnotationView.swift | 28 +++++++++++-------- OBAKit/Stops/StopHeaderController.swift | 10 +++---- OBAKit/Stops/WalkTimeView.swift | 10 +++---- OBAKit/Trip/TripStopListItem.swift | 9 +++--- OBAKit/Trip/TripViewController.swift | 16 +++++++---- 8 files changed, 63 insertions(+), 62 deletions(-) diff --git a/OBAKit/Bookmarks/TripBookmarkCell.swift b/OBAKit/Bookmarks/TripBookmarkCell.swift index b775db6ca..f9c6993ef 100644 --- a/OBAKit/Bookmarks/TripBookmarkCell.swift +++ b/OBAKit/Bookmarks/TripBookmarkCell.swift @@ -141,6 +141,11 @@ final class TripBookmarkTableCell: OBAListViewCell { isAccessibilityElement = true accessibilityTraits = [.button, .updatesFrequently] + + let sizeTraits: [UITrait] = [UITraitVerticalSizeClass.self, UITraitHorizontalSizeClass.self] + registerForTraitChanges(sizeTraits) { (self: Self, previousTraitCollection: UITraitCollection) in + self.layoutView() + } } required init?(coder aDecoder: NSCoder) { @@ -245,11 +250,6 @@ final class TripBookmarkTableCell: OBAListViewCell { accessibilityValue = nil } - override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { - super.traitCollectionDidChange(previousTraitCollection) - layoutView() - } - override var isHighlighted: Bool { didSet { contentView.backgroundColor = isHighlighted ? ThemeColors.shared.highlightedBackgroundColor : nil diff --git a/OBAKit/Controls/VisualEffectsShadow/HoverBar.swift b/OBAKit/Controls/VisualEffectsShadow/HoverBar.swift index 71c9ccd55..27d90eb12 100755 --- a/OBAKit/Controls/VisualEffectsShadow/HoverBar.swift +++ b/OBAKit/Controls/VisualEffectsShadow/HoverBar.swift @@ -109,24 +109,18 @@ class HoverBarPassThroughView: UIView { shadowView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: blurRadius), shadowView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: -blurRadius) ]) - } - - override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { - super.traitCollectionDidChange(previousTraitCollection) - - if traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) { - transition(to: traitCollection.userInterfaceStyle) - } - } - private func transition(to style: UIUserInterfaceStyle) { - switch style { - case .light, .unspecified: - showShadow = true - case .dark: - showShadow = false - @unknown default: - fatalError() + registerForTraitChanges([UITraitUserInterfaceStyle.self]) { (self: Self, previousTraitCollection: UITraitCollection) in + if self.traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) { + switch self.traitCollection.userInterfaceStyle { + case .light, .unspecified: + self.showShadow = true + case .dark: + self.showShadow = false + @unknown default: + fatalError() + } + } } } diff --git a/OBAKit/Mapping/PulsingAnnotationView.swift b/OBAKit/Mapping/PulsingAnnotationView.swift index aa3bcff37..58da7351b 100644 --- a/OBAKit/Mapping/PulsingAnnotationView.swift +++ b/OBAKit/Mapping/PulsingAnnotationView.swift @@ -118,6 +118,12 @@ class PulsingAnnotationView: MKAnnotationView { layer.anchorPoint = CGPoint(x: 0.5, y: 0.5) calloutOffset = CGPoint(x: 0, y: 4) self.bounds = bounds + + registerForTraitChanges([UITraitUserInterfaceStyle.self]) { (self: Self, previousTraitCollection: UITraitCollection) in + if self.traitCollection.userInterfaceStyle != previousTraitCollection.userInterfaceStyle { + self.rebuildLayers() + } + } } required init?(coder aDecoder: NSCoder) { @@ -162,14 +168,6 @@ class PulsingAnnotationView: MKAnnotationView { } } - override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { - super.traitCollectionDidChange(previousTraitCollection) - - if traitCollection.userInterfaceStyle != previousTraitCollection?.userInterfaceStyle { - rebuildLayers() - } - } - override func willMove(toSuperview newSuperview: UIView?) { if newSuperview != nil { rebuildLayers() diff --git a/OBAKit/Mapping/StopAnnotationView.swift b/OBAKit/Mapping/StopAnnotationView.swift index 1c0b85fc0..209c11aaf 100644 --- a/OBAKit/Mapping/StopAnnotationView.swift +++ b/OBAKit/Mapping/StopAnnotationView.swift @@ -76,10 +76,16 @@ class StopAnnotationView: MKAnnotationView { updateAccessibility() NotificationCenter.default.addObserver(self, selector: #selector(voiceoverStatusDidChange), name: UIAccessibility.voiceOverStatusDidChangeNotification, object: nil) + + registerForTraitChanges([UITraitUserInterfaceStyle.self]) { (self: Self, previousTraitCollection: UITraitCollection) in + if self.traitCollection.userInterfaceStyle != previousTraitCollection.userInterfaceStyle { + self.rebuildIcon() + } + } } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } - + // MARK: - Annotation View Overrides public override func prepareForReuse() { @@ -105,17 +111,6 @@ class StopAnnotationView: MKAnnotationView { } } - override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { - super.traitCollectionDidChange(previousTraitCollection) - - guard - let stop = annotation as? Stop, - let delegate = delegate - else { return } - - image = delegate.iconFactory.buildIcon(for: stop, isBookmarked: delegate.isStopBookmarked(stop), traits: traitCollection) - } - // MARK: - Annotation Rendering private func prepareForDisplay(bookmark: Bookmark, delegate: StopAnnotationDelegate) { @@ -179,4 +174,13 @@ class StopAnnotationView: MKAnnotationView { // we should skip the callout and push directly to the annotation's destination view. canShowCallout = !UIAccessibility.isVoiceOverRunning } + + private func rebuildIcon() { + guard + let stop = annotation as? Stop, + let delegate = delegate + else { return } + + image = delegate.iconFactory.buildIcon(for: stop, isBookmarked: delegate.isStopBookmarked(stop), traits: traitCollection) + } } diff --git a/OBAKit/Stops/StopHeaderController.swift b/OBAKit/Stops/StopHeaderController.swift index 7eb8da4ac..7d4ed89f7 100644 --- a/OBAKit/Stops/StopHeaderController.swift +++ b/OBAKit/Stops/StopHeaderController.swift @@ -149,6 +149,11 @@ class StopHeaderView: UIView { ]) addGestureRecognizer(toggleRouteDetailsGestureRecognizer) + + let sizeTraits: [UITrait] = [UITraitVerticalSizeClass.self, UITraitHorizontalSizeClass.self] + registerForTraitChanges(sizeTraits) { (self: Self, previousTraitCollection: UITraitCollection) in + self.configureView() + } } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } @@ -200,11 +205,6 @@ class StopHeaderView: UIView { self.stackPaddingBottomHeight.constant = suggestedHeight } - override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { - super.traitCollectionDidChange(previousTraitCollection) - self.configureView() - } - @objc private func toggleRouteDetails(_ sender: UITapGestureRecognizer) { isHidingRoutesLabel.toggle() routesLabel.alpha = isHidingRoutesLabel ? 1.0 : 0.0 diff --git a/OBAKit/Stops/WalkTimeView.swift b/OBAKit/Stops/WalkTimeView.swift index cfd938e50..826b60ee7 100644 --- a/OBAKit/Stops/WalkTimeView.swift +++ b/OBAKit/Stops/WalkTimeView.swift @@ -74,6 +74,11 @@ class WalkTimeView: UIView { ]) NotificationCenter.default.addObserver(self, selector: #selector(deviceOrientationDidChange), name: UIDevice.orientationDidChangeNotification, object: nil) + + let sizeTraits: [UITrait] = [UITraitVerticalSizeClass.self, UITraitHorizontalSizeClass.self] + registerForTraitChanges(sizeTraits) { (self: Self, previousTraitCollection: UITraitCollection) in + self.setNeedsDisplay() + } } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } @@ -121,11 +126,6 @@ class WalkTimeView: UIView { return CGSize(width: UIView.noIntrinsicMetric, height: maximumIntrinsicHeight) } - override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { - super.traitCollectionDidChange(previousTraitCollection) - setNeedsDisplay() - } - @objc fileprivate func deviceOrientationDidChange(_ notification: Notification) { setNeedsDisplay() } diff --git a/OBAKit/Trip/TripStopListItem.swift b/OBAKit/Trip/TripStopListItem.swift index a902a6e07..8437f9b0d 100644 --- a/OBAKit/Trip/TripStopListItem.swift +++ b/OBAKit/Trip/TripStopListItem.swift @@ -178,6 +178,10 @@ final class TripStopCell: OBAListViewCell { ]) isAccessibilityElement = true + + registerForTraitChanges([UITraitPreferredContentSizeCategory.self]) { (self: Self, previousTraitCollection: UITraitCollection) in + self.layoutAccessibility() + } } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } @@ -232,11 +236,6 @@ final class TripStopCell: OBAListViewCell { layoutAccessibility() } - override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { - super.traitCollectionDidChange(previousTraitCollection) - layoutAccessibility() - } - func layoutAccessibility() { self.textLabelsStack.axis = isAccessibility ? .vertical : .horizontal self.textLabelSpacerView.isHidden = isAccessibility diff --git a/OBAKit/Trip/TripViewController.swift b/OBAKit/Trip/TripViewController.swift index bc19ad195..d8315e468 100644 --- a/OBAKit/Trip/TripViewController.swift +++ b/OBAKit/Trip/TripViewController.swift @@ -30,6 +30,8 @@ class TripViewController: UIViewController, self.tripConvertible = tripConvertible super.init(nibName: nil, bundle: nil) + + registerTraitChangeCallback() } init(application: Application, arrivalDeparture: ArrivalDeparture) { @@ -37,6 +39,8 @@ class TripViewController: UIViewController, self.tripConvertible = TripConvertible(arrivalDeparture: arrivalDeparture) super.init(nibName: nil, bundle: nil) + + registerTraitChangeCallback() } required init?(coder: NSCoder) { @@ -46,6 +50,13 @@ class TripViewController: UIViewController, deinit { enableIdleTimer() } + + private func registerTraitChangeCallback() { + let sizeTraits: [UITrait] = [UITraitVerticalSizeClass.self, UITraitHorizontalSizeClass.self, UITraitPreferredContentSizeCategory.self] + registerForTraitChanges(sizeTraits) { (self: Self, previousTraitCollection: UITraitCollection) in + self.updateTitleView() + } + } // MARK: - UIViewController @@ -102,11 +113,6 @@ class TripViewController: UIViewController, enableIdleTimer() } - override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { - super.traitCollectionDidChange(previousTraitCollection) - updateTitleView() - } - // MARK: - NSUserActivity /// Creates and assigns an `NSUserActivity` object corresponding to this trip. From 1a60780cfdd5174c41af9a68f2f64b2e469fca93 Mon Sep 17 00:00:00 2001 From: Aaron Brethorst Date: Sat, 30 Nov 2024 13:10:50 -0800 Subject: [PATCH 4/4] Removes errant whitespace --- OBAKit/Mapping/MapViewController.swift | 4 ++-- OBAKit/Mapping/StopAnnotationView.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OBAKit/Mapping/MapViewController.swift b/OBAKit/Mapping/MapViewController.swift index 14ed4adc0..e8c0beba8 100644 --- a/OBAKit/Mapping/MapViewController.swift +++ b/OBAKit/Mapping/MapViewController.swift @@ -543,9 +543,9 @@ class MapViewController: UIViewController, public func mapRegionManager(_ manager: MapRegionManager, showSearchResult response: SearchResponse) { Task { @MainActor [weak self] in guard let self, let result = response.results.first else { return } - + statusOverlay.isHidden = true - + switch result { case let result as MKMapItem: let mapItemController = MapItemViewController(application: application, mapItem: result, delegate: self) diff --git a/OBAKit/Mapping/StopAnnotationView.swift b/OBAKit/Mapping/StopAnnotationView.swift index 209c11aaf..0403e8f30 100644 --- a/OBAKit/Mapping/StopAnnotationView.swift +++ b/OBAKit/Mapping/StopAnnotationView.swift @@ -85,7 +85,7 @@ class StopAnnotationView: MKAnnotationView { } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } - + // MARK: - Annotation View Overrides public override func prepareForReuse() {