@@ -537,6 +537,7 @@ - (double)getSize:(SemanticsObject*)semanticsObject {
537
537
538
538
- (SemanticsObject*)search : (SemanticsObject*)semanticsObject withPoint : (CGPoint)point {
539
539
if ([semanticsObject children ].count == 0 ) {
540
+ // Check if the current semantic object should be returned.
540
541
if ([self semanticsObjectContainsPoint: semanticsObject withPoint: point] &&
541
542
[self isFocusable: semanticsObject]) {
542
543
return semanticsObject;
@@ -545,22 +546,31 @@ - (SemanticsObject*)search:(SemanticsObject*)semanticsObject withPoint:(CGPoint)
545
546
}
546
547
547
548
SemanticsObject* bestChild = nil ;
549
+ // Traverse all semantics children to find an elligable and smallest one.
548
550
for (SemanticsObject* child in [semanticsObject children ]) {
549
551
if ([self semanticsObjectContainsPoint: child withPoint: point] &&
550
552
(bestChild == nil || [self getSize: child] < [self getSize: bestChild])) {
551
553
bestChild = child;
552
554
}
553
555
}
556
+
557
+ // Continue searching the child semantic tree.
554
558
if (bestChild != nil ) {
555
559
return [self search: bestChild withPoint: point];
556
560
}
561
+
562
+ // Check if the current semantic object should be returned.
557
563
if ([self semanticsObjectContainsPoint: semanticsObject withPoint: point] &&
558
564
[self isFocusable: semanticsObject]) {
559
565
return semanticsObject;
560
566
}
561
567
return nil ;
562
568
}
563
569
570
+ // Override apple private method to fix https://github.com/flutter/flutter/issues/113377.
571
+ // For overlapping UIAccessibilityElements (e.g. a stack) in IOS, the focus goes to the smallest
572
+ // object before IOS 16, but to the top-left object in IOS 16.
573
+ // Override this method to focus the smallest object.
564
574
- (id )_accessibilityHitTest : (CGPoint)point withEvent : (UIEvent*)event {
565
575
return [self search: self withPoint: point];
566
576
}
0 commit comments