Skip to content

Issues/48903 makes focus traversal more robust - #50522

Closed
chunhtai wants to merge 3 commits into
flutter:masterfrom
chunhtai:issues/48903-take-2
Closed

chunhtai wants to merge 3 commits into
flutter:masterfrom
chunhtai:issues/48903-take-2

Conversation

@chunhtai

@chunhtai chunhtai commented Feb 11, 2020 •

Copy link
Copy Markdown
Contributor

Description

When sets canrequestfocuse= false on a focusScopeNode that is currently focusing one of its child, the focus manager will call unfocus on the current focused child and refocus previous focused child in the tree. However, the search only go one level up in the focus tree. If it cannot find a node to focus in this level, it exit silently and refocus the root focus node.

I updated the logic so that it will search up the tree until it reach the root.

Related Issues

#48903 (comment)

Tests

I added the following tests:

"focus traverse correct when pop mutiple page simultaneously - with focused children"

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.
  • Yes, this is a breaking change. If not, delete the remainder of this section.
    • I wrote a design doc: https://flutter.dev/go/template Replace this with a link to your design doc's short link
    • I got input from the developer relations team, specifically from: Replace with the names of who gave advice
    • I wrote a migration guide: Replace with a link to your migration guide

@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label Feb 11, 2020
@chunhtai chunhtai changed the title Issues/48903 take 2 Issues/48903 makes focus traversal more robust Feb 11, 2020
@goderbauer goderbauer added f: focus Focus traversal, gaining or losing focus a: desktop Running on desktop labels Feb 12, 2020
@goderbauer

Copy link
Copy Markdown
Member

fly-by comment: the analyzer is unhappy.

while (scope != null && !scope.canRequestFocus) {
// This scope is not focusable, we should clears its previously
// focused children and move up the tree.
scope._focusedChildren.clear();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why does it need to clear the children?

@gspencergoog

Copy link
Copy Markdown
Contributor

@chunhtai, Thanks for putting this together. I think #50831 includes the fixes that you have in this PR. The only thing I'm not doing is clearing the focused children as I go up the tree in unfocus, since focus can be removed and added again later, and I don't see why the first focus history needs to change for those nodes when that happens.

So, I'm going to close this if that's OK. Let me know if I'm missing something.

gspencergoog added a commit to gspencergoog/flutter that referenced this pull request Feb 26, 2020
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a: desktop Running on desktop f: focus Focus traversal, gaining or losing focus framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants