Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,223 changes: 1,211 additions & 12 deletions Example/UnitTests/AccessibilityHierarchyParserTests.swift

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public struct SwiftUIAccessibilitySnapshotView<Content: View>: View {
viewRenderingMode: .drawHierarchyInRect
)
let parser = AccessibilityHierarchyParser()
let markers = parser.parseAccessibilityElements(in: hostingController.view)
let markers = parser.parseAccessibilityHierarchy(in: hostingController.view).flattenToElements()

displayMarkers = markers.map { marker in
DisplayMarker(marker: marker)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public struct AccessibilitySnapshotConfiguration {
/// Controls when to show elements' accessibility user input labels (used by Voice Control). Defaults to `.whenOverridden`.
public let inputLabelDisplayMode: AccessibilityContentDisplayMode

/// Controls what information is included in accessibility descriptions.
/// Defaults to `.verbose` which matches default VoiceOver behavior.
public let verbosity: VerbosityConfiguration

// MARK: - Initialization

/// Creates a new accessibility snapshot configuration.
Expand All @@ -73,20 +77,23 @@ public struct AccessibilitySnapshotConfiguration {
/// - includesInputLabels: When to show accessibility user input labels. Defaults to `.whenOverridden`.
/// - includesCustomRotors: When to show accessibility custom rotors and their contents. Defaults to `.whenOverridden`.
/// - rotorResultLimit: Maximum number of rotor results to collect in each direction. Defaults to `10`.
/// - verbosity: Controls what information is included in accessibility descriptions. Defaults to `.verbose`.
public init(
viewRenderingMode: ViewRenderingMode,
colorRenderingMode: ColorRenderingMode = .monochrome,
overlayColors: [UIColor] = MarkerColors.defaultColors,
activationPointDisplay: AccessibilityContentDisplayMode = .whenOverridden,
includesInputLabels: AccessibilityContentDisplayMode = .whenOverridden,
includesCustomRotors: AccessibilityContentDisplayMode = .whenOverridden,
rotorResultLimit: Int = AccessibilityMarker.defaultRotorResultLimit
rotorResultLimit: Int = AccessibilityMarker.defaultRotorResultLimit,
verbosity: VerbosityConfiguration = .verbose
) {
rendering = Rendering(renderMode: viewRenderingMode, colorMode: colorRenderingMode)
rotors = Rotors(displayMode: includesCustomRotors, resultLimit: rotorResultLimit)
markerColors = overlayColors.isEmpty ? MarkerColors.defaultColors : overlayColors
activationPointDisplayMode = activationPointDisplay
inputLabelDisplayMode = includesInputLabels
self.verbosity = verbosity
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public final class AccessibilitySnapshotView: SnapshotAndLegendView {
containedView.layoutIfNeeded()

let parser = AccessibilityHierarchyParser()
let markers = parser.parseAccessibilityElements(in: containedView, rotorResultLimit: snapshotConfiguration.rotors.resultLimit)
let markers = parser.parseAccessibilityHierarchy(in: containedView, rotorResultLimit: snapshotConfiguration.rotors.resultLimit, verbosity: snapshotConfiguration.verbosity).flattenToElements()

var displayMarkers: [DisplayMarker] = []
for (index, marker) in markers.enumerated() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import CoreGraphics

/// Information about a container node
public struct AccessibilityContainer: Equatable, Codable {
/// The type of accessibility container with its associated data
public enum ContainerType: Equatable, Codable {
/// A semantic grouping with optional label, value, and identifier
case semanticGroup(label: String?, value: String?, identifier: String?)

/// A list container (affects rotor navigation)
case list

/// A landmark container (affects rotor navigation)
case landmark

/// A data table with row and column counts
case dataTable(rowCount: Int, columnCount: Int)

/// A tab bar container (detected via .tabBar trait)
case tabBar
}

/// The type of container with its associated data
public let type: ContainerType

/// Container's frame in the root view's coordinate space (for visualization)
public let frame: CGRect

public init(type: ContainerType, frame: CGRect) {
self.type = type
self.frame = frame
}
}
Loading
Loading