Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

disable tab

Hi
I would like to disable a tab or at least popup a message saying that you should do a login before using that specific tab.
I have used setActiveTab to enable the login tab, I had some problem sinche the login tab was on the 5th position.

Someone can help me out, in order to disable and put some opacity on specific tabs.

Thank you

— asked October 16th 2010 by Michele Nasoni
  • disable
  • iphone
  • tab
0 Comments

6 Answers

  • Disclaimer: this is a hack.

    I haven't tried this with Andriod but this worked with iPhone. There is definitely a way to do this with the iPhone SDK http://forums.macrumors.com/showthread.php?t=615581. Since it doesn't seem like this feature is exposed though, I'm just adding a transparent image over the tab bar until the user logs in, then I call the disableNonSettingsTabs function on the tabGroup object to remove the image.

    var disableTabsImage = Titanium.UI.createView({
        backgroundImage:'transparent.png',
        height:50,
        width:'100%',
        bottom:0,
        left:0
    });
    tabGroup.add(disableTabsImage);
    
    tabGroup.enableNonSettingsTabs = function(){
        this.remove(disableTabsImage);
    };
    
    tabGroup.disableNonSettingsTabs = function(){
        tabGroup.setActiveTab(settingsTab);
        this.add(disableTabsImage);
    };
    
    var loginAlert = Titanium.UI.createAlertDialog({
        title:'Please login',
        message:'Please login first.'
    });
    
    disableTabsImage.addEventListener('click', function(e){
        loginAlert.show();
    });
    
    — answered April 2nd 2011 by James Starmer
    permalink
    1 Comment
    • I like this - thanks James.

      Don't need the image though - as long touchEnabled is true on the disableTabsView it's all good.
      I also found it a bit nicer to black background with 0.5 opacity - giving the user a clue that it's disabled

      — commented May 24th 2011 by Mick Crozier
  • Have you found the answer? or does anyone? Having the same question here!

    — answered March 15th 2011 by Tjeu Vdw
    permalink
    0 Comments
  • bump. Same problem as well.

    — answered March 21st 2011 by Tom Fischer
    permalink
    0 Comments
  • I have the same problem too…

    — answered April 4th 2011 by Fotis Spatharakis
    permalink
    0 Comments
  • Prevent Tab Switching on Condition

    One way to prevent tab changing is to set the active tab to the tab you were just on when a condition is met. As you can see, it's not very clean:

    var change = true;
    tabGroup.addEventListener('blur',function(e){
        if (lockTabs && change) {
            if (e.previousIndex!=e.index) {
                tabGroup.setActiveTab(e.previousIndex);
                change = false;
            }
        } else if (change===false) {
            change = true;
        }
    });
    

    Explanation: Essentially what it does is switch the tab on the blur event only when:

    • the given condition is met, in this case the lockTabs variable (line 3)
    • the event isn't being fired because we are changing the tab (line 3)
    • the tab clicked is not the tab we were just at (line 4)

    It's kind of confusing, but if you take out the change variable you'll notice that it switches from the active tab to the previous tab in an infinite loop. You have to let the blur event at least fire once freely.

    — answered May 2nd 2011 by Joe iEntry
    permalink
    0 Comments
  • I was googling for lock or disable tab, and found this thread.

    I ended up going with:

    tab1.touchEnabled =false

    or you can also lock the whole tabgroup which is what I wanted awaiting xhr callback

    tabGroup.touchEnabled = false

    My first post! enjoy..

    — answered May 30th 2012 by Jason Gomes
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.