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

Add enableFeedback param to MaterialButton, RawMaterialButton and IconButton #41972

Merged
merged 14 commits into from Nov 1, 2019

Conversation

NikitaZhelonkin
Copy link
Contributor

@NikitaZhelonkin NikitaZhelonkin commented Oct 4, 2019

In some cases developers need to disable default tap feedback, e.g. if you want to implement custom feedback. This PR gives that opportunity

@fluttergithubbot fluttergithubbot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Oct 4, 2019
@fluttergithubbot
Copy link
Contributor

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@NikitaZhelonkin
Copy link
Contributor Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes and removed cla: no labels Oct 4, 2019
@shihaohong
Copy link
Contributor

Hi, this change looks good! Could you add a few tests to verify that the enableFeedback parameter is working properly for MaterialButton and RawMaterialButton? There should be some useful pointers in ink_well_test.dart.

Thank you!

@shihaohong shihaohong added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 4, 2019
@shihaohong shihaohong changed the title Add enableFeedback param to MaterialButton Add enableFeedback param to MaterialButton and RawMaterialButton Oct 4, 2019
@NikitaZhelonkin NikitaZhelonkin changed the title Add enableFeedback param to MaterialButton and RawMaterialButton Add enableFeedback param to MaterialButton, RawMaterialButton and IconButton Oct 5, 2019
@NikitaZhelonkin
Copy link
Contributor Author

How can i fix " Flutter build is currently broken" ?

@shihaohong shihaohong removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 7, 2019
@shihaohong
Copy link
Contributor

shihaohong commented Oct 7, 2019

That isn't an issue with your PR, so there's nothing you need to do about it.

That basically checks if Flutter's latest master is failing for whatever reason. This prevents new changes from being introduced if there is a potential existing issue in the codebase.

Copy link
Contributor

@shihaohong shihaohong left a comment

Choose a reason for hiding this comment

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

Looks pretty good! I have a request about adding an additional test case, and we should wait to see what Hans has to say about handling long presses with material buttons.

/// Whether detected gestures should provide acoustic and/or haptic feedback.
///
/// For example, on Android a tap will produce a clicking sound and a
/// long-press will produce a short vibration, when feedback is enabled.
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that RawMaterialButton, MaterialButton and IconButton do not have an onLongPress callback or option, which makes this inaccurate. We should either modify the docs to explain that long-press is not supported for these widgets, or implement them correctly.

@HansMuller What seems like the appropriate step here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Related to this issue somewhat, since it explains the default long press behavior for Material buttons and the intent to add an onLongPress param: #40641

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed comment in doc about long-press

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think just removing it is the right approach -- I think if we take the route of not having it respond to long presses, we need to explain how this is different from what is expected. Let's wait for @HansMuller before we continue forward about this topic

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that #40641 will land pretty soon and so it's OK to explain that enableFeedback does what InkWell.enableFeedback does without qualification.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

/// Whether detected gestures should provide acoustic and/or haptic feedback.
///
/// For example, on Android a tap will produce a clicking sound and a
/// long-press will produce a short vibration, when feedback is enabled.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment regarding long-press

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed comment in doc about long-press

Copy link
Contributor

Choose a reason for hiding this comment

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

Commenting here that we've re-added the comment since long-press is now enabled on these buttons

@@ -1191,4 +1192,45 @@ void main() {
final Material material = tester.widget<Material>(rawButtonMaterial);
expect(material.color, const Color(0xff00ff00));
});

group('feedback', () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a set of these tests for RawMaterialButton as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

expect(feedback.hapticCount, 0);
});
});

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove these two additional newlines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -397,6 +398,56 @@ void main() {
expect(focusNode1.hasPrimaryFocus, isTrue);
expect(focusNode2.hasPrimaryFocus, isFalse);
});

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove one newline, since two were added

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

expect(feedback.hapticCount, 0);
});

testWidgets('MaterialButton with enabled feedback', (WidgetTester tester) async {
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels like it tests the default behavior (that enableFeedback is set to true by default). You should probably add a test where enableFeedback is explicitly set to true. ie.

      await tester.pumpWidget(Directionality(
        textDirection: TextDirection.ltr,
        child: MaterialButton(
          onPressed: () {},
          enableFeedback: true, // add a test for this case
        ),
      ));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

expect(feedback.hapticCount, 0);
});

testWidgets('IconButton with enabled feedback', (WidgetTester tester) async {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment about testing for explicitly setting enableFeedback: true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@shihaohong shihaohong self-assigned this Oct 7, 2019
Copy link
Contributor

@shihaohong shihaohong left a comment

Choose a reason for hiding this comment

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

The rest of the changes look good, let's just wait to hear back about the long press detail :)

@shihaohong shihaohong added the waiting for PR to land (fixed) A fix is in flight label Oct 15, 2019
(iconSize + math.min(padding.horizontal, padding.vertical)) * 0.7,
// x 0.5 for diameter -> radius and + 40% overflow derived from other Material apps.
enableFeedback: enableFeedback,
child: result,
Copy link
Contributor

Choose a reason for hiding this comment

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

One of the merges with master cluttered up this section of code. It should be the original, adding the enableFeedback param.

/// Whether detected gestures should provide acoustic and/or haptic feedback.
///
/// For example, on Android a tap will produce a clicking sound and a
/// long-press will produce a short vibration, when feedback is enabled.
Copy link
Contributor

Choose a reason for hiding this comment

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

Commenting here that we've re-added the comment since long-press is now enabled on these buttons

@shihaohong
Copy link
Contributor

@NikitaZhelonkin do you have the bandwidth to finish up this PR?

@NikitaZhelonkin
Copy link
Contributor Author

Yes, what I need to do?

@shihaohong
Copy link
Contributor

There are some failing pre-submit tests that need to be resolved. Also, there is a part of the code I commented on which was formatted incorrectly in one of the recent merges to master that needs to be fixed.

});

group('feedback', () {
FeedbackTester feedback;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shihaohong Why did you remove those tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

It was causing a merge conflict since it's part of an ongoing effort to remove the buttons_test.dart file. There are more specific files that some of these tests belong to (ie. flat_button_test.dart), and it made more sense to have them there.

However, if I seem to have removed a test accidentally that wasn't intentional, please let me know (on looking at the files changed tab on GitHub, it seems like everything looks okay).

@shihaohong shihaohong added waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds and removed waiting for PR to land (fixed) A fix is in flight labels Nov 1, 2019
@shihaohong
Copy link
Contributor

Hi, any updates on this PR? I just want to make sure we can get this one moving along since it's so close to the finish line!

@NikitaZhelonkin
Copy link
Contributor Author

NikitaZhelonkin commented Nov 1, 2019

Fixed formatting; Seems some checks don't pass after merge master from origin repository

@shihaohong
Copy link
Contributor

It seems to be failing the following test:

   info • Unused import: 'feedback_tester.dart' • packages/flutter/test/material/buttons_test.dart:13:8 • unused_import

@@ -10,6 +10,7 @@ import 'package:flutter_test/flutter_test.dart';

import '../rendering/mock_canvas.dart';
import '../widgets/semantics_tester.dart';
import 'feedback_tester.dart';
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this line

@shihaohong
Copy link
Contributor

Make sure to run flutter analyze --flutter-repo locally after your changes to make sure that all analyzer issues are properly addressed.

▌17:09:49▐ RUNNING: cd .; grep --line-number --extended-regexp [[:blank:]]$ packages/flutter/lib/src/material/button.dart packages/flutter/lib/src/material/icon_button.dart packages/flutter/lib/src/material/material_button.dart packages/flutter/test/material/icon_button_test.dart
packages/flutter/lib/src/material/material_button.dart:377:      enableFeedback: enableFeedback,      
▌17:09:49▐ ELAPSED TIME: 0.025s for grep --line-number --extended-regexp [[:blank:]]$ packages/flutter/lib/src/material/button.dart packages/flutter/lib/src/material/icon_button.dart packages/flutter/lib/src/material/material_button.dart packages/flutter/test/material/icon_button_test.dart in .
Detected trailing whitespace in the file[s] listed above.

@NikitaZhelonkin
Copy link
Contributor Author

It shows '36816 issues found." if i run it locally

@shihaohong
Copy link
Contributor

Is there any more detail as to what the issues are? Make sure that you've run flutter update-packages. It might be that your local copy of Flutter's dependencies are not available.

Co-Authored-By: Shi-Hao Hong <shihaohong@google.com>
@NikitaZhelonkin
Copy link
Contributor Author

Yes, flutter update-packages helped, thank you!

Copy link
Contributor

@shihaohong shihaohong left a comment

Choose a reason for hiding this comment

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

LGTM

@shihaohong shihaohong added waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds and removed waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds labels Nov 1, 2019
@shihaohong shihaohong merged commit fbabb26 into flutter:master Nov 1, 2019
Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Nov 26, 2019
…nButton (flutter#41972)

* Wire enableFeedback parameter through MaterialButton, RawMaterialButton, and IconButton.

Co-Authored-By: Shi-Hao Hong <shihaohong@google.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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.

None yet

5 participants