@@ -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 ) {
@@ -173,8 +179,15 @@ export class RippleRenderer {
173
179
174
180
/** Fades out a ripple reference. */
175
181
fadeOutRipple ( rippleRef : RippleRef ) {
182
+ const wasActive = this . _activeRipples . delete ( rippleRef ) ;
183
+
184
+ // Clear out the cached bounding rect if we have no more ripples.
185
+ if ( ! this . _activeRipples . size ) {
186
+ this . _containerRect = null ;
187
+ }
188
+
176
189
// For ripples that are not active anymore, don't re-un the fade-out animation.
177
- if ( ! this . _activeRipples . delete ( rippleRef ) ) {
190
+ if ( ! wasActive ) {
178
191
return ;
179
192
}
180
193
@@ -183,7 +196,6 @@ export class RippleRenderer {
183
196
184
197
rippleEl . style . transitionDuration = `${ animationConfig . exitDuration } ms` ;
185
198
rippleEl . style . opacity = '0' ;
186
-
187
199
rippleRef . state = RippleState . FADING_OUT ;
188
200
189
201
// Once the ripple faded out, the ripple can be safely removed from the DOM.
0 commit comments