Skip to content

Commit 838f40d

Browse files
authored
feat(ripple-effect): add option to disable ripple-effect (#16393)
fixes #16379
1 parent f831186 commit 838f40d

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

core/src/components/app/app.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class App implements ComponentInterface {
2121
const { win, config, queue } = this;
2222

2323
if (!config.getBoolean('_testing')) {
24-
importTapClick(win);
24+
importTapClick(win, config);
2525
}
2626

2727
importInputShims(win, config);
@@ -54,8 +54,8 @@ function importStatusTap(win: Window, config: Config, queue: QueueApi) {
5454
}
5555
}
5656

57-
function importTapClick(win: Window) {
58-
import('../../utils/tap-click').then(module => module.startTapClick(win.document));
57+
function importTapClick(win: Window, config: Config) {
58+
import('../../utils/tap-click').then(module => module.startTapClick(win.document, config));
5959
}
6060

6161
function importInputShims(win: Window, config: Config) {

core/src/components/ripple-effect/ripple-effect.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Component, ComponentInterface, Element, Method, Prop, QueueApi } from '@stencil/core';
22

3-
import { Config } from '../../interface';
4-
53
@Component({
64
tag: 'ion-ripple-effect',
75
styleUrl: 'ripple-effect.scss',
@@ -13,20 +11,12 @@ export class RippleEffect implements ComponentInterface {
1311

1412
@Prop({ context: 'queue' }) queue!: QueueApi;
1513
@Prop({ context: 'window' }) win!: Window;
16-
@Prop({ context: 'config' }) config!: Config;
1714

1815
/**
1916
* Adds the ripple effect to the parent element
2017
*/
2118
@Method()
2219
async addRipple(pageX: number, pageY: number) {
23-
if (this.config.getBoolean('animated', true)) {
24-
return this.prepareRipple(pageX, pageY);
25-
}
26-
return () => { return; };
27-
}
28-
29-
private prepareRipple(pageX: number, pageY: number) {
3020
return new Promise<() => void>(resolve => {
3121
this.queue.read(() => {
3222
const rect = this.el.getBoundingClientRect();

core/src/utils/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ export interface IonicConfig {
77
*/
88
animated?: boolean;
99

10+
/**
11+
* When it's set to `false`, it disables all material-design ripple-effects across the app.
12+
* Defaults to `true`.
13+
*/
14+
rippleEffect?: boolean;
15+
1016
/**
1117
* The mode determines which platform styles to use for the whole application.
1218
*/

core/src/utils/tap-click.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { Config } from '../interface';
12

23
import { now, pointerCoord } from './helpers';
34

4-
export function startTapClick(doc: Document) {
5+
export function startTapClick(doc: Document, config: Config) {
56
let lastTouch = -MOUSE_WAIT * 10;
67
let lastActivated = 0;
78
let cancelled = false;
@@ -11,6 +12,7 @@ export function startTapClick(doc: Document) {
1112
let activeRipple: Promise<() => void> | undefined;
1213
let activeDefer: any;
1314

15+
const useRippleEffect = config.getBoolean('animated', true) && config.getBoolean('rippleEffect', true);
1416
const clearDefers = new WeakMap<HTMLElement, any>();
1517

1618
function onBodyClick(ev: Event) {
@@ -116,7 +118,7 @@ export function startTapClick(doc: Document) {
116118
lastActivated = Date.now();
117119
el.classList.add(ACTIVATED);
118120

119-
const rippleEffect = getRippleEffect(el);
121+
const rippleEffect = useRippleEffect && getRippleEffect(el);
120122
if (rippleEffect && rippleEffect.addRipple) {
121123
activeRipple = rippleEffect.addRipple(x, y);
122124
}

0 commit comments

Comments
 (0)