Skip to content

Instantly share code, notes, and snippets.

Last active Aug 29, 2018
What would you like to do?
Passing through event listeners to widget view elements in Titanium Alloy.
function doClick(e) {
// Remove the event listener like this:
// $"click", doClick);
<Widget id="myWidget" src="my.alloy.widget" doClick="doClick" />
// Overwrite Backbone methods, as used in the generated code by Alloy:
// doClick ? $.__views.myWidget.on("click", doClick) : __defers["$.__views.myWidget!click!doClick"] = !0;
exports.on = $.label.addEventListener; = $.label.removeEventListener;
// Overwrite backbone aliasses:
exports.bind = $.label.addEventListener;
exports.unbind = $.label.removeEventListener;
// Support Titanium methods
exports.addEventListener = $.label.addEventListener;
exports.removeEventListener = $.label.removeEventListener;
// Overwrite Backbone trigger and Titanium fireEvent methods for convenience
exports.trigger = $.label.fireEvent;
exports.fireEvent = $.label.fireEvent;
<Label>Hello World</Label>
Copy link

budowski commented Mar 12, 2014

OK, this seemed to solve it on Android as well (I'm pretty sure it's not the best way to work around it):

exports.on = function(name, cb) { return $.label.addEventListener(name, cb); }; = function(name, cb) { return $.label.removeEventListener(name, cb); };
exports._hasListenersForEventType = function(name, flag) {
    return $.label._hasListenersForEventType(name, flag);

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