Hello,
I was wondering if there was a way to get a callback when a Scrollview is done dragging so that I can center it on the nearest child.
Something along the lines of:
this.entity.scrollview.on('doneDragging',this.centerScrollvew,this);
The only event for Scrollviews that I can find in the forums or online is ‘set:scroll’ but I just need to fire a method when the dragging is done.
Thanks,
Justin
There is but it’s not public API.
this._toggleElementListeners('off'); } } _onViewportElementGain() { this._syncAll(); } _onContentElementGain() { this._destroyDragHelper(); this._contentDragHelper = new ElementDragHelper(this._contentReference.entity.element); this._contentDragHelper.on('drag:start', this._onContentDragStart, this); this._contentDragHelper.on('drag:end', this._onContentDragEnd, this); this._contentDragHelper.on('drag:move', this._onContentDragMove, this); this._prevContentSizes[ORIENTATION_HORIZONTAL] = null; this._prevContentSizes[ORIENTATION_VERTICAL] = null; this._syncAll(); }
You can listen on the drag helpers events for drag:end
Thank you for your response!
Could you give an example of how to do that? I am not very clear what you mean by listen on the drag helpers for the scrollview.
Something like this?
this.entity.scrollview._contentDragHelper.on(‘drag:end’,this.centerScrollview,this);
Actually, just trying this myself and looking at the code, it’s not as easy as that unfortunately. Doesn’t feel like there’s a good way of doing this.
The closest I’ve got is this that uses the private API that is least likely to change: https://playcanvas.com/editor/scene/1155593
var DragEnd = pc.createScript('dragEnd');
// initialize code called once per entity
DragEnd.prototype.initialize = function() {
this._draggingLastFrame = this.entity.scrollview._isDragging();
};
// update code called every frame
DragEnd.prototype.update = function(dt) {
var dragging = this.entity.scrollview._isDragging();
if (this._draggingLastFrame && !dragging) {
console.log('drag end');
}
this._draggingLastFrame = dragging;
};
2 Likes
Hey thank you so much for getting a solution worked up for me! I really appreciate that!