Titanium JIRA Archive
Alloy (ALOY)

[ALOY-1724] Add global event handlers

GitHub Issuen/a
TypeNew Feature
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterNaman Vishoi
AssigneeAbir Mukherjee
Created2020-02-20T16:53:29.000+0000
Updated2020-03-02T15:25:24.000+0000

Description

It'd be great if there is an option to add global event handlers. For example - if on 'close' event of all the windows, I want to execute a line of code, I should be able to do something like this: Ti.UI.windowClose = function(e) { //Do something }

Comments

  1. Naman Vishoi 2020-02-20

    Hi, I think I created the issue in wrong board. Can you move this to Titanium SDK/CLI board ? I don't see that option in the drop down while creating the issue?
  2. Rene Pot 2020-02-24

    [~nvishnoi] thanks for raising the ticket. Only valid tickets go to the TIMOB project in Jira. This is the inbox so it is the correct location. You can already do global events using Ti.App.addEvenListener and Ti.App.fireEvent. You could trigger the event from every window and monitor it at a central place. Something like Ti.App.fireEvent("closewindow", payload) An even better method of globals events would be using Backbone events, so you don't need to "cross the bridge" for every event. See this blog post: https://devblog.axway.com/mobile-apps/global-app-events-in-titanium-using-backbone-js/ If this doesn't answer your question, feel free to reply. Otherwise, I think we can close this ticket! In case you're not in the community yet, join it at https://tislack.org. This is a perfect place for a question like this
  3. Brenton House 2020-02-24

    I think [~nvishnoi] is talking about adding an event once and have it run each time a window was opened or closed, without having to add it each time you created a window. I agree that Ti.App.addEventListener and Ti.App.fireEvent should not be used (due to bridge crossing). I am not aware of this being possible with using Backbone events, but maybe I am missing something. I think this would be a great feature to add to Alloy as it would only require a few lines of code and would allow even more extensibility.
  4. Rene Pot 2020-02-24

    Oh right, in that case, you could override the Alloy.createController method, watch for Window closes dynamically and fire a backbone event. Currently, Alloy doesn't have a built-in global event handler, but that could be PR'd in indeed.

JSON Source