Skip to content

[iOS] Accessibility hit test in a scrollable never reaches a platform view's native subviews #194389

Open

Description

@uwuclxdy

Steps to reproduce

  1. flutter create --platforms ios bug, then replace lib/main.dart and ios/Runner/AppDelegate.swift with the code sample below. It shows a bare UISegmentedControl in a UiKitView twice: once outside any scrollable, once as the first child of a ListView.
  2. Run it on an iOS simulator.
  3. Run the UI test below in a UI-testing bundle targeting the app (XCUIApplication(bundleIdentifier:)). It prints each segment's frame and isHittable.

Expected results

Every segment is hittable, inside the ListView as well as outside it.

Actual results

Outside the list every segment is hittable. Inside the list no segment is, though each has a real frame and the segmented control itself reads hittable:

REPRO control0 frame=(16.0, 78.0, 210.0, 32.0) hittable=true
REPRO control0 segment0 label=Out1 frame=(16.0, 78.0, 70.0, 32.0) hittable=true
REPRO control0 segment1 label=Out2 frame=(86.0, 78.0, 70.0, 32.0) hittable=true
REPRO control0 segment2 label=Out3 frame=(156.0, 78.0, 70.0, 32.0) hittable=true
REPRO control1 frame=(16.0, 142.0, 370.0, 32.0) hittable=true
REPRO control1 segment0 label=In1 frame=(16.0, 142.0, 123.0, 32.0) hittable=false
REPRO control1 segment1 label=In2 frame=(139.0, 142.0, 123.0, 32.0) hittable=false
REPRO control1 segment2 label=In3 frame=(262.0, 142.0, 124.0, 32.0) hittable=false

The window's accessibility hit test at an in-list segment's centre returns the list's FlutterSemanticsScrollView; outside the list it returns the UISegment. VoiceOver touch exploration goes through the same hit test, so a VoiceOver user cannot touch a single segment inside a scrolling list (VoiceOver itself was not run, the simulator has none). A UISwitch and a UISlider in the same list stay hittable.

Root cause (engine at 5f77625673248ee5846fbcaf5d3e1a3878386fd7):

  • SemanticsObject.mm:567 _accessibilityHitTest:withEvent: returns [self search:point], and search: (:543) returns the first node holding the point that isFocusable.
  • isFocusable (:468) is true for any action outside kScrollableSemanticsActions (:480). That mask (lib/ui/semantics/semantics_node.h:60) covers scroll up/down/left/right but not scrollToOffset, which every Scrollable sets since Add handler for SemanticsAction.scrollToOffset #159811. A ListView's node carries scrollToOffset | scrollUp (actions=8388624 in a widget test at the same revision), so the list counts as focusable.
  • The platform view's node has no label or action, so search: skips it and returns the scroll node. The platform view's own subtree is never asked.

Related: #164483 (fixed by #184155) made FlutterSemanticsScrollView stop being an element without a label; this case still reproduces after that fix.

Code sample

Code sample

lib/main.dart:

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() => runApp(const ReproApp());

class ReproApp extends StatelessWidget {
  const ReproApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SafeArea(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              const Padding(
                padding: EdgeInsets.all(16),
                child: _Segmented(titles: ['Out1', 'Out2', 'Out3']),
              ),
              Expanded(
                child: ListView(
                  padding: const EdgeInsets.all(16),
                  children: [
                    const _Segmented(titles: ['In1', 'In2', 'In3']),
                    for (var i = 0; i < 40; i++) ListTile(title: Text('Row $i')),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class _Segmented extends StatelessWidget {
  const _Segmented({required this.titles});

  final List<String> titles;

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: 210,
      height: 32,
      child: UiKitView(
        viewType: 'segmented',
        creationParams: titles,
        creationParamsCodec: const StandardMessageCodec(),
      ),
    );
  }
}

ios/Runner/AppDelegate.swift:

import Flutter
import UIKit

@main
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }

  func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
    GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
    let registrar = engineBridge.pluginRegistry.registrar(forPlugin: "SegmentedRepro")!
    registrar.register(SegmentedFactory(), withId: "segmented")
  }
}

final class SegmentedFactory: NSObject, FlutterPlatformViewFactory {
  func create(withFrame frame: CGRect, viewIdentifier viewId: Int64, arguments args: Any?)
    -> FlutterPlatformView
  {
    SegmentedView(titles: args as? [String] ?? ["A", "B", "C"])
  }

  func createArgsCodec() -> any FlutterMessageCodec & NSObjectProtocol {
    FlutterStandardMessageCodec.sharedInstance()
  }
}

final class SegmentedView: NSObject, FlutterPlatformView {
  private let control: UISegmentedControl

  init(titles: [String]) {
    control = UISegmentedControl(items: titles)
    control.selectedSegmentIndex = 0
  }

  func view() -> UIView { control }
}

UI test:

import XCTest

final class SegReproUITests: XCTestCase {
  func testSegmentHittability() throws {
    let app = XCUIApplication(bundleIdentifier: "com.example.bug")
    app.launch()
    XCTAssertTrue(app.segmentedControls.firstMatch.waitForExistence(timeout: 30))
    Thread.sleep(forTimeInterval: 2)
    for i in 0..<app.segmentedControls.count {
      let control = app.segmentedControls.element(boundBy: i)
      print("REPRO control\(i) frame=\(control.frame) hittable=\(control.isHittable)")
      for j in 0..<control.buttons.count {
        let segment = control.buttons.element(boundBy: j)
        print(
          "REPRO control\(i) segment\(j) label=\(segment.label) frame=\(segment.frame)"
            + " hittable=\(segment.isHittable)")
      }
    }
  }
}

Flutter Doctor output

Doctor output
[!] Flutter (Channel stable, 3.47.0, on macOS 27.0.1 26A434 darwin-arm64, locale en-US) [160ms]
    • Flutter version 3.47.0 on channel stable at /Users/macmini/fvm/versions/3.47.0
    ! The flutter binary is not on your path. Consider adding /Users/macmini/fvm/versions/3.47.0/bin to your path.
    ! The dart binary is not on your path. Consider adding /Users/macmini/fvm/versions/3.47.0/bin to your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4cf2416426 (9 weeks ago), 2026-08-11 11:53:49 -0700
    • Engine revision 5f77625673
    • Dart version 3.13.0
    • DevTools version 2.60.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✗] Android toolchain - develop for Android devices [114ms]
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/to/macos-android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.


[!] Xcode - develop for iOS and macOS (Xcode 27.0) [1,315ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 27A266a
    ! CocoaPods not installed.
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/to/platform-plugins
      For installation instructions, see https://guides.cocoapods.org/using/getting-started.html#installation

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome) [4ms]
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Connected device (2 available) [6.3s]
    • xui-n3-27b (mobile) • 457A2341-0261-4459-ADE9-C29BB865DB3C • ios          • com.apple.CoreSimulator.SimRuntime.iOS-27-0 (simulator)
    • macOS (desktop)     • macos                                • darwin-arm64 • macOS 27.0.1 26A434 darwin-arm64

[✓] Network resources [479ms]
    • All expected network resources are available.

! Doctor found issues in 4 categories.

Activity

  1. added
    in triage
    on Oct 15, 2026
  2. saurabh-mirajkar commented on Oct 15, 2026

    @saurabh-mirajkar
    Contributor

    @uwuclxdy Thanks for the report. Reproduced on the iOS 27.0 simulator using the provided sample and latest stable Flutter 3.47.7. Routing this to the team for further investigation.

    Relevant test output
    Running tests...
        t =      nans Interface orientation changed to Portrait
    Test Suite 'SegReproUITests' started at 2026-10-15 14:17:41.185.
    Test Case '-[RunnerUITests.SegReproUITests testSegmentHittability]' started.
        t =     0.00s Start Test at 2026-10-15 14:17:41.187
        t =     0.02s Set Up
        t =     0.03s Open com.example.bug
        t =     0.03s     Launch com.example.bug
        t =     1.17s         Setting up automation session
    AX Safe category class 'SFBarButtonGroupContainerAccessibility' was not found!
    objc[56871]: Class UIAccessibilityLoaderWebShared is implemented in both /Library/Developer/CoreSimulator/Volumes/iOS_24A434/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 27.0.simruntime/Contents/Resources/RuntimeRoot/System/Library/AccessibilityBundles/WebKit.axbundle/WebKit (0x10a070398) and /Library/Developer/CoreSimulator/Volumes/iOS_24A434/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 27.0.simruntime/Contents/Resources/RuntimeRoot/System/Library/AccessibilityBundles/WebCore.axbundle/WebCore (0x10a164310). This may cause spurious casting failures and mysterious crashes. One of the duplicates must be removed or renamed.
        t =     3.42s         Wait for com.example.bug to idle
    AX Safe category class 'SLHighlightDisambiguationPillViewAccessibility' was not found!
        t =     5.82s Waiting 30.0s for SegmentedControl (First Match) to exist
        t =     6.87s     Checking `Expect predicate `existsNoRetry == 1` for object SegmentedControl (First Match)`
        t =     6.88s         Checking existence of `SegmentedControl (First Match)`
        t =     8.95s Get number of matches for: Descendants matching type SegmentedControl
        t =     8.99s Find the SegmentedControl (Element at index 0)
        t =     9.04s Find the "platform_view[0]" SegmentedControl
    REPRO control0 frame=(16.0, 78.0, 210.0, 32.0) hittable=true
        t =     9.13s Get number of matches for: Descendants matching type Button
        t =     9.17s Find the Button (Element at index 0)
        t =     9.22s Find the "Out1" Button
        t =     9.25s Find the "Out1" Button
    REPRO control0 segment0 label=Out1 frame=(16.0, 78.0, 70.0, 32.0) hittable=true
        t =     9.28s Find the Button (Element at index 1)
        t =     9.31s Find the "Out2" Button
        t =     9.34s Find the "Out2" Button
    REPRO control0 segment1 label=Out2 frame=(86.0, 78.0, 70.0, 32.0) hittable=true
        t =     9.38s Find the Button (Element at index 2)
        t =     9.41s Find the "Out3" Button
        t =     9.45s Find the "Out3" Button
    REPRO control0 segment2 label=Out3 frame=(156.0, 78.0, 70.0, 32.0) hittable=true
        t =     9.48s Find the SegmentedControl (Element at index 1)
        t =     9.51s Find the "platform_view[1]" SegmentedControl
    REPRO control1 frame=(16.0, 142.0, 370.0, 32.0) hittable=true
        t =     9.57s Get number of matches for: Descendants matching type Button
        t =     9.61s Find the Button (Element at index 0)
        t =     9.64s Find the "In1" Button
        t =     9.67s Find the "In1" Button
    REPRO control1 segment0 label=In1 frame=(16.0, 142.0, 123.0, 32.0) hittable=false
        t =     9.72s Find the Button (Element at index 1)
        t =     9.75s Find the "In2" Button
        t =     9.79s Find the "In2" Button
    REPRO control1 segment1 label=In2 frame=(139.0, 142.0, 123.0, 32.0) hittable=false
        t =     9.84s Find the Button (Element at index 2)
        t =     9.87s Find the "In3" Button
        t =     9.90s Find the "In3" Button
    REPRO control1 segment2 label=In3 frame=(262.0, 142.0, 124.0, 32.0) hittable=false
        t =     9.95s Tear Down
    Test Case '-[RunnerUITests.SegReproUITests testSegmentHittability]' passed (10.282 seconds).
    Test Suite 'SegReproUITests' passed at 2026-10-15 14:17:51.469.
    	 Executed 1 test, with 0 failures (0 unexpected) in 10.282 (10.284) seconds
  3. added
    platform-ios
    a: accessibility
    a: platform-views
    has reproducible steps
    fyi-ios
    team-accessibility
    and removed
    in triage
    on Oct 15, 2026
  4. uwuclxdy commented on Oct 18, 2026

    @uwuclxdy
    Author

    Two more findings on the same engine revision (5f77625673, Flutter 3.47.0, iOS 27.0 simulator), from an app with UISwitch, UIButton and pop-up UIButton platform views in a ListView:

    • A UISwitch reading hittable doesn't mean it's reachable. _accessibilityHitTest:withEvent: at its centre returns the FlutterSemanticsScrollView, as for the segments, and accessibilityActivate on that returns NO with nothing toggled (3/3 launches). XCUITest's isHittable reads true there anyway, so it isn't a usable signal for this bug, and the switch is affected as much as the segments.
    • A Text sharing the list child with the platform view merges its label into that child's node, so search: returns that node at every point inside the child (362x397pt in my case). The hit test lands on a static text block covering the controls, and accessibilityActivate on it returns NO too.

    Wrapping each UiKitView in a Semantics node with the control's label, value and an onTap that drives the native control, and setting the native view's accessibilityElementsHidden, works around both: search: returns that node at the control's rect and activating it runs the action (3/3 launches). So imo the fix belongs in search:: when the point falls inside a platform view's node, it could return the native view's own accessibility hit test instead of skipping it.

  5. added
    team-ios
    fyi-accessibility
    P2
    and removed
    fyi-ios
    team-accessibility
    P2
    on Oct 21, 2026
  6. hannah-hyj commented on Oct 21, 2026

    @hannah-hyj
    Member

    From a11y triage: I think this is maybe a P2 because only hit test is affected but not traversal.

  7. added
    triaged-accessibility
    on Oct 21, 2026
  8. removed
    fyi-accessibility
    triaged-accessibility
    on Oct 21, 2026
  9. added
    triaged-ios
    P2
    on Oct 23, 2026
  10. spencerchase11-ops commented on Nov 21, 2026

    @spencerchase11-ops

    The same root cause also affects plain Flutter content, with no platform view. In a ListView with space between its items, a VoiceOver touch in that space focuses the whole list. The Caption Panel shows nothing new, because the list has no label.

    Repro. A fresh flutter create app (below): a ListView.separated of 48 pt items with 48 pt gaps. Debug build, iOS 27.0 Simulator (iPhone 18 Pro). VoiceOver runs in this Simulator (Settings > Accessibility > VoiceOver), and its Caption Panel shows what it speaks.

    1. Touch Item 1. The cursor frames Item 1, and the Caption Panel shows "Item 1".
    2. Touch the gap below Item 1. The cursor frames the whole list. The Caption Panel still shows "Item 1".
    3. Touch Item 2, the gap below it, and the gap below Item 3. The item works. Both gaps focus the list.

    The result is the same on 3.44.4, 3.50.0 and 3.50.1.

    Why. The list's node has no label and has scrollUp | scrollToOffset (actions=8388624 in a widget test). On 3.50.1, kScrollableSemanticsActions (lib/ui/semantics/semantics_node.h:60-61) does not include kScrollToOffset, so -[SemanticsObject isFocusable] (SemanticsObject.mm:525-538) is true for the list. search: (:604-618) then returns the list for any point inside it that no item covers. A widget test that applies this rule to the list's SemanticsData fails on 3.44.4, 3.50.0 and 3.50.1, and passes with the master mask. It models the engine rule. It is not engine code.

    Master. #195731 adds kScrollToOffset to the mask (semantics_node.h:60-62 on master, 5423f94), and the rule moved to -isAccessibilityElement (SemanticsObject.mm:535-560). That should fix this case. I could not run a master engine to confirm it. Its 3.50 cherry-pick, #196163, is still a draft. I did not check whether #195731 also fixes the platform view case in this issue.

    lib/main.dart
    import 'package:flutter/material.dart';
    
    void main() => runApp(const MaterialApp(home: GapPage()));
    
    /// A plain ListView. Each item is 48 pt tall and the items are 48 pt apart.
    class GapPage extends StatelessWidget {
      const GapPage({super.key});
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(title: const Text('Gaps')),
          body: ListView.separated(
            padding: const EdgeInsets.symmetric(vertical: 24),
            itemCount: 12,
            separatorBuilder: (BuildContext context, int index) =>
                const SizedBox(height: 48),
            itemBuilder: (BuildContext context, int index) => SizedBox(
              height: 48,
              child: Center(child: Text('Item ${index + 1}')),
            ),
          ),
        );
      }
    }
    test/gap_focus_test.dart (a model of the engine rule)
    // A MODEL of how the iOS embedder picks the element a VoiceOver touch lands
    // on. It is not engine code. It copies:
    //   -[SemanticsObject isFocusable]  ios/framework/Source/SemanticsObject.mm
    //                                   (3.50.0: lines 525-538; 3.44.4: 468-481)
    //   kScrollableSemanticsActions     lib/ui/semantics/semantics_node.h
    //                                   (3.50.0 and 3.44.4: lines 60-61)
    // -[SemanticsObject search:] (3.50.0: lines 604-618) returns the first node
    // under the touch, in hit-test order, whose isFocusable is true.
    // _accessibilityHitTest:withEvent: (3.50.0: lines 628-633) returns that node.
    // A gap between two items is inside the list's node and inside no item, so a
    // touch there lands on the list's node whenever isFocusable is true for it.
    //
    // On master (afad796) the mask also has kScrollToOffset (PR #195731).
    
    import 'dart:ui' show SemanticsAction;
    
    import 'package:flutter/material.dart';
    import 'package:flutter/rendering.dart';
    import 'package:flutter_test/flutter_test.dart';
    
    import 'package:scroll_gap_focus/main.dart';
    
    final int maskShipped = SemanticsAction.scrollUp.index |
        SemanticsAction.scrollDown.index |
        SemanticsAction.scrollLeft.index |
        SemanticsAction.scrollRight.index;
    
    final int maskMaster = maskShipped | SemanticsAction.scrollToOffset.index;
    
    bool iosIsFocusable(SemanticsData d, int scrollMask) =>
        (d.flagsCollection.hasImplicitScrolling && d.flagsCollection.isHidden) ||
        d.label.isNotEmpty ||
        d.value.isNotEmpty ||
        d.hint.isNotEmpty ||
        (d.actions & ~scrollMask) != 0;
    
    String actionNames(int actions) => SemanticsAction.values
        .where((SemanticsAction a) => actions & a.index != 0)
        .map((SemanticsAction a) => a.name)
        .join(', ');
    
    Future<SemanticsData> listNode(WidgetTester tester) async {
      await tester.pumpWidget(const MaterialApp(home: GapPage()));
      final SemanticsNode node = find.semantics
          .byPredicate(
            (SemanticsNode n) =>
                n.getSemanticsData().flagsCollection.hasImplicitScrolling,
            describeMatch: (_) => 'the list',
          )
          .evaluate()
          .single;
      return node.getSemanticsData();
    }
    
    void main() {
      testWidgets('a touch in the gap between two items: the unlabeled list is '
          'not a touch target (iOS rule as shipped)', (WidgetTester tester) async {
        final SemanticsHandle handle = tester.ensureSemantics();
        final SemanticsData list = await listNode(tester);
    
        // The gap: 48 pt between the bottom of Item 1 and the top of Item 2.
        final Rect item1 = tester.getRect(find
            .ancestor(of: find.text('Item 1'), matching: find.byType(SizedBox))
            .first);
        final Rect item2 = tester.getRect(find
            .ancestor(of: find.text('Item 2'), matching: find.byType(SizedBox))
            .first);
        final Offset gap = Offset(item1.center.dx, (item1.bottom + item2.top) / 2);
        expect(item2.top - item1.bottom, 48);
        expect(item1.contains(gap) || item2.contains(gap), isFalse);
    
        // ignore: avoid_print
        print('list node: label="${list.label}" value="${list.value}" '
            'hint="${list.hint}" actions=${list.actions} '
            '(${actionNames(list.actions)}); gap point $gap');
    
        expect(list.label, isEmpty);
        expect(list.actions & SemanticsAction.scrollToOffset.index, isNonZero);
        expect(iosIsFocusable(list, maskShipped), isFalse,
            reason: 'scrollToOffset is not in kScrollableSemanticsActions, so '
                'isFocusable is true for the list and search: returns it for a '
                'touch in the gap');
        handle.dispose();
      });
    
      testWidgets('the same rule with the mask on master (PR #195731)',
          (WidgetTester tester) async {
        final SemanticsHandle handle = tester.ensureSemantics();
        final SemanticsData list = await listNode(tester);
        expect(iosIsFocusable(list, maskMaster), isFalse);
        handle.dispose();
      });
    }
    Test output on 3.50.1 (excerpt)
    list node: label="" value="" hint="" actions=8388624 (scrollUp, scrollToOffset); gap point Offset(400.0, 152.0)
    Expected: false
      Actual: <true>
    scrollToOffset is not in kScrollableSemanticsActions, so isFocusable is true for the list and
    search: returns it for a touch in the gap
    00:00 +0 -1: a touch in the gap between two items: the unlabeled list is not a touch target (iOS rule as shipped) [E]
    00:00 +1 -1: Some tests failed.
    

    The second test, with the master mask, passes. 3.44.4 and 3.50.0 print the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2a: accessibilitya: platform-viewshas reproducible stepsplatform-iosteam-iostriaged-ios

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions