Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit c6076e1

Browse files
authoredApr 16, 2018
feat(ripple): Call layout on each activation (#2567)
1 parent 1331fd7 commit c6076e1

File tree

3 files changed

+34
-35
lines changed

3 files changed

+34
-35
lines changed
 

‎packages/mdc-ripple/foundation.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ class MDCRippleFoundation extends MDCFoundation {
209209
this.adapter_.addClass(ROOT);
210210
if (this.adapter_.isUnbounded()) {
211211
this.adapter_.addClass(UNBOUNDED);
212+
// Unbounded ripples need layout logic applied immediately to set coordinates for both shade and ripple
213+
this.layoutInternal_();
212214
}
213-
this.layoutInternal_();
214215
});
215216
}
216217

@@ -244,7 +245,10 @@ class MDCRippleFoundation extends MDCFoundation {
244245
});
245246
this.adapter_.registerInteractionHandler('focus', this.focusHandler_);
246247
this.adapter_.registerInteractionHandler('blur', this.blurHandler_);
247-
this.adapter_.registerResizeHandler(this.resizeHandler_);
248+
249+
if (this.adapter_.isUnbounded()) {
250+
this.adapter_.registerResizeHandler(this.resizeHandler_);
251+
}
248252
}
249253

250254
/**
@@ -268,7 +272,10 @@ class MDCRippleFoundation extends MDCFoundation {
268272
});
269273
this.adapter_.deregisterInteractionHandler('focus', this.focusHandler_);
270274
this.adapter_.deregisterInteractionHandler('blur', this.blurHandler_);
271-
this.adapter_.deregisterResizeHandler(this.resizeHandler_);
275+
276+
if (this.adapter_.isUnbounded()) {
277+
this.adapter_.deregisterResizeHandler(this.resizeHandler_);
278+
}
272279
}
273280

274281
/** @private */
@@ -380,6 +387,8 @@ class MDCRippleFoundation extends MDCFoundation {
380387
const {FG_DEACTIVATION, FG_ACTIVATION} = MDCRippleFoundation.cssClasses;
381388
const {DEACTIVATION_TIMEOUT_MS} = MDCRippleFoundation.numbers;
382389

390+
this.layoutInternal_();
391+
383392
let translateStart = '';
384393
let translateEnd = '';
385394

‎test/unit/mdc-ripple/foundation-general-events.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {cssClasses, strings} from '../../../packages/mdc-ripple/constants';
2323

2424
suite('MDCRippleFoundation - General Events');
2525

26-
testFoundation('re-lays out the component on resize event', ({foundation, adapter, mockRaf}) => {
26+
testFoundation('re-lays out the component on resize event for unbounded ripple', ({foundation, adapter, mockRaf}) => {
27+
td.when(adapter.isUnbounded()).thenReturn(true);
2728
td.when(adapter.computeBoundingRect()).thenReturn({
2829
width: 100,
2930
height: 200,
@@ -54,6 +55,7 @@ testFoundation('re-lays out the component on resize event', ({foundation, adapte
5455
});
5556

5657
testFoundation('debounces layout within the same frame on resize', ({foundation, adapter, mockRaf}) => {
58+
td.when(adapter.isUnbounded()).thenReturn(true);
5759
td.when(adapter.computeBoundingRect()).thenReturn({
5860
width: 100,
5961
height: 200,

‎test/unit/mdc-ripple/foundation.test.js

+19-31
Original file line numberDiff line numberDiff line change
@@ -78,47 +78,26 @@ testFoundation('#init gracefully exits when css variables are not supported', fa
7878
td.verify(adapter.addClass(cssClasses.ROOT), {times: 0});
7979
});
8080

81-
testFoundation(`#init sets ${strings.VAR_FG_SIZE} to the circumscribing circle's diameter`,
82-
({foundation, adapter, mockRaf}) => {
83-
const size = 200;
84-
td.when(adapter.computeBoundingRect()).thenReturn({width: size, height: size / 2});
85-
foundation.init();
86-
mockRaf.flush();
87-
const initialSize = size * numbers.INITIAL_ORIGIN_SCALE;
88-
89-
td.verify(adapter.updateCssVariable(strings.VAR_FG_SIZE, `${initialSize}px`));
90-
});
91-
92-
testFoundation(`#init centers via ${strings.VAR_LEFT} and ${strings.VAR_TOP} when unbounded`,
93-
({foundation, adapter, mockRaf}) => {
94-
const width = 200;
95-
const height = 100;
96-
const maxSize = Math.max(width, height);
97-
const initialSize = maxSize * numbers.INITIAL_ORIGIN_SCALE;
98-
99-
td.when(adapter.computeBoundingRect()).thenReturn({width, height});
100-
td.when(adapter.isUnbounded()).thenReturn(true);
101-
foundation.init();
102-
mockRaf.flush();
103-
104-
td.verify(adapter.updateCssVariable(strings.VAR_LEFT,
105-
`${Math.round((width / 2) - (initialSize / 2))}px`));
106-
td.verify(adapter.updateCssVariable(strings.VAR_TOP,
107-
`${Math.round((height / 2) - (initialSize / 2))}px`));
108-
});
109-
11081
testFoundation('#init registers events for interactions on root element', ({foundation, adapter}) => {
11182
foundation.init();
11283

11384
td.verify(adapter.registerInteractionHandler(td.matchers.isA(String), td.matchers.isA(Function)));
11485
});
11586

116-
testFoundation('#init registers an event for when a resize occurs', ({foundation, adapter}) => {
87+
testFoundation('#init registers a resize handler for unbounded ripple', ({foundation, adapter}) => {
88+
td.when(adapter.isUnbounded()).thenReturn(true);
11789
foundation.init();
11890

11991
td.verify(adapter.registerResizeHandler(td.matchers.isA(Function)));
12092
});
12193

94+
testFoundation('#init does not register a resize handler for bounded ripple', ({foundation, adapter}) => {
95+
td.when(adapter.isUnbounded()).thenReturn(false);
96+
foundation.init();
97+
98+
td.verify(adapter.registerResizeHandler(td.matchers.isA(Function)), {times: 0});
99+
});
100+
122101
testFoundation('#init does not register events if CSS custom properties not supported', ({foundation, adapter}) => {
123102
td.when(adapter.browserSupportsCssVars()).thenReturn(false);
124103
foundation.init();
@@ -144,8 +123,9 @@ testFoundation('#destroy unregisters all bound interaction handlers', ({foundati
144123
td.verify(adapter.deregisterDocumentInteractionHandler(td.matchers.isA(String), td.matchers.isA(Function)));
145124
});
146125

147-
testFoundation('#destroy unregisters the resize handler', ({foundation, adapter}) => {
126+
testFoundation('#destroy unregisters the resize handler for unbounded ripple', ({foundation, adapter}) => {
148127
let resizeHandler;
128+
td.when(adapter.isUnbounded()).thenReturn(true);
149129
td.when(adapter.registerResizeHandler(td.matchers.isA(Function))).thenDo((handler) => {
150130
resizeHandler = handler;
151131
});
@@ -155,6 +135,14 @@ testFoundation('#destroy unregisters the resize handler', ({foundation, adapter}
155135
td.verify(adapter.deregisterResizeHandler(resizeHandler));
156136
});
157137

138+
testFoundation('#destroy does not unregister resize handler for bounded ripple', ({foundation, adapter}) => {
139+
td.when(adapter.isUnbounded()).thenReturn(false);
140+
foundation.init();
141+
foundation.destroy();
142+
143+
td.verify(adapter.deregisterResizeHandler(td.matchers.isA(Function)), {times: 0});
144+
});
145+
158146
testFoundation(`#destroy removes ${cssClasses.ROOT}`, ({foundation, adapter, mockRaf}) => {
159147
foundation.destroy();
160148
mockRaf.flush();

0 commit comments

Comments
 (0)