Anime: Nativescript support for mobile app usage

Created on 4 Oct 2019  路  3Comments  路  Source: juliangarnier/anime

Hey,
are you going to support Nativescript for using Anime.js in native mobile app development using Nativescript?
or is there any polyfill or developed library to do that?

Most helpful comment

I've published a patched version on npmjs.
https://www.npmjs.com/package/@mabs.dk/nativescript-animejs

Source Code is in my nativescript-branch her:
https://github.com/m-abs/anime/tree/nativescript

I haven't changed a lot, only disabled a few checks that would never work in NativeScript anyway and made a few other minor changes.

All 3 comments

I was just looking into this.

I managed to get it working, it is a bit hacky but it works.

Add this code:

global["NodeList"] = global['HTMLCollection'] = global['SVGElement'] = global['HTMLInputElement'] = function() {} // Needed because anime.js tests with instanceof 

global['window'] = global; // anime.js use window.Promise and this was the quickest way to work around that.

// Requires requestAnimationFrame

// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating

// requestAnimationFrame polyfill by Erik M枚ller. fixes from Paul Irish and Tino Zijdel

// MIT license
(function() {
    const w = global as any;
    var lastTime = 0;
    var vendors = ['ms', 'moz', 'webkit', 'o'];
    for(var x = 0; x < vendors.length && !w.requestAnimationFrame; ++x) {
        w.requestAnimationFrame = w[vendors[x]+'RequestAnimationFrame'];
        w.cancelAnimationFrame = w[vendors[x]+'CancelAnimationFrame'] 
                                   || w[vendors[x]+'CancelRequestAnimationFrame'];
    }

    if (!w.requestAnimationFrame)
        w.requestAnimationFrame = function(callback, element) {
            var currTime = new Date().getTime();
            var timeToCall = Math.max(0, 16 - (currTime - lastTime));
            var id = w.setTimeout(function() { callback(currTime + timeToCall); }, 
              timeToCall);
            lastTime = currTime + timeToCall;
            return id;
        };

    if (!w.cancelAnimationFrame)
        w.cancelAnimationFrame = function(id) {
            clearTimeout(id);
        };
}());

I've published a patched version on npmjs.
https://www.npmjs.com/package/@mabs.dk/nativescript-animejs

Source Code is in my nativescript-branch her:
https://github.com/m-abs/anime/tree/nativescript

I haven't changed a lot, only disabled a few checks that would never work in NativeScript anyway and made a few other minor changes.

Great work @m-abs, NativeScript is currently not in scope for animejs

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dpw1 picture dpw1  路  4Comments

mrgnou picture mrgnou  路  6Comments

ndimatteo picture ndimatteo  路  5Comments

Crashtor picture Crashtor  路  5Comments

gaou-piou picture gaou-piou  路  6Comments