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

Exposes onSecondaryTap in InkWell. #119058

Merged
merged 1 commit into from
Mar 16, 2023
Merged

Conversation

chinmoy12c
Copy link
Member

This PR adds onSecondaryTap to InkWell.

Fixes: #118622

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Jan 24, 2023
Copy link
Contributor

@Renzo-Olivares Renzo-Olivares left a comment

Choose a reason for hiding this comment

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

Hello @chinmoy12c thank you for your contribution. This is a much needed PR and I'm happy to give some feedback.

  1. The ink splash on secondary tap is not currently enabled. This is because the ink splash is created in handleTapDown but that is only called when a PointerDownEvent comes from a kPrimaryButton. We can take a look at handleTapDown for guidance on that and probably abstract some of the code there into something like this. For this to work we would also have to handle onSecondaryTapDown.
  void handleAnyDown(TapDownDetails details) {
    if (_anyChildInkResponsePressed) {
      return;
    }
    _startNewSplash(details: details);
  }
  1. We should also call updateHighlight(_HighlightType.pressed, value: false); in handleSecondaryTap to cancel the ink splash when the click/tap is released.

  2. I wonder if we should also provide onSecondaryTapUp (called at the same time as onSecondaryTap but provides a TapUpDetails) in this PR as well as on onSecondaryTapCancel to be consistent with the primary button gestures callbacks that InkWell provides.

@@ -1239,6 +1252,7 @@ class _InkResponseState extends State<_InkResponseStateWidget>
onTapCancel: enabled ? handleTapCancel : null,
Copy link
Contributor

Choose a reason for hiding this comment

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

If we look at this enabled property it looks like it includes all of the gesture callbacks. I think we should also add onSecondaryTap into this to correctly handle those cases.

  bool isWidgetEnabled(_InkResponseStateWidget widget) {
    return widget.onTap != null || widget.onDoubleTap != null || widget.onLongPress != null || widget.onTapDown != null;
  }

Copy link
Contributor

@Renzo-Olivares Renzo-Olivares Jan 25, 2023

Choose a reason for hiding this comment

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

Added callbacks like onSecondaryTap, onSecondaryTapUp, and onSecondaryTapDown should also go here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I noticed that onTapUp was not included in this, so I added that too.

@Renzo-Olivares
Copy link
Contributor

Renzo-Olivares commented Jan 27, 2023

Google Test failures look unrelated.

Copy link
Contributor

@Renzo-Olivares Renzo-Olivares left a comment

Choose a reason for hiding this comment

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

@chinmoy12c chinmoy12c force-pushed the issue_118622 branch 2 times, most recently from b3300ee to 4cca6b7 Compare January 28, 2023 08:36
@@ -1110,6 +1149,13 @@ class _InkResponseState extends State<_InkResponseStateWidget>
}
}

void handleSecondaryTap() {
Copy link
Contributor

@Renzo-Olivares Renzo-Olivares Jan 30, 2023

Choose a reason for hiding this comment

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

I think we should also handle and expose secondary tap cancel in a similar way to other callbacks and handleTapCancel since it is possible a tap is cancelled and we want the splash to also cancel in that case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey, @Renzo-Olivares I've updated the PR, sorry for the delay missed the notifications.

Copy link
Contributor

Choose a reason for hiding this comment

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

No worries! Sorry for the delay, i've been out of office for the past week as well.

@Renzo-Olivares
Copy link
Contributor

Hi @chinmoy12c, where you still working on this / did you have any questions about any reviews?

Copy link
Contributor

@Renzo-Olivares Renzo-Olivares left a comment

Choose a reason for hiding this comment

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

LGTM other than my final comments. Thank you for your patience and for this awesome contribution!

@@ -1110,6 +1149,13 @@ class _InkResponseState extends State<_InkResponseStateWidget>
}
}

void handleSecondaryTap() {
Copy link
Contributor

Choose a reason for hiding this comment

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

No worries! Sorry for the delay, i've been out of office for the past week as well.

@Renzo-Olivares
Copy link
Contributor

@chinmoy12c Looks like some tests are failing, but they seem unrelated. Maybe a sync up to master will fix them.

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

lgtm-very

Thank you!

Copy link
Contributor

@justinmc justinmc 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 nits. Thank you for the PR!

packages/flutter/lib/src/material/ink_well.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/material/ink_well.dart Outdated Show resolved Hide resolved
packages/flutter/test/material/ink_well_test.dart Outdated Show resolved Hide resolved
@Renzo-Olivares Renzo-Olivares added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 16, 2023
@auto-submit auto-submit bot merged commit e1eb1b9 into flutter:master Mar 16, 2023
@justinmc
Copy link
Contributor

This has the potential to be a breaking change because InkWell will now steal secondary tap gestures from overlapping widgets. For example, I noticed this exact problem in data-table-2: maxim-saplin/data_table_2#176

The way to fix it is to simply migrate to the new secondary tap API on InkWell rather than using an overlapping widget to receive secondary taps.

@maxim-saplin
Copy link

maxim-saplin commented Mar 18, 2023

It's worth to have the new events added to TableRowInkWell as well.

@Sesa1988
Copy link

Sesa1988 commented Jul 30, 2023

return InkWell(
      onSecondaryTap: isFollowedTo == true ? () => _openMenu(context) : null,
      child: ListTile(
        onTap: isFollowedTo == true ? () => _openMenu(context) : null,
        onLongPress: isFollowedTo == true ? () => _openMenu(context) : null,

onSecondaryTap still not working for me with trackpad two fingers click on macOS, the ripple effect is loading but then nothing is triggered, a long press is working.

[✓] Flutter (Channel stable, 3.10.6, on macOS 13.0 22A380 darwin-x64, locale en-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.80.2)
[✓] Connected device (2 available)
[✓] Network resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App 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.

Expose onSecondaryTap in InkWell
6 participants