@@ -193,7 +193,7 @@ function walkUiHierarchyNode(
193193 const currentIndex = include
194194 ? appendAndroidSnapshotNode ( state , node , parentIndex , systemChrome )
195195 : parentIndex ;
196- const nextAncestorHittable = ancestorHittable || Boolean ( node . hittable ) ;
196+ const nextAncestorHittable = ancestorHittable || isAgentTarget ( node ) ;
197197 const nextAncestorCollection = ancestorCollection || isCollectionContainerType ( node . type ) ;
198198 for ( const child of node . children ) {
199199 walkUiHierarchyNode (
@@ -232,7 +232,7 @@ function appendAndroidSnapshotNode(
232232 enabled : node . enabled ,
233233 focused : node . focused ,
234234 visibleToUser : node . visibleToUser ,
235- hittable : node . hittable ,
235+ hittable : isAgentTarget ( node ) || undefined ,
236236 depth : compactedAndroidNodeDepth ( state . nodes , parentIndex ) ,
237237 parentIndex,
238238 ...( node . hiddenContentAbove ? { hiddenContentAbove : true } : { } ) ,
@@ -255,7 +255,7 @@ function hasInteractiveDescendant(state: AndroidSnapshotBuildState, node: Androi
255255 for ( const child of node . children ) {
256256 if (
257257 child . visibleToUser !== false &&
258- ( child . hittable || hasInteractiveDescendant ( state , child ) )
258+ ( isAgentTarget ( child ) || hasInteractiveDescendant ( state , child ) )
259259 ) {
260260 state . interactiveDescendantMemo . set ( node , true ) ;
261261 return true ;
@@ -421,8 +421,11 @@ export type AndroidUiHierarchy = {
421421 visibleToUser ?: boolean ;
422422 drawingOrder ?: number ;
423423 focused ?: boolean ;
424- hittable ?: boolean ;
425- clickable ?: boolean ;
424+ // Two independent facts, never collapsed, and never undefined: the helper omits false attributes
425+ // while stock UiAutomator writes them out, so reading an absent attribute as a value gave two
426+ // encodings of one control opposite answers.
427+ clickable : boolean ;
428+ focusable : boolean ;
426429 depth : number ;
427430 parentIndex ?: number ;
428431 hiddenContentAbove ?: boolean ;
@@ -467,6 +470,8 @@ export function parseUiHierarchyTree(xml: string): AndroidUiHierarchy {
467470 value : null ,
468471 identifier : null ,
469472 packageName : null ,
473+ clickable : false ,
474+ focusable : false ,
470475 depth : - 1 ,
471476 children : [ ] ,
472477 } ;
@@ -493,8 +498,8 @@ export function parseUiHierarchyTree(xml: string): AndroidUiHierarchy {
493498 focused : attrs . focused ,
494499 visibleToUser : attrs . visibleToUser ,
495500 drawingOrder : attrs . drawingOrder ,
496- hittable : attrs . clickable ?? attrs . focusable ,
497- clickable : attrs . clickable ,
501+ clickable : attrs . clickable === true ,
502+ focusable : attrs . focusable === true ,
498503 scrollable : attrs . scrollable ,
499504 canScrollForward : attrs . canScrollForward ,
500505 canScrollBackward : attrs . canScrollBackward ,
@@ -525,6 +530,53 @@ export function parseUiHierarchyTree(xml: string): AndroidUiHierarchy {
525530 return root ;
526531}
527532
533+ /** A node a touch can act on. */
534+ function isTouchTarget ( node : AndroidNode ) : boolean {
535+ return node . clickable ;
536+ }
537+
538+ /** A node D-pad/keyboard traversal can land on. Normal for TV controls, which are rarely clickable. */
539+ function isFocusTarget ( node : AndroidNode ) : boolean {
540+ return node . focusable || node . focused === true ;
541+ }
542+
543+ /** A node an agent can drive by either input model. This is what the public `hittable` projects. */
544+ function isAgentTarget ( node : AndroidNode ) : boolean {
545+ return isTouchTarget ( node ) || isFocusTarget ( node ) ;
546+ }
547+
548+ /** Text or an address an agent can read or select by. */
549+ function hasSemanticContent ( node : AndroidNode ) : boolean {
550+ return hasMeaningfulLabel ( node ) || hasMeaningfulIdentifier ( node ) ;
551+ }
552+
553+ /** Focusability is traversal, not paint, so it is not evidence a node hides anything (#1733). */
554+ function hasDirectOcclusionEvidence ( node : AndroidNode ) : boolean {
555+ return node . visibleToUser !== false && ( isTouchTarget ( node ) || hasSemanticContent ( node ) ) ;
556+ }
557+
558+ /** Evidence the node is a real surface because it contains something an agent could drive. */
559+ function hasDescendantOcclusionEvidence ( node : AndroidNode , state : AndroidTreePruneState ) : boolean {
560+ const cached = state . actionableContentMemo . get ( node ) ;
561+ if ( cached !== undefined ) return cached ;
562+ const result = node . children . some (
563+ ( child ) =>
564+ child . visibleToUser !== false &&
565+ ( isAgentTarget ( child ) || hasDescendantOcclusionEvidence ( child , state ) ) ,
566+ ) ;
567+ state . actionableContentMemo . set ( node , result ) ;
568+ return result ;
569+ }
570+
571+ /**
572+ * A childless sibling that only presents: an RN screen-level testID, or a label drawn inside a
573+ * higher sibling's box (Telegram's `+` over the country-code EditText). Geometry cannot tell a
574+ * transparent overlay from an opaque one, and exempting a leaf cannot resurrect a covered surface.
575+ */
576+ function isPresentationLeaf ( node : AndroidNode ) : boolean {
577+ return node . children . length === 0 && ! isAgentTarget ( node ) && hasSemanticContent ( node ) ;
578+ }
579+
528580function pruneAndroidInvisibleSubtrees ( node : AndroidNode ) : void {
529581 let keptCount = 0 ;
530582 for ( const child of node . children ) {
@@ -556,24 +608,10 @@ function shouldKeepAndroidSibling(
556608 coveringCandidates : AndroidCoveringCandidate [ ] ,
557609) : boolean {
558610 return (
559- isUncondemnableLeaf ( node ) || ! isCoveredByHigherDrawingOrderSibling ( node , coveringCandidates )
611+ isPresentationLeaf ( node ) || ! isCoveredByHigherDrawingOrderSibling ( node , coveringCandidates )
560612 ) ;
561613}
562614
563- /**
564- * A childless, non-hittable sibling that announces something of its own: the screen-level testID RN
565- * emits beside its rendered navigator, or a composite widget's label drawn inside a higher sibling's
566- * box (Telegram renders the `+` of `+1` as a TextView overlapping the country-code EditText).
567- * Drawing order and geometry cannot tell a transparent overlay from an opaque one, and text an agent
568- * never sees is the one loss it cannot recover from. Staying on the `hittable` contract keeps a
569- * genuinely covered affordance condemned; exempting a leaf is bounded — it can never resurrect a
570- * covered surface.
571- */
572- function isUncondemnableLeaf ( node : AndroidNode ) : boolean {
573- if ( node . children . length > 0 || node . hittable ) return false ;
574- return hasMeaningfulIdentifier ( node ) || hasMeaningfulLabel ( node ) ;
575- }
576-
577615function isCoveredByHigherDrawingOrderSibling (
578616 node : AndroidNode ,
579617 coveringCandidates : AndroidCoveringCandidate [ ] ,
@@ -605,47 +643,20 @@ function canCoverSibling(
605643 node . visibleToUser !== false &&
606644 node . drawingOrder !== undefined &&
607645 hasPositiveRect ( node ) &&
608- ( hasOwnAgentVisibleContent ( node ) || hasActionableDescendant ( node , state ) )
646+ hasOcclusionEvidence ( node , state )
609647 ) ;
610648}
611649
612- /**
613- * Whether this node presents something *of its own*: an affordance to act on, something to announce,
614- * or an address to select by. Keyed on `clickable` rather than `hittable` because `hittable` falls
615- * back to `focusable`, and a node that is only focusable — no text, no id, and (per `canCoverSibling`)
616- * no actionable descendant — offers an agent nothing to see or target, so it cannot be the reason a
617- * sibling is hidden. Telegram wraps every screen in exactly such a full-screen View (#1733).
618- *
619- * This is self-classification only. `hasActionableDescendant` deliberately stays on `hittable`: a
620- * surface *containing* focusable-only controls (the norm on D-pad/TV) is a real covering surface.
621- */
622- function hasOwnAgentVisibleContent ( node : AndroidNode ) : boolean {
623- if ( node . visibleToUser === false ) return false ;
624- return node . clickable === true || hasMeaningfulLabel ( node ) || hasMeaningfulIdentifier ( node ) ;
650+ /** The single occlusion classification. Covering is never re-derived from a raw attribute. */
651+ function hasOcclusionEvidence ( node : AndroidNode , state : AndroidTreePruneState ) : boolean {
652+ return hasDirectOcclusionEvidence ( node ) || hasDescendantOcclusionEvidence ( node , state ) ;
625653}
626654
627655function hasMeaningfulLabel ( node : AndroidNode ) : boolean {
628656 const label = node . label ?. trim ( ) ?? '' ;
629657 return Boolean ( label && ! isGenericAndroidId ( label ) ) ;
630658}
631659
632- function hasActionableDescendant ( node : AndroidNode , state : AndroidTreePruneState ) : boolean {
633- const cached = state . actionableContentMemo . get ( node ) ;
634- if ( cached !== undefined ) return cached ;
635-
636- // Descendant classification stays on `hittable`. The helper emits clickable/focusable only when
637- // true, so a focusable-only control parses as clickable=undefined, hittable=true — and D-pad/TV
638- // surfaces are built almost entirely from those. Narrowing this to `clickable` would stop such a
639- // foreground surface from covering, leaving background targets selectable behind it.
640- const result = node . children . some (
641- ( child ) =>
642- child . visibleToUser !== false &&
643- ( Boolean ( child . hittable ) || hasActionableDescendant ( child , state ) ) ,
644- ) ;
645- state . actionableContentMemo . set ( node , result ) ;
646- return result ;
647- }
648-
649660function hasPositiveRect ( node : AndroidNode ) : node is AndroidNode & { rect : Rect } {
650661 return Boolean ( node . rect && node . rect . width > 0 && node . rect . height > 0 ) ;
651662}
@@ -776,8 +787,7 @@ function shouldIncludeInteractiveAndroidNode(
776787 ancestorCollection : boolean ,
777788) : boolean {
778789 if ( hasNonPositiveRect ( node ) ) return false ;
779- if ( node . focused ) return true ;
780- if ( node . hittable ) return true ;
790+ if ( isAgentTarget ( node ) ) return true ;
781791 if ( isScrollableType ( info . type ) && descendantHittable ) return true ;
782792 return shouldIncludeInteractiveProxyNode (
783793 info ,
@@ -808,7 +818,7 @@ function shouldIncludeStructuralAndroidNode(
808818 info : AndroidNodeInclusionInfo ,
809819 descendantHittable : boolean ,
810820) : boolean {
811- if ( node . hittable ) return true ;
821+ if ( isAgentTarget ( node ) ) return true ;
812822 if ( info . hasMeaningfulText ) return true ;
813823 if ( info . hasMeaningfulId ) return true ;
814824 return descendantHittable ;
0 commit comments