@@ -9,26 +9,27 @@ import {ElementRef, NgZone} from '@angular/core';
99import { Platform , supportsPassiveEventListeners } from '@angular/cdk/platform' ;
1010import { RippleRef , RippleState } from './ripple-ref' ;
1111
12- /** Fade-in duration for the ripples. Can be modified with the speedFactor option. */
13- export const RIPPLE_FADE_IN_DURATION = 450 ;
14-
15- /** Fade-out duration for the ripples in milliseconds. This can't be modified by the speedFactor. */
16- export const RIPPLE_FADE_OUT_DURATION = 400 ;
17-
18- /**
19- * Timeout for ignoring mouse events. Mouse events will be temporary ignored after touch
20- * events to avoid synthetic mouse events.
21- */
22- const IGNORE_MOUSE_EVENTS_TIMEOUT = 800 ;
23-
2412export type RippleConfig = {
2513 color ?: string ;
2614 centered ?: boolean ;
2715 radius ?: number ;
28- speedFactor ?: number ;
2916 persistent ?: boolean ;
17+ animation ?: RippleAnimationConfig ;
18+ /** @deprecated Use the animation property instead. */
19+ speedFactor ?: number ;
3020} ;
3121
22+ /**
23+ * Interface that describes the configuration for the animation of a ripple.
24+ * There are two animation phases with different durations for the ripples.
25+ */
26+ export interface RippleAnimationConfig {
27+ /** Duration in milliseconds for the enter animation. */
28+ enterDuration ?: number ;
29+ /** Duration in milliseconds for the exit animation. */
30+ exitDuration ?: number ;
31+ }
32+
3233/**
3334 * Interface that describes the target for launching ripples.
3435 * It defines the ripple configuration and disabled state for interaction ripples.
@@ -37,11 +38,25 @@ export type RippleConfig = {
3738export interface RippleTarget {
3839 /** Configuration for ripples that are launched on pointer down. */
3940 rippleConfig : RippleConfig ;
40-
4141 /** Whether ripples on pointer down should be disabled. */
4242 rippleDisabled : boolean ;
4343}
4444
45+ /**
46+ * Default ripple animation configuration for ripples without an explicit
47+ * animation config specified.
48+ */
49+ export const defaultRippleAnimationConfig = {
50+ enterDuration : 450 ,
51+ exitDuration : 400
52+ } ;
53+
54+ /**
55+ * Timeout for ignoring mouse events. Mouse events will be temporary ignored after touch
56+ * events to avoid synthetic mouse events.
57+ */
58+ const ignoreMouseEventsTimeout = 800 ;
59+
4560/**
4661 * Helper service that performs DOM manipulations. Not intended to be used outside this module.
4762 * The constructor takes a reference to the ripple directive's host element and a map of DOM
@@ -99,16 +114,17 @@ export class RippleRenderer {
99114 */
100115 fadeInRipple ( x : number , y : number , config : RippleConfig = { } ) : RippleRef {
101116 const containerRect = this . _containerElement . getBoundingClientRect ( ) ;
117+ const animationConfig = { ...defaultRippleAnimationConfig , ...config . animation } ;
102118
103119 if ( config . centered ) {
104120 x = containerRect . left + containerRect . width / 2 ;
105121 y = containerRect . top + containerRect . height / 2 ;
106122 }
107123
108124 const radius = config . radius || distanceToFurthestCorner ( x , y , containerRect ) ;
109- const duration = RIPPLE_FADE_IN_DURATION / ( config . speedFactor || 1 ) ;
110125 const offsetX = x - containerRect . left ;
111126 const offsetY = y - containerRect . top ;
127+ const duration = animationConfig . enterDuration / ( config . speedFactor || 1 ) ;
112128
113129 const ripple = document . createElement ( 'div' ) ;
114130 ripple . classList . add ( 'mat-ripple-element' ) ;
@@ -159,8 +175,9 @@ export class RippleRenderer {
159175 }
160176
161177 const rippleEl = rippleRef . element ;
178+ const animationConfig = { ...defaultRippleAnimationConfig , ...rippleRef . config . animation } ;
162179
163- rippleEl . style . transitionDuration = `${ RIPPLE_FADE_OUT_DURATION } ms` ;
180+ rippleEl . style . transitionDuration = `${ animationConfig . exitDuration } ms` ;
164181 rippleEl . style . opacity = '0' ;
165182
166183 rippleRef . state = RippleState . FADING_OUT ;
@@ -169,7 +186,7 @@ export class RippleRenderer {
169186 this . runTimeoutOutsideZone ( ( ) => {
170187 rippleRef . state = RippleState . HIDDEN ;
171188 rippleEl . parentNode ! . removeChild ( rippleEl ) ;
172- } , RIPPLE_FADE_OUT_DURATION ) ;
189+ } , animationConfig . exitDuration ) ;
173190 }
174191
175192 /** Fades out all currently active ripples. */
@@ -197,7 +214,7 @@ export class RippleRenderer {
197214 /** Function being called whenever the trigger is being pressed using mouse. */
198215 private onMousedown = ( event : MouseEvent ) => {
199216 const isSyntheticEvent = this . _lastTouchStartEvent &&
200- Date . now ( ) < this . _lastTouchStartEvent + IGNORE_MOUSE_EVENTS_TIMEOUT ;
217+ Date . now ( ) < this . _lastTouchStartEvent + ignoreMouseEventsTimeout ;
201218
202219 if ( ! this . _target . rippleDisabled && ! isSyntheticEvent ) {
203220 this . _isPointerDown = true ;
0 commit comments