Created
December 20, 2011 19:59
-
-
Save kwhinnery/1503005 to your computer and use it in GitHub Desktop.
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
//Wrapper class to create extensible Titanium components | |
function Component(/*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}); | |
} | |
}; | |
self.close = function() { | |
if (self.__viewProxy.close) { | |
self.__viewProxy.close(); | |
} | |
}; | |
//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; | |
} | |
module.exports = Component; |
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
var Component = require('Component'); | |
var wrapped = new Component(Ti.UI.createView({ | |
backgroundColor:'red' | |
})); | |
wrapped.set('top',5); | |
wrapped.set('left',5); | |
wrapped.on('click', function() { | |
alert('clicked'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment