Skip to content

Conversation

@gspencergoog
Copy link
Contributor

Description

This re-lands the Focus changes in #30040. Correctness changes in routes.dart, and removes the automatic requesting of focus on reparent when there is no current focus, which caused undesirable selections.

Related Issues

Addresses #11344, #1608, #13264, and #1678
Fixes #30084
Fixes #26704

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

LGTM so long as route.navigator is guaranteed to be non-null for some reason or we use route?.navigator

animations.add(widget.route.secondaryAnimation);
_listenable = Listenable.merge(animations);
if (widget.route.isCurrent) {
widget.route.navigator.focusScopeNode.setFirstFocus(focusScopeNode);
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can only be null if it hasn't been pushed yet, or if it has been disposed.

In this case isCurrent checks that the navigator isn't null, and in the case of didPush below, by definition it has been pushed, so it's probably OK as-is. I'm happy to still add the ?'s if you think it would be better to do it defensively against a future change, but they're not needed as-is.

@gspencergoog gspencergoog merged commit 7775c23 into flutter:master Apr 25, 2019
gspencergoog added a commit that referenced this pull request May 1, 2019
In #31614, I added an unfocus() to FocusNodes to allow giving up of focus, but it only worked on the primary focus. This 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 change, 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.
@gspencergoog gspencergoog deleted the fix_focus 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Focus based navigation needs to have the widget Rect. crash on nested Navigator with GlobalKey

3 participants