Skip to content

Commit

Permalink
Make support for the preferred view more explicit (#10)
Browse files Browse the repository at this point in the history
Used by VoiceOver when a card is newly presented
  • Loading branch information
nighthawk authored Dec 20, 2021
1 parent 3f2baa0 commit a63c449
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Sources/TGCardViewController/cards/TGCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import UIKit
/// - note: This is a `UIResponder` which is usefulf or supporting per-card
/// keyboard shortcuts. Thusly subclasses NSObject to make it easy to
/// implement various UIKit protocols in subclasses.
open class TGCard: UIResponder {
open class TGCard: UIResponder, TGPreferrableView {

/// Enumeration of supported "title" configurations, i.e., what goes at the
/// top of the card
Expand Down
10 changes: 7 additions & 3 deletions Sources/TGCardViewController/cards/TGCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ public protocol TGInteractiveCardTitle: UIView {

}

public protocol TGPreferrableView {
var preferredView: UIView? { get }
}

/// The view for the card itself.
///
/// Cannot be subclassed, by usually used to programatically update the
/// title/subtitle of the card or to get access to the card's table view or
/// collection view - by checking if an instance of this class is a
/// `TGScrollCardView` instance.
public class TGCardView: TGCornerView {
public class TGCardView: TGCornerView, TGPreferrableView {

/// Each card view needs a grab handle, which the controller
/// might hide and show.
Expand Down Expand Up @@ -72,8 +76,8 @@ public class TGCardView: TGCornerView {

/// The preferred view to select using VoiceOver or similar technologies
/// when this card appears.
public var preferredView: UIView {
titleView ?? self
public var preferredView: UIView? {
(titleView as? TGPreferrableView)?.preferredView ?? titleView ?? self
}

override public func awakeFromNib() {
Expand Down
2 changes: 1 addition & 1 deletion Sources/TGCardViewController/cards/TGPageCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class TGPageCardView: TGCardView {
return cardViews[index]
}

override var preferredView: UIView {
override var preferredView: UIView? {
cardViews.first?.preferredView ?? self
}

Expand Down
17 changes: 16 additions & 1 deletion Sources/TGCardViewController/views/TGCardDefaultTitleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

class TGCardDefaultTitleView: UIView {
class TGCardDefaultTitleView: UIView, TGPreferrableView {

@IBOutlet weak var topLevelStack: UIStackView!
@IBOutlet weak var labelStack: UIStackView!
Expand Down Expand Up @@ -39,6 +39,21 @@ class TGCardDefaultTitleView: UIView {
heightConstraint.isActive = true
}

var preferredView: UIView? {
titleLabel ?? subtitleLabel
}

override var accessibilityElements: [Any]? {
get {
[ dismissButton,
titleLabel,
subtitleLabel,
accessoryViewContainer
].compactMap { $0 }
}
set { }
}

// MARK: - Creating New Views

static func newInstance() -> TGCardDefaultTitleView {
Expand Down

0 comments on commit a63c449

Please sign in to comment.