Skip to content
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

Interactive size const #36964

Merged
merged 6 commits into from
Aug 8, 2019
Merged

Conversation

justinmc
Copy link
Contributor

Description

Lots of places in the codebase have a hardcoded value of 48x48 pixels (material) or 44x44 pixels (cupertino) in order to size hit targets in a way that's easily interactive. This PR pulls these two values out as constants and reuses them in all of the places where it was previously hardcoded.

Related Issues

Closes #36713

Tests

Updated tests that were using an old duplicated constant.

@justinmc justinmc requested a review from HansMuller July 25, 2019 20:01
@fluttergithubbot fluttergithubbot added f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Jul 25, 2019
@justinmc justinmc self-assigned this Jul 25, 2019
@justinmc
Copy link
Contributor Author

justinmc commented Jul 25, 2019

I ended up having to create a widgets/constants.dart file and duplicating the material constant there to avoid circular dependencies. Is there a better place to put these constants? Or should I rename the widgets constant to "kMinInteractiveDimensionGeneric" or something like that?

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.

NICE, LGTM.

/// See also:
///
/// * [kMinInteractiveDimensionCupertino]
const double kMinInteractiveDimension = 48.0;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is covered in the "Touch and pointer size" section of the material spec: https://material.io/design/usability/accessibility.html

Probably should provide a link to it.

/// size](https://material.io/guidelines/layout/metrics-keylines.html#metrics-keylines-touch-target-size)
/// The hit region of an icon button will, if possible, be at least
/// kMinInteractiveDimension pixels in size, regardless of the actual
/// [iconSize], to satisfy the [touch target size](https://material.io/guidelines/layout/metrics-keylines.html#metrics-keylines-touch-target-size)
Copy link
Contributor

Choose a reason for hiding this comment

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

Might not be the best spec link; see earlier comment

/// The minimum size that a widget should be in order to be easily interacted
/// with by the user.
@visibleForTesting
const double kMinInteractiveSize = 48.0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately this change makes the PR backwards incompatible. It's a pretty minor one as these things go; but tests may break. We should follow the breaking change protocol for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True. I'll send out that email in a few minutes.

@justinmc justinmc added the c: API break Backwards-incompatible API changes label Jul 29, 2019
@justinmc
Copy link
Contributor Author

Breaking Change Announcement Draft

[Breaking Change] Removing kMinInteractiveSize in text_selection.dart

I'm proposing to remove the constant kMinInteractiveSize from text_selection.dart.  This constant was annotated with @visibleForTesting, so the impact is likely to be very small.

Issue: #36713
PR: #36964

In many places around the framework, we had duplicated hardcoded values for the minimum touch target size (48 pixels for Material and 44 for Cupertino).  The PR consolidates all of those duplicate values into a few shared constants to avoid code duplication.

Anyone who may have been using kMinInteractiveSize should replace it with kMinInteractiveDimension in widgets/constants.dart, which is added in the referenced PR.  Please let me know if you have any trouble migrating and need some help!  I'm available by email and chat.

If anyone objects to this change or would like to discuss further, please comment in the linked PR.

Thanks,

Justin

@justinmc justinmc merged commit 62674ce into flutter:master Aug 8, 2019
@justinmc justinmc deleted the interactive-size-const branch August 8, 2019 20:29
pratikpparikh added a commit to pratikpparikh/zefyr that referenced this pull request Aug 16, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: API break Backwards-incompatible API changes f: cupertino flutter/packages/flutter/cupertino repository 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.

Create a universal constant for minimum interactive size
4 participants