Uploaded image for project: 'Documentation'
  1. Documentation
  2. TIDOC-1055

No documented way to get to the current open window



      There seems to be no documented way to get to the current open window. A component (an Alloy module) may want to listen to certain events happening only in its own window (as there may be multiple windows open with the same component). It may not be possible for one component to get a direct handle of another component's view (e.g. multiple nested views etc.). This means they need a common object inside the window to send and receive events through. The most logical and evident object would be the window itself. Ti.UI.currentWindow normally returns undefined.

      There is, however, no documented way to get the window object from any of its vieww. I have to resort to using undocumented functions:

      Alloy.Globals.getWindowForView = function(view)
      for ( ; view.getParent() != undefined; view = view.getParent()) {};
      return view;

      To actually use the function, I first have to wait until the component is added to the objects tree (and the window object is therefore accessible):

      exports.initialize = function()

      { // Defer attaching of event handlers until the view has been layed out (otherwise no access to window object) $.getView().addEventListener("postlayout", deferredInitialize); }

      function deferredInitialize()

      { $.getView().removeEventListener("postlayout", deferredInitialize); var window = Alloy.Globals.getWindowForView($.getView()); // Perform actual initialization, setting up event listeners etc. // ... }

      It would help a lot that this would at least be documented somewhere.

      Refer to the original discussion here: https://developer.appcelerator.com/question/148840/alloyperform-action-on-view-destruction-remove-event-listeners




            • Assignee:
              bhatfield Benjamin Hatfield (Inactive)
              a.chirikba Andrey Chirikba
            • Watchers:
              3 Start watching this issue


              • Created:

                Backbone Issue Sync

                • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                  Git Integration