@@ -9,26 +9,27 @@ import {ElementRef, NgZone} from '@angular/core';
9
9
import { Platform , supportsPassiveEventListeners } from '@angular/cdk/platform' ;
10
10
import { RippleRef , RippleState } from './ripple-ref' ;
11
11
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
-
24
12
export type RippleConfig = {
25
13
color ?: string ;
26
14
centered ?: boolean ;
27
15
radius ?: number ;
28
- speedFactor ?: number ;
29
16
persistent ?: boolean ;
17
+ animation ?: RippleAnimationConfig ;
18
+ /** @deprecated Use the animation property instead. */
19
+ speedFactor ?: number ;
30
20
} ;
31
21
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 (expansion from point of contact). */
28
+ enterDuration ?: number ;
29
+ /** Duration in milliseconds for the exit animation (fade-out). */
30
+ exitDuration ?: number ;
31
+ }
32
+
32
33
/**
33
34
* Interface that describes the target for launching ripples.
34
35
* It defines the ripple configuration and disabled state for interaction ripples.
@@ -37,11 +38,25 @@ export type RippleConfig = {
37
38
export interface RippleTarget {
38
39
/** Configuration for ripples that are launched on pointer down. */
39
40
rippleConfig : RippleConfig ;
40
-
41
41
/** Whether ripples on pointer down should be disabled. */
42
42
rippleDisabled : boolean ;
43
43
}
44
44
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
+
45
60
/**
46
61
* Helper service that performs DOM manipulations. Not intended to be used outside this module.
47
62
* The constructor takes a reference to the ripple directive's host element and a map of DOM
@@ -99,16 +114,17 @@ export class RippleRenderer {
99
114
*/
100
115
fadeInRipple ( x : number , y : number , config : RippleConfig = { } ) : RippleRef {
101
116
const containerRect = this . _containerElement . getBoundingClientRect ( ) ;
117
+ const animationConfig = { ...defaultRippleAnimationConfig , ...config . animation } ;
102
118
103
119
if ( config . centered ) {
104
120
x = containerRect . left + containerRect . width / 2 ;
105
121
y = containerRect . top + containerRect . height / 2 ;
106
122
}
107
123
108
124
const radius = config . radius || distanceToFurthestCorner ( x , y , containerRect ) ;
109
- const duration = RIPPLE_FADE_IN_DURATION / ( config . speedFactor || 1 ) ;
110
125
const offsetX = x - containerRect . left ;
111
126
const offsetY = y - containerRect . top ;
127
+ const duration = animationConfig . enterDuration / ( config . speedFactor || 1 ) ;
112
128
113
129
const ripple = document . createElement ( 'div' ) ;
114
130
ripple . classList . add ( 'mat-ripple-element' ) ;
@@ -159,8 +175,9 @@ export class RippleRenderer {
159
175
}
160
176
161
177
const rippleEl = rippleRef . element ;
178
+ const animationConfig = { ...defaultRippleAnimationConfig , ...rippleRef . config . animation } ;
162
179
163
- rippleEl . style . transitionDuration = `${ RIPPLE_FADE_OUT_DURATION } ms` ;
180
+ rippleEl . style . transitionDuration = `${ animationConfig . exitDuration } ms` ;
164
181
rippleEl . style . opacity = '0' ;
165
182
166
183
rippleRef . state = RippleState . FADING_OUT ;
@@ -169,7 +186,7 @@ export class RippleRenderer {
169
186
this . runTimeoutOutsideZone ( ( ) => {
170
187
rippleRef . state = RippleState . HIDDEN ;
171
188
rippleEl . parentNode ! . removeChild ( rippleEl ) ;
172
- } , RIPPLE_FADE_OUT_DURATION ) ;
189
+ } , animationConfig . exitDuration ) ;
173
190
}
174
191
175
192
/** Fades out all currently active ripples. */
@@ -197,7 +214,7 @@ export class RippleRenderer {
197
214
/** Function being called whenever the trigger is being pressed using mouse. */
198
215
private onMousedown = ( event : MouseEvent ) => {
199
216
const isSyntheticEvent = this . _lastTouchStartEvent &&
200
- Date . now ( ) < this . _lastTouchStartEvent + IGNORE_MOUSE_EVENTS_TIMEOUT ;
217
+ Date . now ( ) < this . _lastTouchStartEvent + ignoreMouseEventsTimeout ;
201
218
202
219
if ( ! this . _target . rippleDisabled && ! isSyntheticEvent ) {
203
220
this . _isPointerDown = true ;
0 commit comments