@@ -69,7 +69,6 @@ const ignoreMouseEventsTimeout = 800;
69
69
* @docs -private
70
70
*/
71
71
export class RippleRenderer {
72
-
73
72
/** Element where the ripples are being added to. */
74
73
private _containerElement : HTMLElement ;
75
74
@@ -91,6 +90,12 @@ export class RippleRenderer {
91
90
/** Options that apply to all the event listeners that are bound by the renderer. */
92
91
private _eventOptions = supportsPassiveEventListeners ( ) ? ( { passive : true } as any ) : false ;
93
92
93
+ /**
94
+ * Cached dimensions of the ripple container. Set when the first
95
+ * ripple is shown and cleared once no more ripples are visible.
96
+ */
97
+ private _containerRect : ClientRect | null ;
98
+
94
99
constructor ( private _target : RippleTarget ,
95
100
private _ngZone : NgZone ,
96
101
elementRef : ElementRef ,
@@ -117,7 +122,8 @@ export class RippleRenderer {
117
122
* @param config Extra ripple options.
118
123
*/
119
124
fadeInRipple ( x : number , y : number , config : RippleConfig = { } ) : RippleRef {
120
- const containerRect = this . _containerElement . getBoundingClientRect ( ) ;
125
+ const containerRect = this . _containerRect =
126
+ this . _containerRect || this . _containerElement . getBoundingClientRect ( ) ;
121
127
const animationConfig = { ...defaultRippleAnimationConfig , ...config . animation } ;
122
128
123
129
if ( config . centered ) {
@@ -174,7 +180,7 @@ export class RippleRenderer {
174
180
/** Fades out a ripple reference. */
175
181
fadeOutRipple ( rippleRef : RippleRef ) {
176
182
// For ripples that are not active anymore, don't re-un the fade-out animation.
177
- if ( ! this . _activeRipples . delete ( rippleRef ) ) {
183
+ if ( ! this . _activeRipples . has ( rippleRef ) ) {
178
184
return ;
179
185
}
180
186
@@ -183,13 +189,18 @@ export class RippleRenderer {
183
189
184
190
rippleEl . style . transitionDuration = `${ animationConfig . exitDuration } ms` ;
185
191
rippleEl . style . opacity = '0' ;
186
-
187
192
rippleRef . state = RippleState . FADING_OUT ;
188
193
189
194
// Once the ripple faded out, the ripple can be safely removed from the DOM.
190
195
this . runTimeoutOutsideZone ( ( ) => {
191
196
rippleRef . state = RippleState . HIDDEN ;
192
197
rippleEl . parentNode ! . removeChild ( rippleEl ) ;
198
+ this . _activeRipples . delete ( rippleRef ) ;
199
+
200
+ // Clear out the cached bounding rect if we have no more ripples.
201
+ if ( ! this . _activeRipples . size ) {
202
+ this . _containerRect = null ;
203
+ }
193
204
} , animationConfig . exitDuration ) ;
194
205
}
195
206
0 commit comments