Repository navigation
Separate traversal from representation with generic fold - #343
Merged
RoyalPineapple merged 1 commit intoJun 23, 2026
Merged
Conversation
RoyalPineapple
force-pushed
the
RoyalPineapple/hierarchy-fold
branch
2 times, most recently
from
June 4, 2026 14:24
fd831fd to
d5b79c2
Compare
RoyalPineapple
force-pushed
the
RoyalPineapple/hierarchy-fold
branch
from
June 22, 2026 13:06
d5b79c2 to
f9c561c
Compare
RoyalPineapple
marked this pull request as ready for review
June 22, 2026 15:54
RoyalPineapple
requested review from
johnnewman-square,
khanlou,
meherkasam,
meherkasam-square,
robmaceachern and
soroushsq
as code owners
June 22, 2026 15:54
RoyalPineapple
force-pushed
the
RoyalPineapple/hierarchy-fold
branch
from
June 22, 2026 18:55
f9c561c to
7ca0b7b
Compare
RoyalPineapple
marked this pull request as draft
June 22, 2026 19:00
RoyalPineapple
force-pushed
the
RoyalPineapple/hierarchy-fold
branch
2 times, most recently
from
June 22, 2026 21:59
8505721 to
9994f1c
Compare
RoyalPineapple
marked this pull request as ready for review
June 22, 2026 22:37
RoyalPineapple
force-pushed
the
RoyalPineapple/hierarchy-fold
branch
from
June 22, 2026 23:58
0859ca5 to
3044db8
Compare
johnnewman-square
approved these changes
Jun 23, 2026
soroushsq
approved these changes
Jun 23, 2026
soroushsq
left a comment
Collaborator
There was a problem hiding this comment.
This is purely additive in terms of APIs, right? The old APIs are composed out of this new one?
Comment on lines
+980
to
+994
| let _: [String] = parser.parseAccessibilityHierarchy( | ||
| in: rootView, | ||
| userInterfaceLayoutDirectionProvider: TestUserInterfaceLayoutDirectionProvider( | ||
| userInterfaceLayoutDirection: .leftToRight | ||
| ), | ||
| userInterfaceIdiomProvider: TestUserInterfaceIdiomProvider(userInterfaceIdiom: .phone), | ||
| makeElement: { elem, index, source in | ||
| capturedElementSource = source | ||
| return "element:\(elem.description)" | ||
| }, | ||
| makeContainer: { cont, children, source in | ||
| capturedContainerSource = source | ||
| return "container:[\(children.joined(separator: ","))]" | ||
| } | ||
| ) |
Collaborator
There was a problem hiding this comment.
Can this one become generic over (String, Source?, Container?). I guess it's not a generic reduce, so it has to return an array of some kind or other?
Collaborator
Author
There was a problem hiding this comment.
it does need to be an outer array but the generic can be a tuple like that, updated the test to use
typealias FoldNode = (label: String, source: NSObject, container: AccessibilityContainer?)
Introduce parseAccessibilityHierarchy<Node>(in:makeElement:makeContainer:), a single bottom-up fold that builds a caller-defined node type in one traversal. makeElement receives the parsed AccessibilityElement, its traversalIndex, and the source accessibility object; makeContainer receives the AccessibilityContainer, its already-built children, and the source object. parseAccessibilityHierarchy(in:) and parseAccessibilityElements(in:) become the default instantiation producing [AccessibilityHierarchy] and ignoring the source.
RoyalPineapple
force-pushed
the
RoyalPineapple/hierarchy-fold
branch
from
June 23, 2026 16:17
3044db8 to
c7d9d0e
Compare
RoyalPineapple
added a commit
to TheButtonHeist/AccessibilitySnapshotBH
that referenced
this pull request
Jun 23, 2026
…l tracking, trait APIs, container actions Rebased onto upstream/main (includes cashapp#330, cashapp#336, cashapp#339, cashapp#342, cashapp#343). Parser features: - elementVisitor/containerVisitor closures on parseAccessibilityElements - _accessibilityIsScrollable SPI for SwiftUI scroll detection - Container index API fallback (resolvedAccessibilityElements) - Modal container preservation (isModalBoundary) - Container membership tracking (elementIndex/elementCount on ContextProvider) - accessibilityCustomActions surfaced on containers - CustomAction promoted from String typealias to struct Trait APIs on UIAccessibilityTraits: - knownTraits, knownTraitNames, traitNames, fromNames
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Separates the tree traversal from the output representation by making
mapNodesToHierarchygeneric.parseAccessibilityHierarchy(in:)becomes a two-line wrapper that calls the fold with closures producingAccessibilityHierarchy. No behavioral change for existing callers.Usage
sourceis the liveNSObjectthat produced the element or container.