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/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/Mapping/MapViewController.swift b/OBAKit/Mapping/MapViewController.swift index cb53e9948..e8c0beba8 100644 --- a/OBAKit/Mapping/MapViewController.swift +++ b/OBAKit/Mapping/MapViewController.swift @@ -540,7 +540,6 @@ 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 } 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..0403e8f30 100644 --- a/OBAKit/Mapping/StopAnnotationView.swift +++ b/OBAKit/Mapping/StopAnnotationView.swift @@ -76,6 +76,12 @@ 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") } @@ -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/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() } } 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.