Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ripple): Always remove ripple after a certain period #1915

Merged
merged 5 commits into from
Dec 7, 2016

Conversation

tinayuangao
Copy link
Contributor

The ripple foreground is not removed if transition is interrupt (e.g. change parent visibility, hidden).

Fixes #1818

R: @kara @jelbourn

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Nov 17, 2016
@tinayuangao tinayuangao added pr: needs review and removed cla: yes PR author has agreed to Google's Contributor License Agreement labels Nov 17, 2016
@@ -143,6 +143,8 @@ export class RippleRenderer {

rippleDiv.addEventListener('transitionend',
(event: TransitionEvent) => transitionEndCallback(ripple, event));
// Remove the ripple after transitions (fade-in, transform, fade-out)
setTimeout(() => this.removeRippleFromDom(ripple.rippleElement), fadeInSeconds * 3 * 1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will require all related tests to be async, right? @jelbourn Should we run this outside angular zone?

@@ -143,6 +143,8 @@ export class RippleRenderer {

rippleDiv.addEventListener('transitionend',
(event: TransitionEvent) => transitionEndCallback(ripple, event));
// Remove the ripple after transitions (fade-in, transform, fade-out)
setTimeout(() => this.removeRippleFromDom(ripple.rippleElement), fadeInSeconds * 3 * 1000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it solve the problem to remove the ripple element in ngOnDestroy instead of using a timeout?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes the element is only hidden, or display: none. In this case ngOnDestroy is never called.

If we use *ngIf to remove the element, the ripple will be removed when it's removed from the DOM tree.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Nov 17, 2016
@@ -143,6 +143,8 @@ export class RippleRenderer {

rippleDiv.addEventListener('transitionend',
(event: TransitionEvent) => transitionEndCallback(ripple, event));
// Remove the ripple after transitions (fade-in, transform, fade-out)
setTimeout(() => this.removeRippleFromDom(ripple.rippleElement), fadeInSeconds * 3 * 1000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Ensure that ripples are always removed, even when transitionend doesn't fire.
// Run this outside the Angular zone because there's nothing that Angular cares about.
// If it were to run inside the Angular zone, every test that used ripples would have to be
// either async or fakeAsync.
this._ngZone.runOutsideAngular(() => {
  // The ripple lasts a time equal to the sum of fade-in, transform, and fade-out (3 * fade-in time).
  let rippleDuration =  fadeInSeconds * 3 * 1000;
  setTimeout(() => this.removeRippleFromDom(ripple.rippleElement), rippleDuration);
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. PTAL.
Thanks for review!

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM aside from one last comment. You can add the merge_ready label when it's ready.

rippleElement.click();
expect(rippleElement.querySelectorAll('.md-ripple-foreground').length).toBe(1);

setTimeout(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment like

// Use a real timeout because the ripple's timeout runs outside of the angular zone.

@jelbourn
Copy link
Member

jelbourn commented Dec 6, 2016

Still seems to be failing on IE11... I'll try to take a look today.

@tinayuangao
Copy link
Contributor Author

Fixed IE11

@tinayuangao tinayuangao added the action: merge The PR is ready for merge by the caretaker label Dec 7, 2016
@mmalerba mmalerba merged commit 62cc830 into angular:master Dec 7, 2016
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ripple is never removed if its transition is interrupted
5 participants