Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 75e7073

Browse files
committed
Update SemanticsObject.mm
1 parent 3db2590 commit 75e7073

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

shell/platform/darwin/ios/framework/Source/SemanticsObject.mm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ - (double)getSize:(SemanticsObject*)semanticsObject {
537537

538538
- (SemanticsObject*)search:(SemanticsObject*)semanticsObject withPoint:(CGPoint)point {
539539
if ([semanticsObject children].count == 0) {
540+
// Check if the current semantic object should be returned.
540541
if ([self semanticsObjectContainsPoint:semanticsObject withPoint:point] &&
541542
[self isFocusable:semanticsObject]) {
542543
return semanticsObject;
@@ -545,22 +546,31 @@ - (SemanticsObject*)search:(SemanticsObject*)semanticsObject withPoint:(CGPoint)
545546
}
546547

547548
SemanticsObject* bestChild = nil;
549+
// Traverse all semantics children to find an elligable and smallest one.
548550
for (SemanticsObject* child in [semanticsObject children]) {
549551
if ([self semanticsObjectContainsPoint:child withPoint:point] &&
550552
(bestChild == nil || [self getSize:child] < [self getSize:bestChild])) {
551553
bestChild = child;
552554
}
553555
}
556+
557+
// Continue searching the child semantic tree.
554558
if (bestChild != nil) {
555559
return [self search:bestChild withPoint:point];
556560
}
561+
562+
// Check if the current semantic object should be returned.
557563
if ([self semanticsObjectContainsPoint:semanticsObject withPoint:point] &&
558564
[self isFocusable:semanticsObject]) {
559565
return semanticsObject;
560566
}
561567
return nil;
562568
}
563569

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.
564574
- (id)_accessibilityHitTest:(CGPoint)point withEvent:(UIEvent*)event {
565575
return [self search:self withPoint:point];
566576
}

0 commit comments

Comments
 (0)