messageTray: Drop tween helper function

It makes the code harder to follow and saves little in terms of code
duplication.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/654
This commit is contained in:
Florian Müllner 2018-07-20 21:46:19 +02:00
parent 1abfbb82c5
commit 213d10bf4e

View File

@ -1249,30 +1249,6 @@ var MessageTray = class MessageTray {
this._notificationExpired = false; this._notificationExpired = false;
} }
_tween(actor, statevar, value, params) {
let onComplete = params.onComplete;
let onCompleteScope = params.onCompleteScope;
let onCompleteParams = params.onCompleteParams;
params.onComplete = this._tweenComplete;
params.onCompleteScope = this;
params.onCompleteParams = [statevar, value, onComplete, onCompleteScope, onCompleteParams];
// Remove other tweens that could mess with the state machine
Tweener.removeTweens(actor);
Tweener.addTween(actor, params);
let valuing = (value == State.SHOWN) ? State.SHOWING : State.HIDING;
this[statevar] = valuing;
}
_tweenComplete(statevar, value, onComplete, onCompleteScope, onCompleteParams) {
this[statevar] = value;
if (onComplete)
onComplete.apply(onCompleteScope, onCompleteParams);
this._updateState();
}
_clampOpacity() { _clampOpacity() {
this._bannerBin.opacity = Math.max(0, Math.min(this._bannerBin._opacity, 255)); this._bannerBin.opacity = Math.max(0, Math.min(this._bannerBin._opacity, 255));
} }
@ -1349,17 +1325,20 @@ var MessageTray = class MessageTray {
// We use this._showNotificationCompleted() onComplete callback to extend the time the updated // We use this._showNotificationCompleted() onComplete callback to extend the time the updated
// notification is being shown. // notification is being shown.
let tweenParams = { y: 0, this._notificationState = State.SHOWING;
_opacity: 255, Tweener.removeTweens(this._bannerBin);
time: ANIMATION_TIME / 1000, Tweener.addTween(this._bannerBin, {
transition: 'easeOutBack', y: 0,
onUpdate: this._clampOpacity, _opacity: 255,
onUpdateScope: this, time: ANIMATION_TIME / 1000,
onComplete: this._showNotificationCompleted, transition: 'easeOutBack',
onCompleteScope: this onUpdate: () => this._clampOpacity,
}; onComplete: () => {
this._notificationState = State.SHOWN;
this._tween(this._bannerBin, '_notificationState', State.SHOWN, tweenParams); this._showNotificationCompleted();
this._updateState();
}
});
} }
_showNotificationCompleted() { _showNotificationCompleted() {
@ -1419,16 +1398,20 @@ var MessageTray = class MessageTray {
this._resetNotificationLeftTimeout(); this._resetNotificationLeftTimeout();
if (animate) { if (animate) {
this._tween(this._bannerBin, '_notificationState', State.HIDDEN, this._notificationState = State.HIDING;
{ y: -this._bannerBin.height, Tweener.removeTweens(this._bannerBin);
_opacity: 0, Tweener.addTween(this._bannerBin, {
time: ANIMATION_TIME / 1000, y: -this._bannerBin.height,
transition: 'easeOutBack', _opacity: 0,
onUpdate: this._clampOpacity, time: ANIMATION_TIME / 1000,
onUpdateScope: this, transition: 'easeOutBack',
onComplete: this._hideNotificationCompleted, onUpdate: () => this._clampOpacity,
onCompleteScope: this onComplete: () => {
}); this._notificationState = State.HIDDEN;
this._hideNotificationCompleted();
this._updateState();
}
});
} else { } else {
Tweener.removeTweens(this._bannerBin); Tweener.removeTweens(this._bannerBin);
this._bannerBin.y = -this._bannerBin.height; this._bannerBin.y = -this._bannerBin.height;