Skip to content

Instantly share code, notes, and snippets.

@zo0m
Last active August 29, 2015 14:20
Show Gist options
  • Save zo0m/7125a34a843a513fd161 to your computer and use it in GitHub Desktop.
Save zo0m/7125a34a843a513fd161 to your computer and use it in GitHub Desktop.
Appcelerator Titanium iOS animation issue workaround
var version = '2.3';
exports.animate = function (item, paramName, paramCurrentValue, paramTargetValue, duration, timeout) {
Ti.API.debug("ZEAnimator[" + version + "]#animate: " + item.apiName + "[" + item.id + "]." + paramName + '(' + item[paramName] + '): ' + paramCurrentValue + ' --> ' + paramTargetValue + " (d:" + duration + ', t:' + timeout + ')');
if (
(item[paramName] === paramTargetValue)
|| (
!isNaN(parseInt(item[paramName]))
&& !isNaN(parseInt(paramTargetValue))
&& parseInt(item[paramName]) === parseInt(paramTargetValue)
)
) {
Ti.API.debug("Animation no needed, because current and target params are equal.");
item[paramName] = paramTargetValue;
return;
}
setTimeout(
function() {
item[paramName] = paramCurrentValue || item[paramName] || 0;
var animationParams = {
duration: duration
};
animationParams[paramName] = paramTargetValue;
item.animate(animationParams, function() {
item[paramName] = paramTargetValue; // stupid but it works
});
},
timeout
);
}
exports.animateHeight = function (item, duration, heightFrom, heightTo) {
exports.animate(item, 'height', heightFrom, heightTo, duration, 10)
}
exports.animateTop = function (item, duration, topFrom, toptTo) {
exports.animate(item, 'top', topFrom, toptTo, duration, 10)
}
exports.animateHide = function (item, duration) {
var paramName = 'opacity';
var defaultCurrentParamValue = 1;
exports.animate(item, paramName, (item[paramName] || defaultCurrentParamValue), 0, duration, 10)
}
exports.animateShow = function (item, duration, targetOpacity) {
var paramName = 'opacity';
var defaultCurrentParamValue = 1;
exports.animate(
item,
paramName,
(item[paramName] || defaultCurrentParamValue),
(targetOpacity || 1),
duration,
10
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment