@@ -25,14 +25,18 @@ export function collectIosPresentationNoiseSuppression(
2525 context : SnapshotTreeRuleContext ,
2626) : void {
2727 const { suppressedIndexes } = context ;
28- collectIosOffscreenKeyboardSuppression ( nodes , suppressedIndexes ) ;
28+ collectIosOffscreenKeyboardSuppression ( nodes , context . sourceNodesByIndex , suppressedIndexes ) ;
2929 collectIosStructuralIdentifierSuppression ( nodes , suppressedIndexes ) ;
3030 collectIosScrollIndicatorPresentation ( nodes , context ) ;
31- collectIosSearchToolbarSuppression ( nodes , suppressedIndexes ) ;
31+ collectIosSearchToolbarSuppression ( nodes , context . sourceNodesByIndex , suppressedIndexes ) ;
3232 collectIosActionWrapperSuppression ( nodes , suppressedIndexes ) ;
3333 collectIosReactNativeOverlayActionPresentation ( nodes , context . replacements ) ;
3434 collectIosReactNativeOverlayWrapperSuppression ( nodes , suppressedIndexes ) ;
35- collectIosRepeatedStaticSuppression ( nodes , suppressedIndexes , context . replacements ) ;
35+ collectIosRepeatedStaticSuppression (
36+ nodes ,
37+ suppressedIndexes ,
38+ context . semanticRepresentativeIndexes ,
39+ ) ;
3640}
3741
3842function collectIosReactNativeOverlayActionPresentation (
@@ -133,7 +137,7 @@ function collectDescendantNodes(nodes: RawSnapshotNode[], position: number): Raw
133137function collectIosRepeatedStaticSuppression (
134138 nodes : RawSnapshotNode [ ] ,
135139 suppressedIndexes : Set < number > ,
136- replacements : Map < number , RawSnapshotNode > ,
140+ semanticRepresentativeIndexes : ReadonlySet < number > ,
137141) : void {
138142 for ( let position = 0 ; position < nodes . length ; position += 1 ) {
139143 const node = nodes [ position ] ;
@@ -148,7 +152,7 @@ function collectIosRepeatedStaticSuppression(
148152 node ,
149153 nodeLabel ,
150154 suppressedIndexes ,
151- replacements ,
155+ semanticRepresentativeIndexes ,
152156 ) ;
153157 }
154158}
@@ -159,11 +163,17 @@ function collectRepeatedStaticSuppressionForNode(
159163 node : RawSnapshotNode ,
160164 nodeLabel : string ,
161165 suppressedIndexes : Set < number > ,
162- replacements : Map < number , RawSnapshotNode > ,
166+ semanticRepresentativeIndexes : ReadonlySet < number > ,
163167) : void {
164168 const type = normalizeType ( node . type ?? '' ) ;
165169 if ( type === 'statictext' || type === 'link' ) {
166- suppressRepeatedStaticDescendants ( nodes , position , nodeLabel , suppressedIndexes , replacements ) ;
170+ suppressRepeatedStaticDescendants (
171+ nodes ,
172+ position ,
173+ nodeLabel ,
174+ suppressedIndexes ,
175+ semanticRepresentativeIndexes ,
176+ ) ;
167177 return ;
168178 }
169179 if ( type !== 'other' ) {
@@ -173,7 +183,13 @@ function collectRepeatedStaticSuppressionForNode(
173183 suppressedIndexes . add ( node . index ) ;
174184 return ;
175185 }
176- suppressRepeatedStaticDescendants ( nodes , position , nodeLabel , suppressedIndexes , replacements ) ;
186+ suppressRepeatedStaticDescendants (
187+ nodes ,
188+ position ,
189+ nodeLabel ,
190+ suppressedIndexes ,
191+ semanticRepresentativeIndexes ,
192+ ) ;
177193}
178194
179195function hasEquivalentSemanticDescendant (
@@ -197,27 +213,18 @@ function suppressRepeatedStaticDescendants(
197213 position : number ,
198214 label : string ,
199215 suppressedIndexes : Set < number > ,
200- replacements : Map < number , RawSnapshotNode > ,
216+ semanticRepresentativeIndexes : ReadonlySet < number > ,
201217) : void {
202218 forEachDescendant ( nodes , position , ( descendant ) => {
203219 if (
204- ! hasWebSemanticReplacement ( descendant , replacements . get ( descendant . index ) ) &&
220+ ! semanticRepresentativeIndexes . has ( descendant . index ) &&
205221 isRepeatedStaticNode ( descendant , label )
206222 ) {
207223 suppressedIndexes . add ( descendant . index ) ;
208224 }
209225 } ) ;
210226}
211227
212- function hasWebSemanticReplacement (
213- source : RawSnapshotNode ,
214- replacement : RawSnapshotNode | undefined ,
215- ) : boolean {
216- if ( normalizeType ( source . type ?? '' ) !== 'other' ) return false ;
217- const replacementType = normalizeType ( replacement ?. type ?? '' ) ;
218- return replacementType === 'heading' || replacementType === 'statictext' ;
219- }
220-
221228function collectIosActionWrapperSuppression (
222229 nodes : RawSnapshotNode [ ] ,
223230 suppressedIndexes : Set < number > ,
@@ -276,6 +283,7 @@ function isFullscreenActionLabelWrapper(
276283
277284function collectIosOffscreenKeyboardSuppression (
278285 nodes : RawSnapshotNode [ ] ,
286+ sourceNodesByIndex : ReadonlyMap < number , RawSnapshotNode > ,
279287 suppressedIndexes : Set < number > ,
280288) : void {
281289 const viewport = findLargestViewportRect ( nodes ) ;
@@ -289,7 +297,7 @@ function collectIosOffscreenKeyboardSuppression(
289297 continue ;
290298 }
291299 suppressedIndexes . add ( node . index ) ;
292- suppressOffscreenKeyboardAncestors ( node , nodes , suppressedIndexes , screenBottom ) ;
300+ suppressOffscreenKeyboardAncestors ( node , sourceNodesByIndex , suppressedIndexes , screenBottom ) ;
293301 forEachDescendant ( nodes , position , ( descendant ) => {
294302 suppressedIndexes . add ( descendant . index ) ;
295303 } ) ;
@@ -305,16 +313,18 @@ function isOffscreenKeyboardNode(node: RawSnapshotNode, screenBottom: number): b
305313
306314function suppressOffscreenKeyboardAncestors (
307315 node : RawSnapshotNode ,
308- nodes : RawSnapshotNode [ ] ,
316+ sourceNodesByIndex : ReadonlyMap < number , RawSnapshotNode > ,
309317 suppressedIndexes : Set < number > ,
310318 screenBottom : number ,
311319) : void {
312- const byIndex = new Map ( nodes . map ( ( candidate ) => [ candidate . index , candidate ] ) ) ;
313- let current = typeof node . parentIndex === 'number' ? byIndex . get ( node . parentIndex ) : undefined ;
320+ let current =
321+ typeof node . parentIndex === 'number' ? sourceNodesByIndex . get ( node . parentIndex ) : undefined ;
314322 while ( current ?. rect && current . rect . y >= screenBottom ) {
315323 suppressedIndexes . add ( current . index ) ;
316324 current =
317- typeof current . parentIndex === 'number' ? byIndex . get ( current . parentIndex ) : undefined ;
325+ typeof current . parentIndex === 'number'
326+ ? sourceNodesByIndex . get ( current . parentIndex )
327+ : undefined ;
318328 }
319329}
320330
@@ -338,6 +348,7 @@ function collectIosStructuralIdentifierSuppression(
338348
339349function collectIosSearchToolbarSuppression (
340350 nodes : RawSnapshotNode [ ] ,
351+ sourceNodesByIndex : ReadonlyMap < number , RawSnapshotNode > ,
341352 suppressedIndexes : Set < number > ,
342353) : void {
343354 for ( let position = 0 ; position < nodes . length ; position += 1 ) {
@@ -360,7 +371,7 @@ function collectIosSearchToolbarSuppression(
360371 }
361372
362373 suppressedIndexes . add ( node . index ) ;
363- suppressToolbarAncestors ( node , nodes , suppressedIndexes ) ;
374+ suppressToolbarAncestors ( node , sourceNodesByIndex , suppressedIndexes ) ;
364375 suppressSearchToolbarDescendants ( nodes , position , innerSearch . index , suppressedIndexes ) ;
365376 }
366377}
@@ -392,13 +403,12 @@ function suppressSearchToolbarDescendants(
392403
393404function suppressToolbarAncestors (
394405 node : RawSnapshotNode ,
395- nodes : RawSnapshotNode [ ] ,
406+ sourceNodesByIndex : ReadonlyMap < number , RawSnapshotNode > ,
396407 suppressedIndexes : Set < number > ,
397408) : void {
398- const byIndex = new Map ( nodes . map ( ( candidate ) => [ candidate . index , candidate ] ) ) ;
399409 let current = node ;
400410 while ( typeof current . parentIndex === 'number' ) {
401- const parent = byIndex . get ( current . parentIndex ) ;
411+ const parent = sourceNodesByIndex . get ( current . parentIndex ) ;
402412 if ( ! parent || parent . label !== 'Toolbar' ) {
403413 return ;
404414 }
0 commit comments