Last active
December 18, 2015 06:59
-
-
Save raulriera/5743410 to your computer and use it in GitHub Desktop.
Extending the animation.js Alloy builtins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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); | |
} | |
}; |
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
Hmmm Android doesn't like 'dp' values on the transform (pretty weird...) making a fix