Skip to content

Commit

Permalink
Skip map annotation callout when voiceover is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ualch9 committed Sep 19, 2021
1 parent 99b9a59 commit c75ca8d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion OBAKit/Mapping/MapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,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 @@ -440,7 +446,6 @@ public class MapViewController: UIViewController,
}

application.analytics?.reportEvent?(.userAction, label: AnalyticsLabels.mapStopAnnotationTapped, value: nil)

show(stop: 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 @@ -136,4 +138,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 c75ca8d

Please sign in to comment.