Skip to content

Change unfocus to unfocus the entire chain, not just the primary focus - #31909

Merged
gspencergoog merged 3 commits into
flutter:masterfrom
gspencergoog:fix_scope_unfocus
May 1, 2019
Merged

gspencergoog merged 3 commits into
flutter:masterfrom
gspencergoog:fix_scope_unfocus

Conversation

@gspencergoog

@gspencergoog gspencergoog commented May 1, 2019 •

Copy link
Copy Markdown
Contributor

Description

In #31614, I added an unfocus() to FocusNodes to allow giving up of focus, but it only worked on the primary focus. This PR changes that so that it will unfocus the entire chain, not just the primary focus. Now, if you call unfocus() on a FocusNode or FocusScopeNode, and their hasFocus returns true, then after calling unfocus(), it will return false. Before this PR, it would only do that if hasPrimaryFocus was also true.

This also fixes a bug in the way setFirstFocus was implemented, making it conform more to the behavior of the previous implementation. It has simplified logic in reparent, and in when it requests focus for scope nodes that have had setFirstFocus called on them.

Related Issues

Fixes #31784
Fixes #7247
Fixes #31827

Tests

I added the following tests:

  • A test for unfocus.
  • Test that setting first focus requests focus for the scope properly.

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 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

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • No, this is not a breaking change.

@gspencergoog
gspencergoog requested a review from darrenaustin May 1, 2019 15:04
@gspencergoog
gspencergoog force-pushed the fix_scope_unfocus branch 3 times, most recently from 097d475 to 1165ff8 Compare May 1, 2019 16:21
@goderbauer goderbauer added the framework flutter/packages/flutter repository. See also f: labels. label May 1, 2019

@darrenaustin darrenaustin left a comment

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.

Again, not familiar with this code, but it LGTM.

assert(_node != null);
if (isAttached) {
if (_node.hasPrimaryFocus) {
_node.unfocus();

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.

Minor nit, missing a space of indentation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oooh, good eye. Yes, I'll fix that.

@gspencergoog
gspencergoog merged commit be75fb3 into flutter:master May 1, 2019
@gspencergoog
gspencergoog deleted the fix_scope_unfocus branch May 15, 2019 16:29
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

4 participants