Repository navigation
[CP-stable][iOS a11y] Use a real UIScrollView as a11y scrollable container - #196163
Conversation
…utter#195731) Fixes flutter#192774 (and maybe other scrolling related a11y issues). I intend to cherry pick this patch to the beta branch if merged, since the diff is surprisingly small. This PR does 3 things: 1. Forwards some a11y hit test methods to ignore `hidden` `SemanticsObject`s 2. Reports `globalRect` instead of an empty rect for `hidden` `SemanticsObject`s 3. Incorporates `FlutterSemanticsScrollView` (a real `UIScrollView` subclass) as the `accessibilityContainer` of scroll items, instead of the original `SemanticsObject` subclass. Why is 3 needed? Instead of exposing a11y APIs for scrollable containers, the iOS a11y system assumes all scrollable containers are `UIScrollView`s and uses `UIScrollView` APIs to determine relevant geometry information (it relies on `[obj isKindOfClass:[UIScrollView class]]` checks): <details> <summary><b>Concrete Binary Evidence That <code>UIScrollView</code> Is Hardcoded in <code>UIAccessibility.framework</code> & <code>UIKit.axbundle</code> (No Non-<code>UIScrollView</code> Workaround)</b></summary> Disassembling UIAccessibility.framework and UIKit.axbundle (iOS 27.1) proves that iOS explicitly checks isKindOfClass:[UIScrollView class] (loaded from GOT slot 0x221b44f40) and/or ___UIAccessibilityCastAsClass([UIScrollView class], ...) across the scroll, visibility, and opaque-element pipeline: 1. Evidence 1: _accessibilityVisibleFrame: explicitly checks [scrollParent isKindOfClass:[UIScrollView class]] (0x1F069DADC) - Role in Accessibility Scrolling: iOS separates an element's layout geometry (accessibilityFrame, AX attribute 2003) from its on-screen clipped geometry (_accessibilityVisibleFrame, AX attribute 2053 / -[VOTElement visibleFrame]): - Hit-testing & non-scrolling visibility checks (_accessibilityIsVisibleByCompleteHitTest: and _accessibilityFindElementInDirection:... when allowOutOfBoundsChild == NO) check _accessibilityVisibleFrame.width > 0 && height > 0 so that off-screen cached items are not hit-tested by direct finger touch or focused when scrolling is disallowed. - Implicit scroll-into-view (_accessibilityFindElementInDirection:... when allowOutOfBoundsChild == YES and -[VOTElement updateVisuals] / scroll checks in vot) allows a child whose _accessibilityVisibleFrame is CGRectZero as long as its accessibilityFrame is non-empty and its opaque scroll parent's _accessibilityVisibleFrame is non-empty, and uses the empty visibleFrame as the signal that the child must be scrolled into view before placing the VoiceOver cursor. - Hardcoded UIScrollView Check: In ___55-[NSObject(AXPrivCategory) _accessibilityVisibleFrame:]_block_invoke (UIAccessibility.framework @ 0x1F069DABC): 0x1F069DADC: adrp x8, 201895 ; 0x221b44000 0x1F069DAE0: ldr x0, [x8, #0xf40] ; _OBJC_CLASS_$_UIScrollView 0x1F069DAE4: bl _objc_opt_class 0x1F069DAE8: mov x1, x0 0x1F069DAEC: ldr x0, [sp, #0x8] ; scrollParent 0x1F069DAF0: bl _objc_opt_isKindOfClass ; [scrollParent isKindOfClass:[UIScrollView class]] 0x1F069DAF4: tbz w0, #0x0, 0x1f069db5c ; <-- IF NOT UIScrollView, SKIP CLIPPING ENTIRELY! 0x1F069DAF8: ldr x0, [sp, #0x8] 0x1F069DAFC: bl _objc_msgSend$_accessibilityContentFrame ... 0x1F069DB10: bl _CGRectIntersection ; Intersect child frame with UIScrollView._accessibilityContentFrame Even if a custom NSObject container overrides _accessibilityIsScrollAncestor to return YES, _accessibilityVisibleFrame: refuses to clip children against it unless [scrollParent isKindOfClass:[UIScrollView class]] is true. 5. Evidence 2: _axFrameForBoundsCheck: (0x1F069E5C4) and _accessibilityScrollAncestorForSelector: (0x1F067FB24) explicitly check [scrollParent isKindOfClass:[UIScrollView class]] - Role in Accessibility Scrolling: 1. Screen-Bounds Exemption for Off-Screen Scroll Children (_accessibilityIsFrameOutOfBoundsConsideringScrollParents:): Normally, UIAccessibility discards any element whose accessibilityFrame lies outside the UIWindow screen bounds (y > screenHeight or y < 0) as outOfBounds = YES. However, off-screen cached children inside a scroll view must have off-screen coordinates (y = 902, 958, ...) while still remaining eligible for VoiceOver swipe navigation. _axFrameForBoundsCheck:YES (UIAccessibility.framework @ 0x1F069E5C4) solves this by substituting the outermost scroll parent's on-screen frame in place of the child's off-screen frame during the screen-bounds check—if and only if [scrollParent isKindOfClass:[UIScrollView class]] (0x1F069E66C): 0x1F069E648: bl _objc_msgSend$_axOutermostScrollParent 0x1F069E650: mov x20, x0 0x1F069E654: cbz x0, 0x1f069e6b8 0x1F069E658: adrp x8, 201894 ; 0x221b44000 0x1F069E65C: ldr x0, [x8, #0xf40] ; _OBJC_CLASS_$_UIScrollView 0x1F069E660: bl _objc_opt_class 0x1F069E664: mov x1, x0 0x1F069E668: mov x0, x20 0x1F069E66C: bl _objc_opt_isKindOfClass ; [scrollParent isKindOfClass:[UIScrollView class]] 2. Routing Scroll Actions from Focused Child to Scroll Container (_accessibilityScrollAncestorForSelector: / _accessibilityFindScrollParent:): When a user focuses a child item and performs a 3-finger swipe (accessibilityScroll:) or when VoiceOver triggers scroll-to-visible, UIAccessibility walks up the hierarchy via _accessibilityScrollAncestorForSelector:alwaysAllowRefreshAction: (0x1F067FB24) and _accessibilityFindScrollParent: (0x1F0680E00), both of which check [ancestor isKindOfClass:[UIScrollView class]] (0x1F067FBC4 and 0x1F0680E80). 6. Evidence 3: _accessibilityOpaqueElementScrollToDirection: & _accessibilityScrollOpaqueElementIntoView:previousScroller: require UIScrollView (0x1F06983C8 & 0x1F0697744) - Role in Accessibility Scrolling: When VoiceOver reaches the last cached child inside an opaque scroll container (or when entering an opaque scroll container whose current viewport has no visible children) during _accessibilitySearchSubtreesAfterChildElement:..., UIAccessibility calls _accessibilityOpaqueElementScrollToDirection: to advance the scroll container's contentOffset so that newly-materialized lazy items can be discovered and focused. - Hardcoded UIScrollView Check & Checked Cast: - In -[NSObject(AXPrivCategory) _accessibilityOpaqueElementScrollToDirection:] (0x1F06983C8), UIAccessibility walks up the container chain and checks [ancestor isKindOfClass:[UIScrollView class]] (0x1F0698434) before checking isScrollEnabled and invoking _accessibilityScrollOpaqueElementIntoView:previousScroller:. - In -[NSObject(AXPrivCategory) _accessibilityScrollOpaqueElementIntoView:previousScroller:] (0x1F0697744) and -[NSObject(AXPrivCategory) _accessibilityOffsetForOpaqueElementDirection:] (0x1F0697908), UIAccessibility executes ___UIAccessibilityCastAsClass([UIScrollView class], self, YES, &error) (calling _abort at 0x1F0697860 / 0x1F069796C if self is not a UIScrollView), reads UIScrollView.bounds, contentSize, and adjustedContentInset, and calls accessibilityApplyScrollContent:sendScrollStatus:animated:. 7. Evidence 4: -[UIScrollViewAccessibility _accessibilityFirstLastOpaqueElement:options:] in UIKit.axbundle (0x1C8DFA64C) - Role in Accessibility Scrolling: Controls which child receives initial VoiceOver focus when swiping into a scroll view from an adjacent sibling outside the scroll view (invoked via _accessibilityFirstOpaqueElementWithOptions: at 0x1C8DFA9DC when swiping right/down into the scroll view, or _accessibilityLastOpaqueElementWithOptions: at 0x1C8DFB5D0 when swiping left/up into the scroll view from below). - For example, if a user has scrolled halfway down a ListView (Item 0..2 cached off-screen above, Item 3..12 visible on screen, Item 13..16 cached off-screen below): - Swiping right from the AppBar into the ListView must land on Item 3 (the first currently visible item), not jump the scroll view back to Item 0. - Swiping left from a bottom bar into the ListView must land on Item 12 (the last currently visible item), not jump the scroll view down to Item 16. - Hardcoded UIScrollView Implementation: The base -[NSObject(AXPrivCategory) _accessibilityFirstLastOpaqueElement:options:] (0x1F0696488) does not filter by viewport visibility—it simply returns firstObject or lastObject of _accessibilitySortedElementsWithinWithOptions:. Only UIScrollViewAccessibility (+[UIScrollViewAccessibility safeCategoryTargetClassName] -> @"UIScrollView") overrides _accessibilityFirstLastOpaqueElement:options: to query [UIScrollView visibleBounds] (0x1C8DFA77C), intersect each child's accessibilityFrame with visibleBounds in screen coordinates (0x1C8DFA898), and skip off-screen cached children whose visible intersection is smaller than childHeight / _accessibilityVisibleItemDenominator (0x1C8DFA8E0). </details> When `accessibilityFrame` returns `[self globalRect]` without a UIScrollView ancestor in the accessibilityContainer chain, `-[NSObject(AXPrivCategory) _accessibilityVisibleFrame:]` has `[[self _axOutermostScrollParent] _accessibilityContentFrame] == nil`. As a result, it only clips `accessibilityFrame` against the screen bounds rather than the scroll view's viewport. Which means those hidden elements will get a label when voice control is on, among other things. With this patch: https://github.com/user-attachments/assets/2ec109da-147e-48ce-822b-314775b83724 ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant in-code documentation (doc comments with `///`). - [ ] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/CONTRIBUTING.ai.md [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
|
@LongCatIsLooong please fill out the PR description above, afterwards the release team will review this request. |
|
This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter. Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed. |
There was a problem hiding this comment.
Code Review
This pull request refactors iOS accessibility semantics for scrollable containers by allowing FlutterScrollableSemanticsObject to use its underlying FlutterSemanticsScrollView directly as an accessibility container for its children, rather than using a SemanticsObjectContainer. This ensures child elements have a UIScrollView as their ancestor in the UIKit accessibility tree. The changes implement child-traversal and hit-testing methods on FlutterSemanticsScrollView, update coordinate conversions during hit-testing, and add comprehensive unit tests to verify these behaviors. There are no review comments provided, so there is no additional feedback to address.
|
This targets the 3.50 release branch but I'm not sure if this CP will be accepted before the branch getting promoted to stable? |
|
We decided to wait until we verify in test flight |
chunhtai
left a comment
There was a problem hiding this comment.
My take is this is relatively high risk since we aren't sure whether there will be other corner cases (for example voice control and switch controll), but looks like current voiceover is broken without this IIUC. so LGTM anyway.
UIScrollView as a11y scrollable containerUIScrollView as a11y scrollable container
|
Did not get any ITMS-90338 errors when I uploaded a sample app built using the CP commit. |
|
This is still a draft, so I'm going to ignore this for the stable hotfix this week unless someone tells me otherwise. |
Yeah this is still waiting on 2 other patches. |
This pull request is created by automatic cherry pick workflow
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.
Issue Link:
What is the link to the issue this cherry-pick is addressing?
#192774
Impact Description:
VoiceOver on iOS 27 stops at the last visible list item
Changelog Description:
[flutter/192774] on iOS 27, swiping through a scrollable container with VoiceOver stops at the last visible list item.
Workaround:
Is there a workaround for this issue?
No known easy workaround.
Risk:
What is the risk level of this cherry-pick?
The diff without new tests is only 200+ lines and and the logic should be pretty straightforward but we are changing a node in the UIA tree, and the iOS a11y runtime does a lot of runtime type checks and calls private APIs so this may break some hidden contracts.
Test Coverage:
Are you confident that your fix is well-tested by automated tests?
Validation Steps:
Follow the steps in #192774.
Gemini recoded a video which I posted in the PR description of #195731