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

fix(all): ripple effect is no longer added when scrolling #25352

Merged
merged 5 commits into from
Jun 3, 2022
Merged

Conversation

liamdebeasi
Copy link
Contributor

@liamdebeasi liamdebeasi commented May 25, 2022

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
    • Some docs updates need to be made in the ionic-docs repo, in a separate PR. See the contributing guide for details.
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue URL: resolves #22030

The tap click utility in Ionic ensures that the active state is added to interactives on iOS and Android. On iOS this is an active shade color. On Android this is the ripple effect.

To align with native, the active state should never be added when scrolling. For example, if you begin to scroll by tapping on a button, that button should not receive the ripple effect. See the below example on Android 12:

demo.mp4

Observe that the ripple effect does not appear on items as the user scrolls. However, when tapping/pressing an item when not scrolling shows the ripple effect.


In Ionic, this used to work by listening for the scroll event on ion-content. However, this behavior unintentionally changed in fd1b44a. The downside of this approach is that it adds quite a bit of main thread work due to the scroll listener.

How this all comes together is on touchstart, we create a setTimeout (https://github.com/ionic-team/ionic-framework/blob/main/core/src/utils/tap-click.ts#L103) which, when fired, will add the activated state. When we detect scrolling, the cancelActive function is invoked (https://github.com/ionic-team/ionic-framework/blob/main/core/src/utils/tap-click.ts#L151) which cancels the setTimeout.

What is the new behavior?

When we begin to scroll, the pointercancel event is fired which then calls cancelActive which prevents the active state from being added.

See a demo below:

main branch
md
branch.mp4
fix.mp4
ios
current-ios.mp4
fix-ios.mp4

There is another bug on Android that this change fixes. Currently, when you swipe on an interactive (but don't scroll), the ripple effect is added to the element. However, the browser never dispatches the click event, so it looks like you selected the element and nothing happened. With pointercancel, this no longer happens.

See a demo below

main branch
header-now.mp4
header-fix.mp4

Note: Safari does not dispatch pointercancel in this scenario. However, this bug existed even when we were using the old scroll events method so I am not sure it's worth fixing at the moment.

Does this introduce a breaking change?

  • Yes
  • No

Other information

@github-actions github-actions bot added the package: core @ionic/core package label May 25, 2022
@liamdebeasi liamdebeasi changed the title Testing tap click update DO NOT MERGE fix(all): ripple effect is no longer added when scrolling May 25, 2022
@liamdebeasi
Copy link
Contributor Author

liamdebeasi commented May 25, 2022

A few things:

1. Let me know if you'd prefer a meeting to review this. I scheduled an architectural alignment meeting for next week so we can discuss tapclick.
2. Any thoughts on how to automate a test for this? Since the activated state is added asynchronously, it's a bit hard to ensure that the ion-activated class is not added without it being flaky.

@liamdebeasi liamdebeasi marked this pull request as ready for review May 25, 2022 20:46
@liamdebeasi liamdebeasi requested a review from a team as a code owner May 25, 2022 20:46
Copy link
Contributor

@sean-perkins sean-perkins left a comment

Choose a reason for hiding this comment

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

🚀 thanks for the walkthrough!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: tap click activates buttons without scrollEvents, but scrollEvents introduces perf issues
3 participants