Skip to content

Instantly share code, notes, and snippets.

@raulriera
Last active December 18, 2015 06:59
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raulriera/5743410 to your computer and use it in GitHub Desktop.
Save raulriera/5743410 to your computer and use it in GitHub Desktop.
Extending the animation.js Alloy builtins
/**
* @method slideIn
* Makes the specified view appear using a "slide-in" animation, it will automatically
* detect where the view is offscreen and bring it into the user's vison.
* @param {Titanium.UI.View} view View to animate.
* @param {Number} duration Fade duration in milliseconds.
* @param {function()} [finishCallback] Callback function, invoked after the popIn completes.
*/
exports.slideIn = function (view, duration, finishCallback) {
var xValue, yValue;
if (view.top && view.top.indexOf('-') != -1) {
yValue = view.top.substring(1);
} else if (view.bottom && view.bottom.indexOf('-') != -1){
yValue = view.bottom;
} else {
yValue = '0dp';
}
if (view.left && view.left.indexOf('-') != -1) {
xValue = view.left.substring(1);
} else if (view.right && view.right.indexOf('-') != -1){
xValue = view.right;
} else {
xValue = '0dp';
}
if (OS_ANDROID) {
xValue = parseInt(xValue.replace(/[a-z-]gi/, "")) * Ti.Platform.displayCaps.dpi / 160;
yValue = parseInt(yValue.replace(/[a-z-]gi/, "")) * Ti.Platform.displayCaps.dpi / 160;
}
var transform = Titanium.UI.create2DMatrix();
transform = transform.translate(xValue, yValue); // Looks like I can't do this one in one line
var animation = Titanium.UI.createAnimation({
"transform": transform,
"duration": duration
});
if (finishCallback) {
view.animate(animation, finishCallback);
} else {
view.animate(animation);
}
};
@raulriera
Copy link
Author

Hmmm Android doesn't like 'dp' values on the transform (pretty weird...) making a fix

@raulriera
Copy link
Author

This won't "slideIn" from the sizes (not automatically though) maybe I should just let the user pass in the values for X and Y like on Animator?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment