Devlog

Titanium fireevent and bubbling

In iOS events bubble up from child to parent view by default, but in Android you have to explicitly say so. For example if we have a parentview that adds a childview that has a button in it. After clicking the button, the childview fires a “logout” event on the button. The parent view listens for this event on the child view (so not on the button).

// From the parent view
var childView = Alloy.createController("childView").getView();
childView.addEventListener("logout", function() {
  console.log("Received the logout event from the childView!");
});
$.container.add(childView);

In the childView we fire the logout event from the button:

// From the childView
var button = Ti.UI.createButton({
  title : "Logout"
});
button.addEventListener("click", function() {
  button.fireEvent("logout", {
    bubbles : true
  });
});
$.container.add(button);