-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Make pressing and moving on CupertinoButton closer to native behavior. #161731
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
Conversation
ceb258b to
560a9ff
Compare
|
This is awesome! I'm still reading the code (and it looks great so far) and I have a question: If I understand correctly, only Cupertino uses the tap-move gesture, while other existing code (such as Material) still cancels on movement. How did |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally great! I think iOS's button behavior is slightly different from the current code (see comments below), but no major issues!
| expect(find.text('Copy'), findsOneWidget); | ||
| }, | ||
| variant: TargetPlatformVariant.all(), | ||
| variant: TargetPlatformVariant.mobile(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why this is changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, maybe just don't do this in this PR. I guess you did it just because this test appears to be relevant only to mobile? But I worry that it could conceal a failure if we make this change in this PR.
| } | ||
|
|
||
| void _handTapMove(TapMoveDetails event) { | ||
| final double distance = switch (defaultTargetPlatform) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit troubled by the duplicate switch statement here and in the unit test. What do you think if we extract this switch statement as a function and replace the kCupertinoButtonTapMoveOpacityChangeDistance constant?
|
Sorry for the delay due to the Chinese New Year holiday.
|
|
The reason why I asked that is because there would be two kinds of behaviors:
Does your PR keep the first kind for existing widgets, and if so, how? |
|
@dkwingsmt In |
dkwingsmt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with minor suggestions. Thank you very much!
justinmc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few questions and small changes. I think the only real blockers are the "eyeballed" comment and the question about being a breaking change.
Thanks for the PR! It looks like this required some reworking of the events here that probably wasn't easy, but everything looks very Fluttery and like a good change.
| /// The parameter `move` is the move event of the primary pointer that started | ||
| /// the tap sequence. | ||
| @protected | ||
| void handleTapMove({required PointerMoveEvent move}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this possibly be a breaking change for users that implement BaseTapGestureRecognizer? Would it be desirable to add a default implementation here to avoid this, or do we want to break people that implement BaseTapGestureRecognizer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm running the Google tests on this PR to check if there are breakages there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recently there has been a complaint about we adding such methods breaking packages that implement it. I think it'll help developers if we mention such "non-breaking-by-Flutter-standards" changes, especially "notable new methods" in the patchnotes. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that sounds like a good idea to me. I've seen this kind of thing come up before too.
I think in this case it makes sense to allow users to subtype BaseTapGestureRecognizer, right? And if they are, then do they care about implementing handleTapMove? Maybe not, since I guess they would probably have some specific use case for their subclass that doesn't care about this "tap and move" bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it makes sense to provide a default implementation in this case too.
| String get debugDescription => 'any tap'; | ||
|
|
||
| @override | ||
| void handleTapMove({required PointerMoveEvent move}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you provided a default implementation for handleTapMove, then you wouldn't need this. Not sure if that's good or not though.
| expect(find.text('Copy'), findsOneWidget); | ||
| }, | ||
| variant: TargetPlatformVariant.all(), | ||
| variant: TargetPlatformVariant.mobile(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, maybe just don't do this in this PR. I guess you did it just because this test appears to be relevant only to mobile? But I worry that it could conceal a failure if we make this change in this PR.
|
@dkwingsmt @justinmc Waiting for a new LGTM. |
dkwingsmt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
justinmc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 Thanks for the fixes.
Roll Flutter from 2e570ca to 842db35 (59 revisions) flutter/flutter@2e570ca...842db35 2025-03-02 [email protected] Roll Skia from ad64415050aa to 101eee8fce59 (1 revision) (flutter/flutter#164449) 2025-03-02 [email protected] Roll Fuchsia Linux SDK from ln3joxJfRN2XGhvCv... to AO1KirSDI7-MVYNPN... (flutter/flutter#164440) 2025-03-02 [email protected] android: Clean up gen_snapshot artifact build (flutter/flutter#164418) 2025-03-02 [email protected] Start using `bin/cache/engine.{stamp|realm}` instead of `bin/internal/engine.{realm|version}`. (flutter/flutter#164352) 2025-03-01 [email protected] Add macos/android_debug_unopt to local_engine.json (flutter/flutter#164410) 2025-03-01 [email protected] Delete unused build archive targets (flutter/flutter#164414) 2025-03-01 [email protected] Roll Fuchsia Linux SDK from QMun2itYrV_zUYrvW... to ln3joxJfRN2XGhvCv... (flutter/flutter#164423) 2025-03-01 [email protected] Roll Skia from ac14158663ea to ad64415050aa (1 revision) (flutter/flutter#164413) 2025-03-01 [email protected] Update linux_host_engine.json ci/host_release description (flutter/flutter#164402) 2025-03-01 [email protected] In update_engine_version_test.dart, do not populate the test environment with the host platform environment (flutter/flutter#164395) 2025-03-01 [email protected] Roll-forward #164317: Use `bin/cache/engine.stamp` (flutter/flutter#164401) 2025-02-28 [email protected] Make pressing and moving on CupertinoButton closer to native behavior. (flutter/flutter#161731) 2025-02-28 [email protected] Roll Skia from 4005ba3ca7b6 to ac14158663ea (7 revisions) (flutter/flutter#164404) 2025-02-28 [email protected] [macOS] Prepare FlutterKeyboardManager for multi-view (flutter/flutter#163962) 2025-02-28 [email protected] Add PlatformDispatcher.engineId (flutter/flutter#163476) 2025-02-28 [email protected] Move `integration_test.FlutterDeviceScreenshotTest` to the framework slow shard (flutter/flutter#164398) 2025-02-28 [email protected] Fix: Update DelegatedTransition animation parameter correctly (flutter/flutter#163853) 2025-02-28 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Write an identical value to `bin/cache/engine.stamp` to prepare for migration (#164317)" (flutter/flutter#164396) 2025-02-28 [email protected] Add action for configuring default action of EditableText.onTapUpOutside (flutter/flutter#162575) 2025-02-28 [email protected] Align jvmTarget usages across codebase, while editing build.gradle files align them with android version documentation (flutter/flutter#164200) 2025-02-28 [email protected] Roll Packages from 01d3d5c to 70b41e1 (5 revisions) (flutter/flutter#164380) 2025-02-28 [email protected] [tool] Allow using archiveName in android bundle build (flutter/flutter#162390) 2025-02-28 [email protected] Fix incorrectly checking for invalid environment variables in the tool (flutter/flutter#164101) 2025-02-28 [email protected] Support forward and back buttons (flutter/flutter#164356) 2025-02-28 [email protected] Fix window creation callback for multi-window (flutter/flutter#164353) 2025-02-28 [email protected] Fix flutter doctor usage of eglinfo in failure cases. (flutter/flutter#164334) 2025-02-28 [email protected] Refactor writing of package config in tests (flutter/flutter#163734) 2025-02-28 [email protected] Fixed the issue that Slider's secondaryTrackValue is not updated. (flutter/flutter#163996) 2025-02-28 [email protected] Roll pub packages (flutter/flutter#164357) 2025-02-28 [email protected] Remove `Mac mac_unopt` presubmit retry count (flutter/flutter#164350) 2025-02-28 [email protected] Roll Fuchsia Linux SDK from 1elkOxihZuTEiTXzY... to QMun2itYrV_zUYrvW... (flutter/flutter#164351) 2025-02-28 [email protected] Drag handles only need to be tested on mobile platforms. (flutter/flutter#163723) 2025-02-28 [email protected] [Android] Use java for looking up Android API level. (flutter/flutter#163558) 2025-02-28 [email protected] Write an identical value to `bin/cache/engine.stamp` to prepare for migration (flutter/flutter#164317) 2025-02-27 [email protected] Wires up expanded state in web engine (flutter/flutter#164048) 2025-02-27 [email protected] Remove Cheserton's File (flutter/flutter#164340) 2025-02-27 [email protected] Replace update semantics handler with signal. (flutter/flutter#163583) 2025-02-27 [email protected] Split up the conical gradient fragment shader (flutter/flutter#164058) 2025-02-27 [email protected] Roll Skia from c16b145749d4 to 4005ba3ca7b6 (3 revisions) (flutter/flutter#164339) 2025-02-27 [email protected] Delete and update stale documentation regarding engine/engine hash. (flutter/flutter#164324) 2025-02-27 [email protected] Document how `engine.version` (is/will be) computed (flutter/flutter#164335) 2025-02-27 [email protected] Update conductor to write engine.version file (flutter/flutter#163350) 2025-02-27 [email protected] remove last usages of min/compile/target SdkVersion, align sourceCompatibility across repo and update android version documentation (flutter/flutter#164198) 2025-02-27 [email protected] Update links to the `flutter/engine` repository for the monorepo. (flutter/flutter#164328) 2025-02-27 [email protected] Add empty `io.flutter.app.FlutterApplication` to give deprecation notice, and un-break projects that have not migrated (flutter/flutter#164233) 2025-02-27 [email protected] Revert dart sdks that were causing dartaotruntime issues in g3 (flutter/flutter#164307) ...
Roll Flutter from 2e570ca to 842db35 (59 revisions) flutter/flutter@2e570ca...842db35 2025-03-02 [email protected] Roll Skia from ad64415050aa to 101eee8fce59 (1 revision) (flutter/flutter#164449) 2025-03-02 [email protected] Roll Fuchsia Linux SDK from ln3joxJfRN2XGhvCv... to AO1KirSDI7-MVYNPN... (flutter/flutter#164440) 2025-03-02 [email protected] android: Clean up gen_snapshot artifact build (flutter/flutter#164418) 2025-03-02 [email protected] Start using `bin/cache/engine.{stamp|realm}` instead of `bin/internal/engine.{realm|version}`. (flutter/flutter#164352) 2025-03-01 [email protected] Add macos/android_debug_unopt to local_engine.json (flutter/flutter#164410) 2025-03-01 [email protected] Delete unused build archive targets (flutter/flutter#164414) 2025-03-01 [email protected] Roll Fuchsia Linux SDK from QMun2itYrV_zUYrvW... to ln3joxJfRN2XGhvCv... (flutter/flutter#164423) 2025-03-01 [email protected] Roll Skia from ac14158663ea to ad64415050aa (1 revision) (flutter/flutter#164413) 2025-03-01 [email protected] Update linux_host_engine.json ci/host_release description (flutter/flutter#164402) 2025-03-01 [email protected] In update_engine_version_test.dart, do not populate the test environment with the host platform environment (flutter/flutter#164395) 2025-03-01 [email protected] Roll-forward #164317: Use `bin/cache/engine.stamp` (flutter/flutter#164401) 2025-02-28 [email protected] Make pressing and moving on CupertinoButton closer to native behavior. (flutter/flutter#161731) 2025-02-28 [email protected] Roll Skia from 4005ba3ca7b6 to ac14158663ea (7 revisions) (flutter/flutter#164404) 2025-02-28 [email protected] [macOS] Prepare FlutterKeyboardManager for multi-view (flutter/flutter#163962) 2025-02-28 [email protected] Add PlatformDispatcher.engineId (flutter/flutter#163476) 2025-02-28 [email protected] Move `integration_test.FlutterDeviceScreenshotTest` to the framework slow shard (flutter/flutter#164398) 2025-02-28 [email protected] Fix: Update DelegatedTransition animation parameter correctly (flutter/flutter#163853) 2025-02-28 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Write an identical value to `bin/cache/engine.stamp` to prepare for migration (#164317)" (flutter/flutter#164396) 2025-02-28 [email protected] Add action for configuring default action of EditableText.onTapUpOutside (flutter/flutter#162575) 2025-02-28 [email protected] Align jvmTarget usages across codebase, while editing build.gradle files align them with android version documentation (flutter/flutter#164200) 2025-02-28 [email protected] Roll Packages from 01d3d5c to 70b41e1 (5 revisions) (flutter/flutter#164380) 2025-02-28 [email protected] [tool] Allow using archiveName in android bundle build (flutter/flutter#162390) 2025-02-28 [email protected] Fix incorrectly checking for invalid environment variables in the tool (flutter/flutter#164101) 2025-02-28 [email protected] Support forward and back buttons (flutter/flutter#164356) 2025-02-28 [email protected] Fix window creation callback for multi-window (flutter/flutter#164353) 2025-02-28 [email protected] Fix flutter doctor usage of eglinfo in failure cases. (flutter/flutter#164334) 2025-02-28 [email protected] Refactor writing of package config in tests (flutter/flutter#163734) 2025-02-28 [email protected] Fixed the issue that Slider's secondaryTrackValue is not updated. (flutter/flutter#163996) 2025-02-28 [email protected] Roll pub packages (flutter/flutter#164357) 2025-02-28 [email protected] Remove `Mac mac_unopt` presubmit retry count (flutter/flutter#164350) 2025-02-28 [email protected] Roll Fuchsia Linux SDK from 1elkOxihZuTEiTXzY... to QMun2itYrV_zUYrvW... (flutter/flutter#164351) 2025-02-28 [email protected] Drag handles only need to be tested on mobile platforms. (flutter/flutter#163723) 2025-02-28 [email protected] [Android] Use java for looking up Android API level. (flutter/flutter#163558) 2025-02-28 [email protected] Write an identical value to `bin/cache/engine.stamp` to prepare for migration (flutter/flutter#164317) 2025-02-27 [email protected] Wires up expanded state in web engine (flutter/flutter#164048) 2025-02-27 [email protected] Remove Cheserton's File (flutter/flutter#164340) 2025-02-27 [email protected] Replace update semantics handler with signal. (flutter/flutter#163583) 2025-02-27 [email protected] Split up the conical gradient fragment shader (flutter/flutter#164058) 2025-02-27 [email protected] Roll Skia from c16b145749d4 to 4005ba3ca7b6 (3 revisions) (flutter/flutter#164339) 2025-02-27 [email protected] Delete and update stale documentation regarding engine/engine hash. (flutter/flutter#164324) 2025-02-27 [email protected] Document how `engine.version` (is/will be) computed (flutter/flutter#164335) 2025-02-27 [email protected] Update conductor to write engine.version file (flutter/flutter#163350) 2025-02-27 [email protected] remove last usages of min/compile/target SdkVersion, align sourceCompatibility across repo and update android version documentation (flutter/flutter#164198) 2025-02-27 [email protected] Update links to the `flutter/engine` repository for the monorepo. (flutter/flutter#164328) 2025-02-27 [email protected] Add empty `io.flutter.app.FlutterApplication` to give deprecation notice, and un-break projects that have not migrated (flutter/flutter#164233) 2025-02-27 [email protected] Revert dart sdks that were causing dartaotruntime issues in g3 (flutter/flutter#164307) ...
Roll Flutter from 2e570ca to 842db35 (59 revisions) flutter/flutter@2e570ca...842db35 2025-03-02 [email protected] Roll Skia from ad64415050aa to 101eee8fce59 (1 revision) (flutter/flutter#164449) 2025-03-02 [email protected] Roll Fuchsia Linux SDK from ln3joxJfRN2XGhvCv... to AO1KirSDI7-MVYNPN... (flutter/flutter#164440) 2025-03-02 [email protected] android: Clean up gen_snapshot artifact build (flutter/flutter#164418) 2025-03-02 [email protected] Start using `bin/cache/engine.{stamp|realm}` instead of `bin/internal/engine.{realm|version}`. (flutter/flutter#164352) 2025-03-01 [email protected] Add macos/android_debug_unopt to local_engine.json (flutter/flutter#164410) 2025-03-01 [email protected] Delete unused build archive targets (flutter/flutter#164414) 2025-03-01 [email protected] Roll Fuchsia Linux SDK from QMun2itYrV_zUYrvW... to ln3joxJfRN2XGhvCv... (flutter/flutter#164423) 2025-03-01 [email protected] Roll Skia from ac14158663ea to ad64415050aa (1 revision) (flutter/flutter#164413) 2025-03-01 [email protected] Update linux_host_engine.json ci/host_release description (flutter/flutter#164402) 2025-03-01 [email protected] In update_engine_version_test.dart, do not populate the test environment with the host platform environment (flutter/flutter#164395) 2025-03-01 [email protected] Roll-forward #164317: Use `bin/cache/engine.stamp` (flutter/flutter#164401) 2025-02-28 [email protected] Make pressing and moving on CupertinoButton closer to native behavior. (flutter/flutter#161731) 2025-02-28 [email protected] Roll Skia from 4005ba3ca7b6 to ac14158663ea (7 revisions) (flutter/flutter#164404) 2025-02-28 [email protected] [macOS] Prepare FlutterKeyboardManager for multi-view (flutter/flutter#163962) 2025-02-28 [email protected] Add PlatformDispatcher.engineId (flutter/flutter#163476) 2025-02-28 [email protected] Move `integration_test.FlutterDeviceScreenshotTest` to the framework slow shard (flutter/flutter#164398) 2025-02-28 [email protected] Fix: Update DelegatedTransition animation parameter correctly (flutter/flutter#163853) 2025-02-28 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Write an identical value to `bin/cache/engine.stamp` to prepare for migration (#164317)" (flutter/flutter#164396) 2025-02-28 [email protected] Add action for configuring default action of EditableText.onTapUpOutside (flutter/flutter#162575) 2025-02-28 [email protected] Align jvmTarget usages across codebase, while editing build.gradle files align them with android version documentation (flutter/flutter#164200) 2025-02-28 [email protected] Roll Packages from 01d3d5c to 70b41e1 (5 revisions) (flutter/flutter#164380) 2025-02-28 [email protected] [tool] Allow using archiveName in android bundle build (flutter/flutter#162390) 2025-02-28 [email protected] Fix incorrectly checking for invalid environment variables in the tool (flutter/flutter#164101) 2025-02-28 [email protected] Support forward and back buttons (flutter/flutter#164356) 2025-02-28 [email protected] Fix window creation callback for multi-window (flutter/flutter#164353) 2025-02-28 [email protected] Fix flutter doctor usage of eglinfo in failure cases. (flutter/flutter#164334) 2025-02-28 [email protected] Refactor writing of package config in tests (flutter/flutter#163734) 2025-02-28 [email protected] Fixed the issue that Slider's secondaryTrackValue is not updated. (flutter/flutter#163996) 2025-02-28 [email protected] Roll pub packages (flutter/flutter#164357) 2025-02-28 [email protected] Remove `Mac mac_unopt` presubmit retry count (flutter/flutter#164350) 2025-02-28 [email protected] Roll Fuchsia Linux SDK from 1elkOxihZuTEiTXzY... to QMun2itYrV_zUYrvW... (flutter/flutter#164351) 2025-02-28 [email protected] Drag handles only need to be tested on mobile platforms. (flutter/flutter#163723) 2025-02-28 [email protected] [Android] Use java for looking up Android API level. (flutter/flutter#163558) 2025-02-28 [email protected] Write an identical value to `bin/cache/engine.stamp` to prepare for migration (flutter/flutter#164317) 2025-02-27 [email protected] Wires up expanded state in web engine (flutter/flutter#164048) 2025-02-27 [email protected] Remove Cheserton's File (flutter/flutter#164340) 2025-02-27 [email protected] Replace update semantics handler with signal. (flutter/flutter#163583) 2025-02-27 [email protected] Split up the conical gradient fragment shader (flutter/flutter#164058) 2025-02-27 [email protected] Roll Skia from c16b145749d4 to 4005ba3ca7b6 (3 revisions) (flutter/flutter#164339) 2025-02-27 [email protected] Delete and update stale documentation regarding engine/engine hash. (flutter/flutter#164324) 2025-02-27 [email protected] Document how `engine.version` (is/will be) computed (flutter/flutter#164335) 2025-02-27 [email protected] Update conductor to write engine.version file (flutter/flutter#163350) 2025-02-27 [email protected] remove last usages of min/compile/target SdkVersion, align sourceCompatibility across repo and update android version documentation (flutter/flutter#164198) 2025-02-27 [email protected] Update links to the `flutter/engine` repository for the monorepo. (flutter/flutter#164328) 2025-02-27 [email protected] Add empty `io.flutter.app.FlutterApplication` to give deprecation notice, and un-break projects that have not migrated (flutter/flutter#164233) 2025-02-27 [email protected] Revert dart sdks that were causing dartaotruntime issues in g3 (flutter/flutter#164307) ...
Fixes: #91581
This PR adds an
onTapMoveevent toTapGestureRecognizer, and thenCupertinoButtonuses this event to implement the behavior of the native iOSUIButton(as shown in the issue). It is worth noting that this PR slightly changes the wayCupertinoButton'sonPressedis triggered. Specifically, it changes from being triggered byTapGestureRecognizer'sonTapto checking if the event position is still above the button inTapGestureRecognizer'sonTapUp. Additionally, it removes the previous behavior where the gesture was canceled if moved beyondkScaleSlop(18 logical pixels). Overall, previously,onPressedcould not be triggered if the button was pressed and then moved more than 18 pixels. This PR adjusts it so thatonPressedcannot be triggered if the button is pressed and then moved outside the button.Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.