Skip to content

Instantly share code, notes, and snippets.

@kwhinnery
Created November 5, 2011 02:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwhinnery/1341023 to your computer and use it in GitHub Desktop.
Save kwhinnery/1341023 to your computer and use it in GitHub Desktop.
//Wrapper class to create extensible Titanium components
exports.Component = function(/*Object*/ tiView) {
var self = {
__viewProxy:tiView
};
//passthrough for add
self.add = function(/*Object*/ tiChildView) {
var v = tiChildView.__viewProxy||tiChildView;
self.__viewProxy.add(v);
};
//passthrough for remove
self.remove = function(/*Object*/ tiChildView) {
var v = tiChildView.__viewProxy||tiChildView;
self.__viewProxy.remove(v);
};
//passthrough for open
self.open = function(args) {
if (self.__viewProxy.open) {
self.__viewProxy.open(args||{animated:false});
}
};
//set/get properties on the view proxy
self.set = function(k,v) {
self.__viewProxy[k] = v;
};
self.get = function(k) {
return self.__viewProxy[k];
}
//passthrough for animation
self.animate = function(args,cb) {
self.__viewProxy.animate(args,cb||function(){});
};
//passthrough and shorthand for events
self.on = function(name,cb) {
self.__viewProxy.addEventListener(name,cb);
};
self.fire = function(name,e) {
self.__viewProxy.fireEvent(name,e||{});
}
//memory management
self.onDestroy = function(){};
self.release = function() {
self.__viewProxy = null;
self.onDestroy();
};
return self;
};
@rblalock
Copy link

rblalock commented Nov 7, 2011

NOICE! I like it.

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