-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
feat(progress-spinner): switch to css-based animation #6551
Conversation
283306a
to
c5a54d0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, one minor comment
// stylelint-enable | ||
} | ||
|
||
@keyframes mat-progress-spinner-stroke-rotate-fallback { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment describing this animation?
// For IE11 and Edge, we fall back to simply rotating the spinner because
// animating stroke-dashoffset is not supported. The fallback uses multiple
// iterations to vary where the spin "lands".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. FWIW, animating stroke-dashoffset
is supported in Edge, but rotation the circle with a CSS transform
isn't.
c5a54d0
to
b759be0
Compare
b759be0
to
a673da2
Compare
@jelbourn The reason I removed the |
1d9e9d8
to
f7f4b07
Compare
return this.mode == 'determinate' ? 0 : null; | ||
} | ||
/** Tracks diameters of existing instances to de-dupe generated styles. */ | ||
static diameters = new Set<number>([100]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment about 100
being the default diameter?
if (this._interdeterminateInterval) { | ||
clearInterval(this._interdeterminateInterval); | ||
set diameter(size: number) { | ||
this._setDiameterClass(size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Break the content of this setter into its own function?
} | ||
|
||
return null; | ||
} | ||
|
||
private _setDiameterClass(size: number): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JsDoc descriptions for these functions?
} | ||
} | ||
|
||
_getStrokeDashOffset() { | ||
get _circleRadius() { | ||
return this._diameter / 2 - 5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the 5
come from? I assume it's half the stroke width?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that's what it's supposed to be, yes; fixing.
$end: (1 - 0.8) * $_mat-progress-spinner-default-circumference; // end the animation at 80% | ||
$fallback-iterations: 4; | ||
|
||
@keyframes mat-progress-spinner-stroke-rotate-100 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we keep this one around, considering that the keyframes are being generated at runtime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We won't generate a style tag at runtime for the default diameter - only for custom diameters (the set starts with 100 included).
// Boilerplate for applying mixins to MdProgressSpinner. | ||
/** @docs-private */ | ||
export class MdProgressSpinnerBase { | ||
constructor(public _renderer: Renderer2, public _elementRef: ElementRef) {} | ||
} | ||
export const _MdProgressSpinnerMixinBase = mixinColor(MdProgressSpinnerBase, 'primary'); | ||
|
||
/* tslint:disable:max-line-length */ | ||
const INDETERMINATE_ANIMATION_TEMPLATE = ` | ||
.mat-progress-spinner-DIAMETER.mat-progress-spinner-indeterminate-animation[mode="indeterminate"] circle { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than constructing this selector, it might be better to just assign the animation-name: mat-progress-spinner-stroke-rotate-DIAMETER
as an inline style. That way people can still override the timing and duration through CSS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh hey, that's a great idea. Should simplify this a lot.
set diameter(size: number) { | ||
this._setDiameterClass(size); | ||
this._diameter = size; | ||
if (!MdProgressSpinner.diameters.has(this.diameter)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we don't support the spec animation on IE and Edge, we shouldn't append the keyframes either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call
9b453c3
to
71c5cb6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, one nit. I'm not allowed to approve my own PR.
[style.animation-name]="'mat-progress-spinner-stroke-rotate-' + diameter" | ||
[style.stroke-dashoffset.px]="_strokeDashOffset" | ||
[style.stroke-dasharray.px]="_strokeCircumference" | ||
[style.transform.rotate]="'360deg'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this? It doesn't look like it does anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know, I thought that was from your commit, but now I have no idea. Maybe it's a weird rebase error? Don't remember adding it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I haven't pulled in your changes into my local branch yet. I tried checking it out and it's not in there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must have been testing something at some point? I'll remove it, in any case.
@kara this one needs a rebase. |
Reworks the progress spinner to use a CSS-based indeterminate animation. For IE and Edge where we can't pull of the animation reliably, it falls back to a non-spec animation.
71c5cb6
to
0504e41
Compare
@kara i am using the latest beta.
on debounced by 300ms keystroke any idea how i could set the spinner to fit the text input field ? |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Reworks the progress spinner to use a CSS-based indeterminate animation. For IE and Edge where we can't pull of the animation reliably, it falls back to a non-spec animation.
Demo: https://material-cb7ec.firebaseapp.com/progress-spinner