Changing menu tab text dynamically

0 votes
asked Oct 27, 2016 in Help by raydekk (530 points)
Hello,

I'm trying to change the tabName text when a button is touched. The problem is that the tabs are generated at runtime and the button is touched sometime later in the app (when the user does it).

So even if i change the page1GO.GetComponent<TabPage> ().tabName, the whole tab menu needs to be recreated (I think) - or as a feature request it would be really nice if there was an event to update the text from the generated tab game objects when the tabName is changed.

Any idea how I could recreate the tab menus?

Thanks

2 Answers

0 votes
answered Oct 27, 2016 by raydekk (530 points)
Found it - just call

tabView.GetComponent<TabView> ().InitializeTabs ();

after :)
commented Oct 27, 2016 by raydekk (530 points)
P.S. TabView still doesn't display properly when switching from Portrait to Landscape or viceversa (tested on 1.1.6).

Tried doing a

                    InitializeTabs();
                    InitializePages();

when the OnDeviceChange was fired but it's still glitching.
commented Oct 31, 2016 by admin (31,720 points)
Is the MaterialUIScaler's reference resolution swapping the X/Y values when you rotate?

~ Declan.
commented Oct 31, 2016 by raydekk (530 points)

It seems that way, but I haven't checked the values on the device.

Overall 1.1.6 seems like a great update, at least 3 issues I knew of were fixed. I haven't checked it on iOS yet.

The only two issues that remain are:

- the NavDrawer in Portrait mode (sometimes it's at 1/2 screen or in this case at 1/3 screen - should be at 3/4 screen (way more screen covered by it)

 - the tabview looks like this after a few portrait/landscape changes on Android (it does seem to render it correctly the first 2 times or so).

 

the screen to the right is actually the next tab (Social)

commented Oct 31, 2016 by admin (31,720 points)
What reference resolution are you working with? Are those issues present if you use 360x640 (or 640x360 for landscape)?

~ Declan.
commented Oct 31, 2016 by raydekk (530 points)
I'm using 800x600 - will give it a shot with 640x360 when I get the chance.
commented Oct 31, 2016 by anonymous

The TabView bug on 800x600 is the same on 640x360.

I start the app on portrait, I go to the menu that has the 3 tabs, they are correctly placed. I switch to landscape - they are correct again. I switch to portrait - they are screwed up. I see half (or so) of the first tab.

I switch to landscape again and I can see the first tab and a part of the second tab.

0 votes
answered Nov 21, 2016 by admin (31,720 points)
Hey,

Just wanted to point out that there's a way better way to update the tabName.
Calling InitializeTabs is not optimal at all :)

You can just do:
tabView.GetComponent<TabView>().tabs[0].itemText.text = "yourTitle"

Of course here I've used tabs[0], but if it's your second tab or third, you would use tabs[1], tabs[2] etc...

~ Yohan
commented Dec 13, 2016 by raydekk (530 points)
Hey Yohan,

About the NavDrawer in Portrait mode - did you manage to reproduce it? This and the TabView bug are the only things keeping me from publishing the app in portrait mode (only landscape for now).

But I can rearrange the menus and discard the TabView - so the NavDrawer bug would be the only one left.

Thanks,

Raydekk
commented Dec 14, 2016 by admin (31,720 points)
Hey Raydekk,

Sorry but it's Declan who will look on this issue, and he's super busy at the moment :/
But it will be done don't worry!

I'm really sorry for making you wait like that :(

~ Yohan
commented Dec 14, 2016 by raydekk (530 points)
No problem :)
commented Jan 5, 2017 by admin (31,720 points)
Hi raydekk,

I'm working on fixing that Tabs issue :)

Just double checking - are you still getting the NavDrawer bug since switching to 360x640 as the reference resolution?

~ Declan.
commented Jan 5, 2017 by raydekk (530 points)
Hey Declan,

I think I found a workaround. I will try to change the canvas scaler reference resolution from 360x640 to 800x600 each time the mobile is switching from portrait to landscape.

And to 360x640 when it's switching back.

I think I know what my issue was. I'm trying to build an app that would work on all 4 orientations, so when the orientation changed I was expecting 800x600 to turn into 600x800 automatically. That would be a nice-to-have :)

 

Raydekk
commented Jan 5, 2017 by admin (31,720 points)
Hey Raydekk,

The MaterialUIScaler is supposed to do exactly that (that's what the 'match orientation to screen' option is), so it seems it's not working properly and I'll look into that.

In the meantime, I'd recommend disabling that option if your solution works to avoid any possible issues :)

~ Declan.
commented Jan 5, 2017 by raydekk (530 points)
Ok retested and it's working. My resolution is 360x800 (this way it looks great on both portrait and landscape). Sorry for the misunderstanding. I think my issue was testing from the Unity Editor in landscape with a portrait resolution (360x640 for example).

The only bug that remains is the one with the TabView (screens above). When changing from landscape to portrait, the tabview tabs sizes remain the same so for example if you started in portrait and you switch to landscape while looking at a tabview, you will see the first tab + a portion of the second tab like in the second picture (blue upper panel).

IMO, this isn't such an important bug, the orientation changing was my biggest problem, the TabView is just cosmetic (I scrapped tabs from my projects, will bring them back when they're fixed). You guys should focus on other more important task you probably must have :)

Thank you for all the great work,

Raydekk
commented Jan 13, 2017 by admin (31,720 points)
Thanks a lot :)

We've added the tab issue to the list of things to do. If you see this still hasn't been fixed in a while, feel free to ping us again!

Have a great day.

~ Yohan
Welcome to MaterialUI support! Ask us anything :)
...