From 6319564e1c1b3d32b9097c007d7d6b519c768e01 Mon Sep 17 00:00:00 2001 From: Adrian Schoenig Date: Fri, 15 Oct 2021 19:40:41 +1100 Subject: [PATCH] Tell VoiceOver that screen changes when pushing or popping (#5) --- Sources/TGCardViewController/TGCardViewController.swift | 2 ++ Sources/TGCardViewController/cards/TGCardView.swift | 6 ++++++ Sources/TGCardViewController/cards/TGPageCardView.swift | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/Sources/TGCardViewController/TGCardViewController.swift b/Sources/TGCardViewController/TGCardViewController.swift index cabecf0..2d4a945 100644 --- a/Sources/TGCardViewController/TGCardViewController.swift +++ b/Sources/TGCardViewController/TGCardViewController.swift @@ -984,6 +984,7 @@ extension TGCardViewController { self.updateForNewPosition(position: animateTo.position) self.updateResponderChainForNewTopCard() self.toggleCardWrappers(hide: cardView == nil) + UIAccessibility.post(notification: .screenChanged, argument: cardView?.preferredView) completionHandler?() } ) @@ -1141,6 +1142,7 @@ extension TGCardViewController { self.updateResponderChainForNewTopCard() self.isPopping = false self.toggleCardWrappers(hide: newTop?.view == nil) + UIAccessibility.post(notification: .screenChanged, argument: topView?.preferredView) completionHandler?() } ) diff --git a/Sources/TGCardViewController/cards/TGCardView.swift b/Sources/TGCardViewController/cards/TGCardView.swift index 1ddea3b..7d6842b 100644 --- a/Sources/TGCardViewController/cards/TGCardView.swift +++ b/Sources/TGCardViewController/cards/TGCardView.swift @@ -70,6 +70,12 @@ public class TGCardView: TGCornerView { return scrollView.frame.minY } + /// The preferred view to select using VoiceOver or similar technologies + /// when this card appears. + public var preferredView: UIView { + titleView ?? self + } + override public func awakeFromNib() { super.awakeFromNib() diff --git a/Sources/TGCardViewController/cards/TGPageCardView.swift b/Sources/TGCardViewController/cards/TGPageCardView.swift index 0d76e1b..4d0f216 100644 --- a/Sources/TGCardViewController/cards/TGPageCardView.swift +++ b/Sources/TGCardViewController/cards/TGPageCardView.swift @@ -38,6 +38,10 @@ class TGPageCardView: TGCardView { (contentView.subviews as? [TGCardView]) ?? [] } + override var preferredView: UIView { + cardViews.first?.preferredView ?? self + } + override var grabHandles: [TGGrabHandleView] { cardViews.compactMap { $0.grabHandle } }