Accessing Parent tabGroups and/or Windows

You must Login before you can answer or comment on any questions.

Hi there,

I've built a prototype application which is just a 3-tab tab-group with 1 window each. So in essence

page1.xml, page1.tss, page.js

page2.xml, page2.tss, page2.js

page3.xml, page3.tss, page3.js

I want to use setActiveTab - To programatically control which tab to trigger from a custom button (i.e. not the tab group itself)

So inside say page2.js I try do this:

$.btnSettings.addEventListener("click", function() {
    $.tabGroup.setActiveTab(2);
});
I get an undefined error, and I just basically can't access the tab group nor the current Tab using the stadard Titanium 2 docs

Where $.tabGroup is also the ID in the index.xml file like so:

<TabGroup id='tabGroup'>
        <Require src="page1"/>
        <Require src="page2"/>
        <Require src="page3"/>
    </TabGroup>
Any help would be amazing!

2 Answers

Accepted Answer

$.tabGroup will only reference the tabgroup you created in the view/controller that contains the tabgroup, in this case, it would only work in index.js, but not in page1.js, page2.js, or page3.js. If you want to be able to access the tabgroup globally, you'll need to create a global reference to it. You can do so by:

  • Attaching a property to Alloy.CFG, which is available in all controllers, that holds the reference to the tabgroup.
  • Create a standard commonjs module in "lib" that basically does the same thing as Alloy.CFG, a module for passing around global values.
— answered 8 months ago by Tony Lukasavage
answer permalink
1 Comment
  • You can access a library in a widget just like you would in any other controller, but you probably shouldn't. Widgets are meant to be totally self-contained and have no external dependencies.

    If you still wanted to access a library in a widget, say the library "app/lib/myLib.js", you would simply do the following in your widget's controller code:

    var myLib = require('myLib');
    If you instead packaged the library with the widget, say in "app/widgets/WIDGET_ID/lib/myLib.js", then you could access like this in your widget code:
    var myLib = require('WIDGET_ID/myLib');
     
    // or you can use the shorthand WPATH() version
    var myLib = require(WPATH('myLib'));
    for more info on exactly how the shorthand function WPATH() works, check here: https://github.com/appcelerator/alloy/blob/master/test/apps/widgets/wpath/widgets/com.test.hellobutton/controllers/widget.js

    — commented 8 months ago by Tony Lukasavage

Thanks for the reply.

So based on this structure, how would I use a file in /lib/ within a widget? as in with the require method?

Your Answer

Think you can help? Login to answer this question!