dnd: Emit drag-end in after snapback complete
Emit the signal at the correct time to take action on snapback (i.e. after the end of the snapback animation). Add a boolean to the drag-end signal saying whether it was accepted, which ensures consumers know whether the drag was successful.
This commit is contained in:
parent
296e0c2054
commit
c23b9ee192
11
js/ui/dnd.js
11
js/ui/dnd.js
@ -153,8 +153,6 @@ _Draggable.prototype = {
|
|||||||
if (!dragging)
|
if (!dragging)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
this.emit('drag-end', event.get_time());
|
|
||||||
|
|
||||||
// Find a drop target
|
// Find a drop target
|
||||||
actor.hide();
|
actor.hide();
|
||||||
let [dropX, dropY] = event.get_coords();
|
let [dropX, dropY] = event.get_coords();
|
||||||
@ -173,6 +171,7 @@ _Draggable.prototype = {
|
|||||||
if (actor.get_parent() == actor.get_stage())
|
if (actor.get_parent() == actor.get_stage())
|
||||||
actor.destroy();
|
actor.destroy();
|
||||||
|
|
||||||
|
this.emit('drag-end', event.get_time(), true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -196,19 +195,21 @@ _Draggable.prototype = {
|
|||||||
transition: "easeOutQuad",
|
transition: "easeOutQuad",
|
||||||
onComplete: this._onSnapBackComplete,
|
onComplete: this._onSnapBackComplete,
|
||||||
onCompleteScope: this,
|
onCompleteScope: this,
|
||||||
onCompleteParams: [actor]
|
onCompleteParams: [actor, event.get_time()]
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
_onSnapBackComplete : function (dragActor) {
|
_onSnapBackComplete : function (dragActor, eventTime) {
|
||||||
if (this._dragOrigParent) {
|
if (this._dragOrigParent) {
|
||||||
dragActor.reparent(this._dragOrigParent);
|
dragActor.reparent(this._dragOrigParent);
|
||||||
dragActor.set_scale(this._dragOrigScale, this._dragOrigScale);
|
dragActor.set_scale(this._dragOrigScale, this._dragOrigScale);
|
||||||
dragActor.set_position(this._dragOrigX, this._dragOrigY);
|
dragActor.set_position(this._dragOrigX, this._dragOrigY);
|
||||||
} else
|
} else {
|
||||||
dragActor.destroy();
|
dragActor.destroy();
|
||||||
}
|
}
|
||||||
|
this.emit('drag-end', eventTime, false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Signals.addSignalMethods(_Draggable.prototype);
|
Signals.addSignalMethods(_Draggable.prototype);
|
||||||
|
Loading…
Reference in New Issue
Block a user