Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.
Flavio Maria De Stefano edited this page Nov 3, 2016 · 3 revisions

Flow

Manages the app windows flow using a global navigator and exposing informations about opened controller and windows. It also tracks the screen view and timing automatically - Documentation

Flow uses a concept of navigation though the windows. Once defined a base navigator, it automatically tracks all opened/closed windows (tracking them through Trimethyl.GA module).

On iOS, it uses the default Ti.UI.iOS.NavigationWindow; on Android, instead, the interface of the navigator must be compatible with the Ti.UI.iOS.NavigationWindow interface API, ad you can use the Trimethyl.UIFactory.NavigationWindow to simply do that.

Once you've instantiated a NavigationWindow in your base controller, you should call Flow.startup to assign the Navigator: for example, in your index.xml the code should be something like:

<Alloy>
   <NavigationWindow module="T/uifactory" id="nav">
      <Window module="T/uifactory" id="win">
         /* ... */
      </window>
   </NavigationWindow>
</Alloy>
Flow.startup($.nav, $.win, true);

Once you've set a Navigator, you can move between your Alloy Controllers using the Flow.open(controller, args) method:

Flow.open("users_controller", { id: 2 });

It's advised to use always Alloy Controllers to permit Trimethyl to manage your memory: for example, on the Window's close event, a Controller.off() and Controller.destroy() is called.

If you've custom events that Titanium can't manage, add a method to your controller to release memory like a charm:

exports.cleanup = function() {
   // clean up blobs (release to null)
   largeBlob = null;
   // remove listeners
   Ti.App.removeEventListener('controller_event', func);
   // other memory managements
};

Sometimes, you don't want that certain controllers are opened in the standard flow: could be for strange opening logics.

You can obviously manage these situations by calling Flow.openDirect(controller, args).

Flow.openDirect("modal_window");

The Flow class will execute the $.open() function in your controller if defined, otherwise it try to open the main window of your controller using the standard Alloy call: $.getView().open().

Auto screen tracking + screen timing with Google Analytics

Flow.open and Flow.openDirect calls are tracked with the Google Analytics SDK using the Trimethyl.GA module (you must install the analytics.google module to use this feature), tracking screen with GA.trackScreen and GA.trackTiming when window closes.

You can set the Google Analytics screen name by passing as 4th argument to Flow.open(), Flow.openDirect():

// /users is the screen name
Flow.open('users_controller', { id: 2, }, { animated: true }, '/users');

Pay attention: if you don't set a screen name, the screen name is the controller name (users_controller in the prev. example)

Retrieve current Controller / NavigationWindow / Window

  • Flow.getNavigationController() or Flow.nav() to get current NavigationWindow
  • Flow.getCurrentWindow() or Flow.win() to get opened Window
  • Flow.getCurrentController() to get last opened controller

Close the flow

Once you finished with your natigator, just call:

Flow.close();