Skip to content

Commit 20c755d

Browse files
authored
Fixes OverlayPortal semantics bounds corruption (flutter#192139)
fixes flutter#182604 Historically, the configuration/order of children and parents for widgets is identical across both traversal and hit test order. However, with introduction over OverlayPortal, flutter@fccfa97, this is no longer always the case. For example when traversing, the actual portal child, eg, a floating drop down box, is a child of the `OverlayPortal`. However when hit testing, the portal child is a child of the `Overlay`. Prior to this pr, both setChildrenInHitTestOrder and setChildren have identical implementations. ``` for (SemanticsObject* child in _childrenInHitTestOrder) { if (child.parent == self) { child.parent = nil; } } _childrenInHitTestOrder = [childrenInHitTestOrder copy]; for (SemanticsObject* child in _childrenInHitTestOrder) { child.parent = self; } ``` On every frame, setChildren and setChildrenInHitTestOrder is run sequentially on every widget. So first, when setChildren is run for `OverlayPortal`, it sets `portalChild.parent = overlayPortal`. This is the correct traversal order. Then, sometime later, it runs setChildrenInHitTestOrder for `Overlay`, which sets portalChild.parent = overlay`. This is incorrect. This is why in the bug the accessibility nodes still exist, just weirdly offset - because its now anchored to 0, 0 of `Overlay` instead of the the position over `OverlayPortal`. Because hittest order strictly walks top down (parent isnt ever accessed), we don't actually have to do any mutation to the parents. https://github.com/user-attachments/assets/df093797-7482-42ba-ba4c-b9a172484031
1 parent aa36805 commit 20c755d

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

‎engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,7 @@ - (void)setChildren:(NSArray<SemanticsObject*>*)children {
331331
}
332332

333333
- (void)setChildrenInHitTestOrder:(NSArray<SemanticsObject*>*)childrenInHitTestOrder {
334-
for (SemanticsObject* child in _childrenInHitTestOrder) {
335-
if (child.parent == self) {
336-
child.parent = nil;
337-
}
338-
}
339334
_childrenInHitTestOrder = [childrenInHitTestOrder copy];
340-
for (SemanticsObject* child in _childrenInHitTestOrder) {
341-
child.parent = self;
342-
}
343335
}
344336

345337
- (BOOL)hasChildren {

‎engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,24 @@ - (void)testOldParentDoesNotDetachReparentedChild {
8888
XCTAssertEqual(child.parent, newParent);
8989
}
9090

91+
- (void)testSetChildrenInHitTestOrderDoesNotModifyParent {
92+
fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
93+
new flutter::testing::MockAccessibilityBridge());
94+
fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
95+
SemanticsObject* traversalParent = [[SemanticsObject alloc] initWithBridge:bridge uid:0];
96+
SemanticsObject* hitTestParent = [[SemanticsObject alloc] initWithBridge:bridge uid:1];
97+
SemanticsObject* child = [[SemanticsObject alloc] initWithBridge:bridge uid:2];
98+
99+
traversalParent.children = @[ child ];
100+
XCTAssertEqual(child.parent, traversalParent);
101+
102+
hitTestParent.childrenInHitTestOrder = @[ child ];
103+
XCTAssertEqual(child.parent, traversalParent);
104+
105+
hitTestParent.childrenInHitTestOrder = @[];
106+
XCTAssertEqual(child.parent, traversalParent);
107+
}
108+
91109
- (void)testAccessibilityHitTestFocusAtLeaf {
92110
fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(
93111
new flutter::testing::MockAccessibilityBridge());

0 commit comments

Comments
 (0)