Skip to content

Extract ContainerContext and add AccessibilityDescribable protocol#309

Draft
RoyalPineapple wants to merge 3 commits intoa11y-hierarchy-parsingfrom
container-context-refactor
Draft

Extract ContainerContext and add AccessibilityDescribable protocol#309
RoyalPineapple wants to merge 3 commits intoa11y-hierarchy-parsingfrom
container-context-refactor

Conversation

@RoyalPineapple
Copy link
Collaborator

@RoyalPineapple RoyalPineapple commented Feb 3, 2026

Summary

This PR makes accessibility descriptions regenerable from stored data by eliminating NSObject references from the container context.

Motivation

Previously, AccessibilityHierarchyParser.Context held references to live UIKit objects (e.g., UITabBarItem). This meant:

  • Context couldn't be serialized (not Codable)
  • Descriptions could only be generated at parse time
  • No way to regenerate descriptions with different verbosity settings

Solution

1. Extract reference-free ContainerContext

The new AccessibilityElement.ContainerContext stores only primitive data:

  • Series position: (index: Int, count: Int) instead of object references
  • Tab bar items: Just index/count, no UITabBarItem reference
  • Data table cells: Pre-formatted header strings instead of [NSObject]

2. Add AccessibilityDescribable protocol

Unified description generation that works for both:

  • NSObject (live UIKit elements at parse time)
  • AccessibilityElement (stored elements with containerContext)

3. Enable dynamic description regeneration

AccessibilityElement.voiceOverDescription can now recompute the description from stored properties, enabling future verbosity controls.

Also included

  • High-importance AXCustomContent now appears in descriptions (per WWDC21)
  • File rename: UIAccessibility+SnapshotAdditions.swiftUIAccessibility+RotorAdditions.swift

Test plan

  • Unit tests pass
  • ContainerContext serializes to JSON
  • voiceOverDescription regenerates identical descriptions from stored data
  • High-importance custom content appears in descriptions

🤖 Generated with Claude Code

@RoyalPineapple RoyalPineapple force-pushed the container-context-refactor branch from 0526035 to ffc8f11 Compare February 4, 2026 16:04
@RoyalPineapple RoyalPineapple changed the title Extract ContainerContext as public Codable type Add AccessibilityDescribable protocol and hierarchical parsing API Feb 4, 2026
@RoyalPineapple RoyalPineapple force-pushed the container-context-refactor branch from ffc8f11 to 09f2ec8 Compare February 4, 2026 17:16
@RoyalPineapple RoyalPineapple changed the title Add AccessibilityDescribable protocol and hierarchical parsing API Extract ContainerContext and add AccessibilityDescribable protocol Feb 4, 2026
@RoyalPineapple RoyalPineapple force-pushed the a11y-hierarchy-parsing branch 2 times, most recently from f5e9f91 to 99cb260 Compare February 5, 2026 10:48
@RoyalPineapple RoyalPineapple force-pushed the container-context-refactor branch 3 times, most recently from d56de3a to 35c20f3 Compare February 5, 2026 11:35
Introduces `parseAccessibilityHierarchy()` which returns accessibility
data as a tree structure preserving container relationships, compared
to the existing `parseAccessibilityElements()` which returns a flat list.

New types:
- `AccessibilityHierarchy`: Recursive enum with `.element` and `.container` cases
- `AccessibilityContainer`: Container metadata (type, frame, traits)
- `ContainerType`: Enum for semantic groups, lists, landmarks, data tables, tab bars

All types conform to Codable for serialization. The hierarchy can be
flattened back to elements via `flattenToElements()` for compatibility.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
RoyalPineapple and others added 2 commits February 10, 2026 19:53
- Add AccessibilityDescribable protocol for unified VoiceOver description generation
- Extract ContainerContext from internal parser type to public AccessibilityElement.ContainerContext
- Add containerContext property to AccessibilityElement for storing parse-time context
- Add voiceOverDescription computed property to regenerate descriptions from stored properties
- Include high-importance custom content in accessibility descriptions (per WWDC21)
- Rename UIAccessibility+SnapshotAdditions.swift to UIAccessibility+RotorAdditions.swift

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@RoyalPineapple RoyalPineapple force-pushed the container-context-refactor branch from 35c20f3 to 7e7f707 Compare February 10, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments