Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Modify focus traversal policy search to use focus tree instead of widget tree #121186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 23, 2023

Conversation

gspencergoog
Copy link
Contributor

@gspencergoog gspencergoog commented Feb 22, 2023

Description

When the focus tree and widget tree aren't the same shape, as when an explicit parentNode is supplied to a Focus widget, then the determination of the focus group is sometimes incorrect (Googlers, see b/270168643), because the algorithm uses an inherited widget lookup to find the nearest FocusTraversalGroup to determine the policy, which is incorrect.

This PR modifies the algorithm to traverse the focus tree instead, and introduces a static function FocusTraversalGroup.maybeOfNode , which takes a FocusNode and returns the policy in effect for it. It also modifies the of and maybeOf functions to use inherited widget lookup to find the nearest ancestor Focus or FocusScope widget, and then call maybeOfNode with their implicit FocusNode to determine the policy instead of searching for the FocusTraversalGroup ancestor directly, so that they'll follow the focus tree instead of the widget tree once they find a focus node.

To implement this, I also added a createDependency argument to Focus.of, Focus.maybeOf, and FocusScope.of, which allows callers to find a focus node in the widget tree without creating a rebuild dependency.

Tests

  • Added a test to check that the correct policy is found when the widget and focus trees aren't the same shape.

@flutter-dashboard flutter-dashboard bot added f: focus Focus traversal, gaining or losing focus framework flutter/packages/flutter repository. See also f: labels. tool Affects the "flutter" command-line tool. See also t: labels. labels Feb 22, 2023
@gspencergoog gspencergoog marked this pull request as ready for review February 22, 2023 19:08
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

@gspencergoog gspencergoog force-pushed the focus_tree_groups branch 3 times, most recently from 66cbc4f to 2564afc Compare February 23, 2023 01:18
@gspencergoog gspencergoog added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 23, 2023
@auto-submit auto-submit bot merged commit b1d8a4e into flutter:master Feb 23, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 24, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 24, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 24, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 24, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 24, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 25, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 25, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 26, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 26, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 26, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 27, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 27, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 27, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 27, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 27, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 27, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 27, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App f: focus Focus traversal, gaining or losing focus framework flutter/packages/flutter repository. See also f: labels. tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants