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;
Tweener.removeTweens(this._bannerBin);
Tweener.addTween(this._bannerBin, {
y: 0,
_opacity: 255, _opacity: 255,
time: ANIMATION_TIME / 1000, time: ANIMATION_TIME / 1000,
transition: 'easeOutBack', transition: 'easeOutBack',
onUpdate: this._clampOpacity, onUpdate: () => this._clampOpacity,
onUpdateScope: this, onComplete: () => {
onComplete: this._showNotificationCompleted, this._notificationState = State.SHOWN;
onCompleteScope: this this._showNotificationCompleted();
}; this._updateState();
}
this._tween(this._bannerBin, '_notificationState', State.SHOWN, tweenParams); });
} }
_showNotificationCompleted() { _showNotificationCompleted() {
@ -1419,15 +1398,19 @@ 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);
Tweener.addTween(this._bannerBin, {
y: -this._bannerBin.height,
_opacity: 0, _opacity: 0,
time: ANIMATION_TIME / 1000, time: ANIMATION_TIME / 1000,
transition: 'easeOutBack', transition: 'easeOutBack',
onUpdate: this._clampOpacity, onUpdate: () => this._clampOpacity,
onUpdateScope: this, onComplete: () => {
onComplete: this._hideNotificationCompleted, this._notificationState = State.HIDDEN;
onCompleteScope: this this._hideNotificationCompleted();
this._updateState();
}
}); });
} else { } else {
Tweener.removeTweens(this._bannerBin); Tweener.removeTweens(this._bannerBin);