Repository navigation
[iOS] Preserve semantics parents after reparenting - #189686
Conversation
Exercise the default mobile long-press reorder path and verify that the native iOS semantic hierarchy preserves the reordered item's frame. Issue: flutter#100946
Only detach a semantics child when the object being updated still owns its parent link. This prevents a removed reorderable-list container from clearing a child that has already moved into its replacement and losing the ancestor transform used for its accessibility frame. Issue: flutter#100946
Add a deterministic reorder target and native UI test for exercising drag interactions in the iOS platform-view integration app.
241e4a0 to
a6bb2aa
Compare
There was a problem hiding this comment.
Code Review
This pull request updates iOS semantics handling in SemanticsObject.mm to ensure that an old parent does not detach a child that has already been reparented, and adds corresponding unit and integration tests. The review feedback identifies that ReorderableListView.builder in both drag.dart and reorderable_list_semantics.dart incorrectly uses the non-existent parameter onReorderItem instead of onReorder.
|
@LongCatIsLooong @LouiseHsu friendly ping for review. |
LongCatIsLooong
left a comment
There was a problem hiding this comment.
LGTM. Thanks for contributing!
| class _DragScreenState extends State<DragScreen> { | ||
| List<int> items = <int>[1, 2, 3, 4, 5]; | ||
|
|
||
| // Target order for Maestro drag-and-drop test validation. |
There was a problem hiding this comment.
It seems Maestro is a testing framework, but still I'm a bit confused as to what information this comment is conveying to the reader?
There was a problem hiding this comment.
It was a leftover comment from testing. Removed.
| XCTAssertNotNil([child accessibilityContainer]); | ||
| } | ||
|
|
||
| - (void)testRemovedSemanticsDoesNotDetachReparentedChild { |
There was a problem hiding this comment.
nit: is this test necessary? The unit test in SemanticsObjectTest.mm verifies the oversight in setChildren is fixed, and the integration test verifies with the fix reorderable list's semantics work correctly?
There was a problem hiding this comment.
Fair point. This one created the reparenting scenario by itself but with the other tests, this is redundant. Removed.
The onReorderItem callback already adjusts the destination after removing the source item. Insert directly at that index so downward drags do not move one position too early.
There was a problem hiding this comment.
I kicked the tests for you and have (tried) to re-run the google3 tests (the failure wasn't your code it was a flake in the infra itself :/)
Took at quick review pass while I was here and was wondering why the -1 adjustment, but turns out that this shouldn't be necessary. See inline comment. Other than that, just @LongCatIsLooong's comments to address.
| setState(() { | ||
| if (newIndex > oldIndex) { | ||
| newIndex -= 1; | ||
| } |
There was a problem hiding this comment.
It looks like this newIndex -= 1 was required for the old onReorder callback but onReorderItem already handles this internally:
flutter/packages/flutter/lib/src/widgets/reorderable_list.dart
Lines 1022 to 1025 in 875be1c
There was a problem hiding this comment.
Updated and renamed. testDragScreen in PlatformViewUITests should've caught this but apparently I didn't run that test until now. Might have been too caught up in the manual testing or disturbed the test myself.
|
|
||
| bool get isCorrectOrder => listEquals(items, targetOrder); | ||
|
|
||
| void _onReorder(int oldIndex, int newIndex) { |
There was a problem hiding this comment.
You should rename this _onReorderItem since this is the handler being passed to that param down below.
The SemanticsObject unit test covers parent ownership, while the iOS integration test covers the native hierarchy and frame after a reorder. Remove the overlapping bridge-level scenario.
|
@cbracken @LongCatIsLooong Thanks for the reviews. Addressed the comments and made the updates. |
flutter/flutter@0cbd1a4...70797e1 2026-09-02 [email protected] [analysis] Upgrade package:analyzer to 14.3.0 and enable custom plugin compilation (flutter/flutter#191590) 2026-09-02 [email protected] Roll Dart SDK from d8d7869d8031 to 9a8fbde80f6c (1 revision) (flutter/flutter#192179) 2026-09-02 [email protected] Roll Skia from dec311244db4 to ae22da2e8308 (1 revision) (flutter/flutter#192177) 2026-09-02 [email protected] [tool] Migrate DoctorCommand to modular dependency injection (flutter/flutter#190758) 2026-09-02 [email protected] Roll Skia from 482b7e285244 to dec311244db4 (3 revisions) (flutter/flutter#192161) 2026-09-02 [email protected] Roll Skia from 28447e9fb8d5 to 482b7e285244 (3 revisions) (flutter/flutter#192157) 2026-09-02 [email protected] feat: Add placeholder to DecorationImage (flutter/flutter#191528) 2026-09-02 [email protected] [Android] Do not schedule engine frames on a detached FlutterJNI (flutter/flutter#191204) 2026-09-02 [email protected] Roll Skia from 3a242fb7cdb3 to 28447e9fb8d5 (1 revision) (flutter/flutter#192145) 2026-09-02 [email protected] Roll Dart SDK from 9164def35347 to d8d7869d8031 (2 revisions) (flutter/flutter#192144) 2026-09-02 [email protected] Add FadeInImageTransition.fadeInOver to fade the image in over the placeholder (flutter/flutter#186246) 2026-09-02 [email protected] Roll Skia from 63d13ec4df6d to 3a242fb7cdb3 (9 revisions) (flutter/flutter#192138) 2026-09-02 [email protected] [flutter_tools] Add --no-plugins flag and disable plugins for benchmark (flutter/flutter#192129) 2026-09-02 [email protected] [tool] Migrate ChannelCommand to modular dependency injection (flutter/flutter#190751) 2026-09-01 [email protected] Add mouseCursor to RawScrollbar (flutter/flutter#185750) 2026-09-01 [email protected] Fix self-comparison and assert typos in TestSemantics (flutter/flutter#191938) 2026-09-01 [email protected] [Linux] Wait for frames to be rendered before using them in another context (flutter/flutter#192094) 2026-09-01 [email protected] [wimp] Turn on multithreading for wimp. (flutter/flutter#191747) 2026-09-01 [email protected] Roll Skia from 3911a1fe7f7a to 63d13ec4df6d (6 revisions) (flutter/flutter#192125) 2026-09-01 [email protected] Remove the redundant flutter/shell/platform/android:robolectric_tests build target (flutter/flutter#192117) 2026-09-01 [email protected] [iOS] Preserve semantics parents after reparenting (flutter/flutter#189686) 2026-09-01 [email protected] [flutter_tools] Report preview reload timing analytics in LspPreviewDetector (flutter/flutter#192120) 2026-09-01 [email protected] [flutter_tools] Implement Templates slice and flutter create integration (flutter/flutter#191748) 2026-09-01 [email protected] Uiscene migrate add2app hosts (flutter/flutter#191847) 2026-09-01 [email protected] Roll Packages from d642322 to 7a7912f (8 revisions) (flutter/flutter#192119) 2026-09-01 [email protected] [web] Anchor flt-semantics-host at 0,0 to fix WebKit semantics offset (flutter/flutter#190486) 2026-09-01 [email protected] Replace Shell::WaitForFirstFrame with an asynchronous API that matches the Shell threading model (flutter/flutter#191841) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…r#12727) flutter/flutter@0cbd1a4...70797e1 2026-09-02 [email protected] [analysis] Upgrade package:analyzer to 14.3.0 and enable custom plugin compilation (flutter/flutter#191590) 2026-09-02 [email protected] Roll Dart SDK from d8d7869d8031 to 9a8fbde80f6c (1 revision) (flutter/flutter#192179) 2026-09-02 [email protected] Roll Skia from dec311244db4 to ae22da2e8308 (1 revision) (flutter/flutter#192177) 2026-09-02 [email protected] [tool] Migrate DoctorCommand to modular dependency injection (flutter/flutter#190758) 2026-09-02 [email protected] Roll Skia from 482b7e285244 to dec311244db4 (3 revisions) (flutter/flutter#192161) 2026-09-02 [email protected] Roll Skia from 28447e9fb8d5 to 482b7e285244 (3 revisions) (flutter/flutter#192157) 2026-09-02 [email protected] feat: Add placeholder to DecorationImage (flutter/flutter#191528) 2026-09-02 [email protected] [Android] Do not schedule engine frames on a detached FlutterJNI (flutter/flutter#191204) 2026-09-02 [email protected] Roll Skia from 3a242fb7cdb3 to 28447e9fb8d5 (1 revision) (flutter/flutter#192145) 2026-09-02 [email protected] Roll Dart SDK from 9164def35347 to d8d7869d8031 (2 revisions) (flutter/flutter#192144) 2026-09-02 [email protected] Add FadeInImageTransition.fadeInOver to fade the image in over the placeholder (flutter/flutter#186246) 2026-09-02 [email protected] Roll Skia from 63d13ec4df6d to 3a242fb7cdb3 (9 revisions) (flutter/flutter#192138) 2026-09-02 [email protected] [flutter_tools] Add --no-plugins flag and disable plugins for benchmark (flutter/flutter#192129) 2026-09-02 [email protected] [tool] Migrate ChannelCommand to modular dependency injection (flutter/flutter#190751) 2026-09-01 [email protected] Add mouseCursor to RawScrollbar (flutter/flutter#185750) 2026-09-01 [email protected] Fix self-comparison and assert typos in TestSemantics (flutter/flutter#191938) 2026-09-01 [email protected] [Linux] Wait for frames to be rendered before using them in another context (flutter/flutter#192094) 2026-09-01 [email protected] [wimp] Turn on multithreading for wimp. (flutter/flutter#191747) 2026-09-01 [email protected] Roll Skia from 3911a1fe7f7a to 63d13ec4df6d (6 revisions) (flutter/flutter#192125) 2026-09-01 [email protected] Remove the redundant flutter/shell/platform/android:robolectric_tests build target (flutter/flutter#192117) 2026-09-01 [email protected] [iOS] Preserve semantics parents after reparenting (flutter/flutter#189686) 2026-09-01 [email protected] [flutter_tools] Report preview reload timing analytics in LspPreviewDetector (flutter/flutter#192120) 2026-09-01 [email protected] [flutter_tools] Implement Templates slice and flutter create integration (flutter/flutter#191748) 2026-09-01 [email protected] Uiscene migrate add2app hosts (flutter/flutter#191847) 2026-09-01 [email protected] Roll Packages from d642322 to 7a7912f (8 revisions) (flutter/flutter#192119) 2026-09-01 [email protected] [web] Anchor flt-semantics-host at 0,0 to fix WebKit semantics offset (flutter/flutter#190486) 2026-09-01 [email protected] Replace Shell::WaitForFirstFrame with an asynchronous API that matches the Shell threading model (flutter/flutter#191841) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…r#12727) flutter/flutter@0cbd1a4...70797e1 2026-09-02 [email protected] [analysis] Upgrade package:analyzer to 14.3.0 and enable custom plugin compilation (flutter/flutter#191590) 2026-09-02 [email protected] Roll Dart SDK from d8d7869d8031 to 9a8fbde80f6c (1 revision) (flutter/flutter#192179) 2026-09-02 [email protected] Roll Skia from dec311244db4 to ae22da2e8308 (1 revision) (flutter/flutter#192177) 2026-09-02 [email protected] [tool] Migrate DoctorCommand to modular dependency injection (flutter/flutter#190758) 2026-09-02 [email protected] Roll Skia from 482b7e285244 to dec311244db4 (3 revisions) (flutter/flutter#192161) 2026-09-02 [email protected] Roll Skia from 28447e9fb8d5 to 482b7e285244 (3 revisions) (flutter/flutter#192157) 2026-09-02 [email protected] feat: Add placeholder to DecorationImage (flutter/flutter#191528) 2026-09-02 [email protected] [Android] Do not schedule engine frames on a detached FlutterJNI (flutter/flutter#191204) 2026-09-02 [email protected] Roll Skia from 3a242fb7cdb3 to 28447e9fb8d5 (1 revision) (flutter/flutter#192145) 2026-09-02 [email protected] Roll Dart SDK from 9164def35347 to d8d7869d8031 (2 revisions) (flutter/flutter#192144) 2026-09-02 [email protected] Add FadeInImageTransition.fadeInOver to fade the image in over the placeholder (flutter/flutter#186246) 2026-09-02 [email protected] Roll Skia from 63d13ec4df6d to 3a242fb7cdb3 (9 revisions) (flutter/flutter#192138) 2026-09-02 [email protected] [flutter_tools] Add --no-plugins flag and disable plugins for benchmark (flutter/flutter#192129) 2026-09-02 [email protected] [tool] Migrate ChannelCommand to modular dependency injection (flutter/flutter#190751) 2026-09-01 [email protected] Add mouseCursor to RawScrollbar (flutter/flutter#185750) 2026-09-01 [email protected] Fix self-comparison and assert typos in TestSemantics (flutter/flutter#191938) 2026-09-01 [email protected] [Linux] Wait for frames to be rendered before using them in another context (flutter/flutter#192094) 2026-09-01 [email protected] [wimp] Turn on multithreading for wimp. (flutter/flutter#191747) 2026-09-01 [email protected] Roll Skia from 3911a1fe7f7a to 63d13ec4df6d (6 revisions) (flutter/flutter#192125) 2026-09-01 [email protected] Remove the redundant flutter/shell/platform/android:robolectric_tests build target (flutter/flutter#192117) 2026-09-01 [email protected] [iOS] Preserve semantics parents after reparenting (flutter/flutter#189686) 2026-09-01 [email protected] [flutter_tools] Report preview reload timing analytics in LspPreviewDetector (flutter/flutter#192120) 2026-09-01 [email protected] [flutter_tools] Implement Templates slice and flutter create integration (flutter/flutter#191748) 2026-09-01 [email protected] Uiscene migrate add2app hosts (flutter/flutter#191847) 2026-09-01 [email protected] Roll Packages from d642322 to 7a7912f (8 revisions) (flutter/flutter#192119) 2026-09-01 [email protected] [web] Anchor flt-semantics-host at 0,0 to fix WebKit semantics offset (flutter/flutter#190486) 2026-09-01 [email protected] Replace Shell::WaitForFirstFrame with an asynchronous API that matches the Shell threading model (flutter/flutter#191841) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
… + Fix OverlayPortal semantics bounds corruption (#192139) (#193420) Cherry-picks #189686 and #192139 into `flutter-3.47-candidate.0` (stable). Both applied cleanly with `git cherry-pick -x`; both touch only `SemanticsObject.mm` (+ tests). ### Issue Link #182604 · #100946 ### Impacted Users End users of iOS apps built with stable who rely on VoiceOver / Switch Control, and teams driving XCUITest / Maestro against Flutter apps. Any route that mounts a Material `Slider` is affected out of the box: `Slider` keeps its value-indicator `OverlayPortal` shown from construction (`slider.dart`: `OverlayPortalController(...)..show()`), so no popover, menu or reorder is needed to trigger it. ### Impact Description Since fccfa97 an `OverlayPortal` child has a different parent in traversal order and in hit-test order. The iOS accessibility bridge overwrote the native `SemanticsObject.parent` with the hit-test one (and cleared parents of moved children), so the parent chain used to compute `accessibilityFrame` no longer reaches the root: every element of the route reports a frame scaled by 1/devicePixelRatio (exactly 1/3 on a 3x device) and anchored top-left. VoiceOver touch exploration focuses the wrong place; `XCUIElement.tap()` misses the visible control. Measured on iPhone 16 Pro Max / iOS 26.7 with Flutter 3.44.8 (stable 3.47.5 has the same `SemanticsObject.mm`): a full-width CTA laid out at `{{32, 834}, {376, 56}}` is published as `{{10.7, 278.0}, {125.3, 18.7}}`; a player route with a `Slider` is 1/3 from its first frame. The corruption persists after the portal unmounts and after background/foreground. ### Changelog Description [flutter/182604](#182604) When a route shows an `OverlayPortal` on iOS (including any Material `Slider`), accessibility frames are shrunk by the device pixel ratio and anchored to the top-left, so VoiceOver focus and XCUITest taps miss the visible controls. ### Workaround Replace Material `Slider` with `CupertinoSlider` (no `OverlayPortal`) on affected routes and avoid `OverlayPortal` altogether. Not viable for apps using Material menus / dropdowns or third-party popovers. ### Risk Low. Parent bookkeeping only: #189686 clears `child.parent` only when the object still owns it; #192139 stops the hit-test-order setter from mutating `parent`. No behaviour change when traversal and hit-test parents coincide. ### Cherry-pick diff composition The two upstream PRs touch the same function, so the composed diff on `SemanticsObject.mm` (`+6 -8`) matches neither of them individually — upstream, #189686 is `+9 -3` on this file and #192139 is `+0 -8`. Net against the `flutter-3.47-candidate.0` base: | site | net effect vs. base | |---|---| | `dealloc` | `+3 -1` — guard becomes `if (child.parent == self) { child.parent = nil; }` | | `setChildren` | `+3 -1` — same guard | | `setChildrenInHitTestOrder` | `-6` — #189686 adds the guard here too, then #192139 deletes both parent loops outright, so those 3 added lines never survive and the block's 6 original lines go away | Additions `3 + 3 = 6`; deletions `1 + 1 + 6 = 8`. The three "missing" additions are the ones the second commit removes from the first. No conflict was resolved by hand — both applied cleanly with `git cherry-pick -x`. ### Test Coverage Yes. #189686 adds an iOS XCUITest (`testReorderableListAccessibilityHierarchyUpdates`) asserting the accessibility frame after reparenting; #192139 adds `SemanticsObjectTest.mm` coverage. Both have been on master since 2026-09-01/03 and ship in beta 3.49.0-0.1.pre. ### Validation Steps 1. On a 3x iOS device, push a route (e.g. `MaterialApp.router` + `GoRoute`) whose body contains a Material `Slider`. 2. Print `XCUIApplication().debugDescription` from an XCUITest, or inspect with Accessibility Inspector. 3. Before: every element of the route reports a frame at 1/3 of its logical size near (0,0). After: frames match the visible layout, and `XCUIElement.tap()` / VoiceOver touch exploration hit the visible controls.
Fixes #100946.
Problem
Reordering a
ReorderableListViewon iOS could move VoiceOver focus to the upper-left corner of the screen. The affected items could no longer be focused at their visual positions.During a reorder, semantics children move through temporary containers used by the drag overlay and drop animation. A child may already have been attached to its replacement
SemanticsObjectwhen its previous parent is updated or deallocated.The previous parent unconditionally cleared the child's
parentproperty. This overwrote the new parent relationship and disconnected the child from the native semantics hierarchy.SemanticsObjectcalculates its global accessibility frame by walking this parent chain and composing each ancestor's transform. Once the chain was disconnected, the element retained only its local physical-pixel rectangle. On a 3x simulator, the expected frame:became:
This accounts for both the missing translation and the frame being reduced by the device pixel ratio.
Fix
Only clear a child's parent when the
SemanticsObjectperforming cleanup still owns that parent relationship:This guard is applied when:
SemanticsObjectis deallocated.A previous parent can now release its stale child references without detaching a child that has already moved under a replacement container. The complete ancestor transform remains available when calculating the native accessibility frame.
Testing
Added An iOS XCUITest that performs the default mobile long-press reorder gesture, verifies the resulting native semantic traversal order, and asserts that the reordered item retains the expected accessibility frame.
The integration app also includes a deterministic direct-drag fixture for exercising XCUITest drag synthesis.
Validation performed:
testReorderableListAccessibilityHierarchyUpdatespasses with the locally built engine.packages/flutter/test/widgets/reorderable_list_test.dartpasses.packages/flutter/test/material/reorderable_list_test.dartpasses.ios_test_flutterbuilds successfully.Pre-launch Checklist
///).