Skip to content

Fix SemanticsNode.rect position for nested scrollables with useTwoPan…#62359

Merged
fluttergithubbot merged 1 commit intoflutter:masterfrom
nscobie:issue/61631
Jul 31, 2020
Merged

Fix SemanticsNode.rect position for nested scrollables with useTwoPan…#62359
fluttergithubbot merged 1 commit intoflutter:masterfrom
nscobie:issue/61631

Conversation

@nscobie
Copy link
Contributor

@nscobie nscobie commented Jul 27, 2020

…eSemantics

Description

Issue

If a scrolling widget such as ListView or GridView (with shrinkWrap: true) is nested under another scrolling widget such as SingleChildScrollView, then new "beyond the fold" content which is revealed by swiping off screen cannot be selected by tap, and continued swiping beyond the fold will eventually make a11y focus jump to a random element on iOS.

Repro case
import 'package:flutter/material.dart';

void main() => runApp(A11yApp());

class A11yApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final appBar =
    AppBar(title: const Icon(Icons.archive));

    return MaterialApp(
      home: Scaffold(
        appBar: appBar,
        body: SingleChildScrollView(
          child: Column(
            children: [_buildGridView(), _buildGridView(), _buildGridView()],
          ),
        ),
      ),
    );
  }

  Widget _buildGridView() {
    return Column(
      children: [
        const Text('Grid header'),
        GridView.count(
          shrinkWrap: true,
          crossAxisSpacing: 10,
          mainAxisSpacing: 10,
          crossAxisCount: 2,
          children: <Widget>[
            for (var i = 0; i < 50; ++i)
              Container(
                padding: const EdgeInsets.all(8),
                color: Colors.green[100],
                child: Text('Number $i'),
              ),
          ],
        ),
      ],
    );
  }
}

Fix

The inner semantics pane of the child ListView/GridView needs to have its position updated to match the outer semantics pane when the parent SingleChildScrollView scrolls.

This comment on issue #61631 explains the technical details of the fix.

Related Issues

Fixes #61631

Tests

I added the following tests:

  • widgets/scrollable_semantics_test.dart
    • "transform of inner node from useTwoPaneSemantics scrolls correctly with nested scrollables"
      • Ensures the global rect of the inner and outer semantics panes of a ListView match when nested under a SingleChildScrollView. The parent SingleChildScrollView is scrolled to the end -> beginning -> middle of the shrink-wrapped ListView's hidden elements to test both scroll directions.

Checklist

Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.

@fluttergithubbot fluttergithubbot added a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) framework flutter/packages/flutter repository. See also f: labels. labels Jul 27, 2020
@nscobie nscobie marked this pull request as draft July 27, 2020 22:05
@nscobie nscobie added customer: money (g3) f: scrolling Viewports, list views, slivers, etc. P1 labels Jul 27, 2020
@nscobie nscobie requested review from gaaclarke and goderbauer July 27, 2020 22:25
@nscobie
Copy link
Contributor Author

nscobie commented Jul 27, 2020

@goderbauer This behavior wasn't covered by tests before, and I don't have enough knowledge on how the framework is typically used to know if this could break other sliver/scrolling/nesting configurations. Can you think of any issues this might introduce?

The debugging logs in the linked comment might give more context on the issue, but are admittedly hard to follow. I'm available to discuss further or elaborate on the logs.

@nscobie nscobie marked this pull request as ready for review July 27, 2020 22:39
@nscobie nscobie self-assigned this Jul 27, 2020
@chunhtai
Copy link
Contributor

cirrus looks unhappy, can you rebase off the master branch?

@nscobie nscobie force-pushed the issue/61631 branch 2 times, most recently from 0a75b49 to 52fa1f1 Compare July 29, 2020 00:25
@nscobie
Copy link
Contributor Author

nscobie commented Jul 29, 2020

cirrus looks unhappy, can you rebase off the master branch?

Had to also fix some lints I missed, but seems good now.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code and test looks good to me. I'll defer to the others with respect to the wisdom of the change as-is. Nice sleuthing.

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fluttergithubbot fluttergithubbot merged commit 19f8fb1 into flutter:master Jul 31, 2020
Pragya007 pushed a commit to Pragya007/flutter that referenced this pull request Aug 11, 2020
mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

a11y focus moves randomly in GridView with many children.

6 participants