SortableJS / Sortable

Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.
https://sortablejs.github.io/Sortable/
MIT License
29.58k stars 3.7k forks source link

No animations when compiling with Angular CLI #1658

Closed DanielToft closed 4 years ago

DanielToft commented 5 years ago

Hi

When compiling SortableJS in production mode with angular CLI, there is no animations. I think, the build-optimizer maybe is removing some code.

I have found an old issue about the same here: https://github.com/SortableJS/ngx-sortablejs/issues/70

I'm using the sortablejs library directly in my angular solution without ngx-sortablejs.

My environment look like this: Angular: 8.2.9 Angular CLI: 8.3.8 sortablejs: 1.10.1

owen-m1 commented 5 years ago

There is currently a repaint function in the animation file that may be being removed in your build. Can you check whether or not it is in your compiled code?

DanielToft commented 5 years ago

Hi @owen-m1

I can see that the repaint function is excluded and the call to repaint in the animate function is excluded too.

Here is the compiled animate function

animate: function(l, n, e, t) {
    if (t) {
        Ei(l, "transition", ""),
        Ei(l, "transform", "");
        var i = Di(this.el)
            , o = (n.left - e.left) / (i && i.a || 1)
            , u = (n.top - e.top) / (i && i.d || 1);
        l.animatingX = !!o,
        l.animatingY = !!u,
        Ei(l, "transform", "translate3d(" + o + "px," + u + "px,0)"),

        // repaint function should be here

        Ei(l, "transition", "transform " + t + "ms" + (this.options.easing ? " " + this.options.easing : "")),
        Ei(l, "transform", "translate3d(0,0,0)"),
        "number" == typeof l.animated && clearTimeout(l.animated),
        l.animated = setTimeout(function() {
            Ei(l, "transition", ""),
            Ei(l, "transform", ""),
            l.animated = !1,
            l.animatingX = !1,
            l.animatingY = !1
        }, t)
    }
}
DanielToft commented 5 years ago

I think angulars build optimizer will remove unused properties, because it assumes that it has no side effects.

I assume that you are calling offsetWidth because you want to force a layout reflow? Maybe you can use getClientRects() instead? It should force a reflow too, but i don't know if that method is slower.

owen-m1 commented 5 years ago

@DanielToft Does calling that function instead cause the code to stay in the compiled build? Also yes I think it would be slower.

denisr-w commented 4 years ago

Still having issues with that. Animation not working, when --prod flag enabled.

amay077 commented 4 years ago

Could you publish to NPM include this PR?