What's the best way to hide a tab in a TabNavigator?
Asked Answered
S

5

9

I'd like to conditionally hide a tab in a TabNavigator. It seems that setting visible doesn't work properly (presumably because this is how the TabNavigator hides the tabs that aren't currently selected).

What's the right way to do this?

Sarazen answered 6/5, 2009 at 18:23 Comment(0)
B
21

You can do this by making use of TabNavigator's getTabAt() method which returns the Button that makes up the visual tab. You can then set that Button's visible property. It's a little tricky to get this setup with a bindings, but it's doable.

You could also consider just disabling the tab instead, which you can do by setting enabled on the corresponding TabNavigator child (for which visible didn't work).

Blackcock answered 6/5, 2009 at 23:20 Comment(1)
This works well, thanks. You also need to set includeInLayout on the Button. I ended up just implementing it with normal listeners, and not worrying about trying to do it with bindings.Sarazen
S
1

What do you mean by hide? If you actually mean remove, then just take your array that's bound to the data in the TabNavigator, and remove the applicable element from it.

If you want to just have them removed temporarily, create a component of your own that encapsulates the TabNavigator and has an array of removed tabs and an array of actual tabs. Then handle this as you see fit.

Scour answered 6/5, 2009 at 18:28 Comment(1)
I mean "don't show, temporarily". Removing it from the TabNavigator seems like overkill. It would be nice to do this in a way that just uses bindings...Sarazen
L
1

You might want to check out the flexlib project. They have a component called SuperTabNavigator that adds a lot of functionality to the base Flex TabNavigator, including hiding tabs (I think).

If you do have to create your own component, though, it's a bit more tricky. The thing to know is that "tabs" are actually specially styled buttons, contained within a TabBar component (the TabBar is then contained within the TabNavigator). What you'll have to do then, is subclass TabNavigator and have some property on your views (i.e. the canvases, etc. that are added to the TabNavigator) that is bound to the visible and includeInLayout properties of the TabBar buttons.

In essence, what you'll have is something like:

BindingUtils.bindProperty( tabButton, "visible", view, "someProperty" );
BindingUtils.bindProperty( tabButton, "includeInLayout", view, "someProperty" );
Loren answered 6/5, 2009 at 20:34 Comment(0)
L
0

I don't know about TabNavigator, but in other containers, you can set the includeInLayout property to false and it will be ignored. You probably still need to combine it with visible.

Leavitt answered 6/5, 2009 at 22:25 Comment(0)
G
0
var secondTab = tabNavigator.removeChildAt(0);
Garrick answered 17/5, 2011 at 14:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.