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
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion core/src/components/content/content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@

overflow: hidden;

touch-action: manipulation;
/**
* touch-action: manipulation is an alias
* for this, but WebKit has an issue
* where pointercancel events are not fired
* when scrolling: https://bugs.webkit.org/show_bug.cgi?id=240917
* Using the long form below avoids the issue.
*/
touch-action: pan-x pan-y pinch-zoom;
}

.scroll-y,
Expand Down
30 changes: 15 additions & 15 deletions core/src/utils/tap-click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { now, pointerCoord } from './helpers';
export const startTapClick = (config: Config) => {
let lastTouch = -MOUSE_WAIT * 10;
let lastActivated = 0;
let scrollingEl: HTMLElement | undefined;

let activatableEle: HTMLElement | undefined;
let activeRipple: Promise<() => void> | undefined;
Expand All @@ -14,11 +13,6 @@ export const startTapClick = (config: Config) => {
const useRippleEffect = config.getBoolean('animated', true) && config.getBoolean('rippleEffect', true);
const clearDefers = new WeakMap<HTMLElement, any>();

const isScrolling = () => {
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
return scrollingEl !== undefined && scrollingEl.parentElement !== null;
};

// Touch Events
const onTouchStart = (ev: TouchEvent) => {
lastTouch = now(ev);
Expand Down Expand Up @@ -58,10 +52,9 @@ export const startTapClick = (config: Config) => {
};

const pointerDown = (ev: UIEvent) => {
if (activatableEle || isScrolling()) {
if (activatableEle) {
return;
}
scrollingEl = undefined;
setActivatedElement(getActivatableTarget(ev), ev);
};

Expand Down Expand Up @@ -146,19 +139,26 @@ export const startTapClick = (config: Config) => {
};

const doc = document;
doc.addEventListener('ionScrollStart', (ev) => {
scrollingEl = ev.target as HTMLElement;
cancelActive();
});
doc.addEventListener('ionScrollEnd', () => {
scrollingEl = undefined;
});
doc.addEventListener('ionGestureCaptured', cancelActive);

doc.addEventListener('touchstart', onTouchStart, true);
doc.addEventListener('touchcancel', onTouchEnd, true);
doc.addEventListener('touchend', onTouchEnd, true);

/**
* Tap click effects such as the ripple effect should
* not happen when scrolling. For example, if a user scrolls
* the page but also happens to do a touchstart on a button
* as part of the scroll, the ripple effect should not
* be dispatched. The ripple effect should only happen
* if the button is activated and the page is not scrolling.
*
* pointercancel is dispatched on a gesture when scrolling
* starts, so this lets us avoid having to listen for
* ion-content's scroll events.
*/
doc.addEventListener('pointercancel', cancelActive, true);

doc.addEventListener('mousedown', onMouseDown, true);
doc.addEventListener('mouseup', onMouseUp, true);

Expand Down