8000 Automatic focus highlight mode for FocusManager by gspencergoog · Pull Request #37825 · flutter/flutter · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Automatic focus highlight mode for FocusManager #37825

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 4 commits into from
Aug 16, 2019

Conversation

gspencergoog
Copy link
Contributor

Description

This adds a FocusHighlightMode to the FocusManager that switches based on the type of input that has recently been received. The initial value is based on the platform, but is updated as soon as user input is received. There is also a FocusHighlightStrategy enum so that the developer can change the strategy to a fixed value if needed.

The default is to automatically detect the mode based on the last type of user input. If they use a mouse or keyboard, it shows the focus highlights. If they use a touch interface, then the highlights disappear. This is consistent with the way that Android and Chrome work. The controls still receive focus, only the display of the highlight changes.

Text fields show the focus highlight regardless of the focus highlight mode.

Tests

Added tests for both the FocusManager and InkWell.

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.
  • I checked all the boxes!

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 HansMuller August 8, 2019 00:17
@fluttergithubbot fluttergithubbot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Aug 8, 2019
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 just some small-stuff feedback

///
/// If [highlightMode] returns [FocusHighlightMode.touch], then widgets should
/// only draw their focus highlight if they are currently focused, and they
/// bring up the soft keyboard (e.g. [TextField]) when focused.
Copy link
Contributor

Choose a reason for hiding this comment

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

The TextField reference is little confusing. TextField doesn't always bring up a software keyboard because desktop etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, updated.

}
}

// The list of listeners for [highlightMode] state changes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use a ValueNotifier<FocusHighlightMode> instance here? Might eliminate some of the boilerplate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I didn't do that because the ValueNotifier only provides for a VoidCallback, and I wanted to send the value with the callback. If I used ValueNotifier, I could wrap the ValueChanged<FocusHighlightMode> in a void callback closure, and pass the value of _highlightMode when the void callback is called, but then I couldn't remove the closure later without keeping it in a private list, which is more error-prone, and needs almost as much code as the boilerplate.

@@ -956,6 +995,130 @@ class FocusManager with DiagnosticableTreeMixin {
FocusManager() {
rootScope._manager = this;
RawKeyboard.instance.addListener(_handleRawKeyEvent);
RendererBinding.instance.pointerRouter.addGlobalRoute(_handlePointerEvent);
Copy link
Contributor

Choose a reason for hiding this comment

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

Where do we remove this "global route"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't, because once we construct the FocusManager, we never release it: it's a singleton attached to the binding.

@gspencergoog gspencergoog force-pushed the highlight_mode branch 2 times, most recently from f85fda2 to 45e77d7 Compare August 14, 2019 21:12
@gspencergoog gspencergoog merged commit a11d731 into flutter:master Aug 16, 2019
gspencergoog added a commit to gspencergoog/flutter that referenced this pull request Aug 20, 2019
This reverts commit a11d731 because of a regression in
flutter_gallery_ios32__transition_perf and 90th_percentile_frame_build_time_millis.

See issue flutter#38860.
gspencergoog added a commit that referenced this pull request Aug 21, 2019
…8866)

This reverts commit a11d731 because of a regression in
flutter_gallery_ios32__transition_perf's 90th_percentile_frame_build_time_millis.

Fixes #38860.
@gspencergoog gspencergoog deleted the highlight_mode branch October 9, 2019 23:54
bool showFocus;
switch (WidgetsBinding.instance.focusManager.highlightMode) {
case FocusHighlightMode.touch:
showFocus = false;
Copy link
Member
@xu-baolin xu-baolin Nov 12, 2020

Choose a reason for hiding this comment

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

@gspencergoog Hi,
This change lets the touch phone disabled the focusColor without API documentations. I think we should improve the documentations.

/// The color of the ink response when the parent widget is focused. If this
/// property is null then the focus color of the theme,
/// [ThemeData.focusColor], will be used.
///
/// See also:
///
/// * [highlightShape], the shape of the focus, hover, and pressed
/// highlights.
/// * [hoverColor], the color of the hover highlight.
/// * [splashColor], the color of the splash.
/// * [splashFactory], which defines the appearance of the splash.
final Color? focusColor;

Sometimes it is useful that display the focus color on touch devices, such as #70294

Based on this, I want to add a property of InkWell like alwaysShowFocusColor to optional this behavior.

      case FocusHighlightMode.touch:
        showFocus = alwaysShowFocusColor  ? _shouldShowFocus : false;
        break;

Waiting for your thoughts! thanks very much.

Copy link
Member

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0