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?
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
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.