Skip to content

Commit

Permalink
Merge pull request #528 from ualch9/voiceover
Browse files Browse the repository at this point in the history
Skip map annotation callout when voiceover is enabled
  • Loading branch information
aaronbrethorst authored Sep 19, 2021
2 parents 1662d24 + c349d8f commit 819ef6c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
9 changes: 7 additions & 2 deletions OBAKit/Mapping/MapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,12 @@ public class MapViewController: UIViewController,
present(alert, animated: true) {
mapView.deselectAnnotation(view.annotation, animated: true)
}
} else if let stop = view.annotation as? Stop, UIAccessibility.isVoiceOverRunning {
// When VoiceOver is running, StopAnnotationView does not display a callout due to
// VoiceOver limitations with MKMapView. Therefore, we should skip any callouts
// and just go directly to pushing the stop onto the navigation stack.
application.analytics?.reportEvent?(.userAction, label: AnalyticsLabels.mapStopAnnotationTapped, value: nil)
show(stop: stop)
}
}

Expand All @@ -472,8 +478,7 @@ public class MapViewController: UIViewController,
if let stop = view.annotation as? Stop {
application.analytics?.reportEvent?(.userAction, label: AnalyticsLabels.mapStopAnnotationTapped, value: nil)
show(stop: stop)
}
else if let bookmark = view.annotation as? Bookmark {
} else if let bookmark = view.annotation as? Bookmark {
application.analytics?.reportEvent?(.userAction, label: AnalyticsLabels.mapStopAnnotationTapped, value: nil)
show(stop: bookmark.stop)
}
Expand Down
15 changes: 14 additions & 1 deletion OBAKit/Mapping/StopAnnotationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class StopAnnotationView: MKAnnotationView {
rightCalloutAccessoryView = UIButton.chevronButton

annotationSize = ThemeMetrics.defaultMapAnnotationSize
canShowCallout = true
updateAccessibility()

NotificationCenter.default.addObserver(self, selector: #selector(voiceoverStatusDidChange), name: UIAccessibility.voiceOverStatusDidChangeNotification, object: nil)
}

required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
Expand Down Expand Up @@ -151,4 +153,15 @@ class StopAnnotationView: MKAnnotationView {

/// Foreground color for text written directly onto the map as part of this annotation view.
public var mapTextColor: UIColor = ThemeColors.shared.mapText

// MARK: - Accessibility
@objc fileprivate func voiceoverStatusDidChange(_ notification: Notification) {
updateAccessibility()
}

fileprivate func updateAccessibility() {
// Callouts are finicky when in VoiceOver. When VoiceOver is running,
// we should skip the callout and push directly to the annotation's destination view.
canShowCallout = !UIAccessibility.isVoiceOverRunning
}
}

0 comments on commit 819ef6c

Please sign in to comment.