animation: Optionally animate spinner start/stop

In contrast to generic animated icons, it is reasonable to expect
spinners to be invisible while inactive. Implement that behavior
in the new Spinner class and optionally animate the transitions.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/316
This commit is contained in:
Florian Müllner
2018-11-28 17:34:48 +01:00
committed by Florian Müllner
parent 22e21ad7d1
commit 945a019974
3 changed files with 51 additions and 50 deletions

View File

@ -8,7 +8,11 @@ const St = imports.gi.St;
const Signals = imports.signals;
const Atk = imports.gi.Atk;
const Tweener = imports.ui.tweener;
var ANIMATED_ICON_UPDATE_TIMEOUT = 16;
var SPINNER_ANIMATION_TIME = 0.3;
var SPINNER_ANIMATION_DELAY = 1.0;
var Animation = new Lang.Class({
Name: 'Animation',
@ -92,8 +96,46 @@ var Spinner = new Lang.Class({
Name: 'Spinner',
Extends: AnimatedIcon,
_init(size) {
_init(size, animate=false) {
let file = Gio.File.new_for_uri('resource:///org/gnome/shell/theme/process-working.svg');
this.parent(file, size);
this.actor.opacity = 0;
this._animate = animate;
},
play() {
Tweener.removeTweens(this.actor);
if (this._animate) {
this.parent();
Tweener.addTween(this.actor, {
opacity: 255,
delay: SPINNER_ANIMATION_DELAY,
time: SPINNER_ANIMATION_TIME,
transition: 'linear'
});
} else {
this.actor.opacity = 255;
this.parent();
}
},
stop() {
Tweener.removeTweens(this.actor);
if (this._animate) {
Tweener.addTween(this.actor, {
opacity: 0,
time: SPINNER_ANIMATION_TIME,
transition: 'linear',
onComplete: () => {
this.stop(false);
}
});
} else {
this.actor.opacity = 0;
this.parent();
}
}
});