Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabbed page behavior change #1195

Merged
merged 4 commits into from
Oct 5, 2017
Merged

Conversation

brianlagunas
Copy link
Member

@brianlagunas brianlagunas commented Oct 5, 2017

We are making a breaking change to the behavior of navigating to a TabbedPage.

Current Behavior (v6.3.0)

NavigateAsync("TabbedPage/ViewA/ViewB") will select the tab ViewA in the TabbedPage if it exists, then continue navigating. If ViewA does not exist as a tab, then you will continue to navigate as expected.

NavigateAsync("TabbedPage/NavigationPage/ViewA/ViewB") would search the TabbedPage for the first instance of a tab that was a NavigationPage, then navigate within the Navigation page the remaining ViewA and ViewB pages. This provided the ability to deep link into a tab's nested navigation page, but there was no way to opt-out of this behavior.

Also, the INavigationAware methods did not get called to all tabs meaning that you would be responsible for forwarding any parameters to all your tabs.

New Behavior

NavigateAsync("TabbedPage/ViewA/ViewB") will no longer select any tabs, but rather continue processing the navigation as separate pages on the navigation stack.

If you wish to select a tab, you will now use a parameter called "selectedTab" to indicate which tab you would like to select.

NavigateAsync("TabbedPage?selectedTab=MiddleTab/ViewA/ViewB")

This will navigate to the TabbedPage, selected the "MiddleTab" and continue navigating ViewA and ViewB onto the navigation stack.

For tabs that are wrapped inside a NavigationPage, you do not need to change anything. The syntax is the same. This will search each tab to see if it is a navigation page and if the CurrentPage of the NavigationPage matches "MiddleTab", the tab will be selected. This is much more flexible than the existing behavior as before it would take the first instance of the NavigationPage found. Now you can choose which tab exactly.

There is a constant in the KnownNavigationParameters called SelectedTab that you can use instead of a string.

NavigateAsync($"TabbedPage?{KnownNavigationParameters.SelectedTab}=MiddleTab")

This will search each tab to see if it is a navigation page and if the first page on the stack matches "MiddleTab". This is much more flexible than the existing behavior as before it would take the first instance of the NavigationPage found. Now you can choose which tab exactly.

Some INavigationAware methods are now fired on all Tabs:

  • OnNavigatingTo will be invoked on the TabbedPage and ALL TABS.
  • OnNavigatedTo will be invoked on the TabbedPage and only the SELECTED TAB.
  • OnNavigatedFrom will be invoked on the TabbedPage and only the SELECTED TAB.

Note: the parameter key selectedTab is now a reserved parameter name. Similar to a reserved keyword in C#. If you use this in your app as a key, you may experience undesired behavior.

Note: At this time there is no native support for deep linking into a Tab that is a navigation page. Please let me know if you need this functionality.

Feel free to test this out with the latest 7.0.0.124-ci build on MyGet

https://www.myget.org/gallery/prism

@OpticNectar
Copy link

@brianlagunas Do you still need to handle IActiveAware for initial tab selection or is there a better way to handle it now?

@dansiegel
Copy link
Member

@OpticNectar yes it's still handled though I suggest using IPageLifecycleAware instead

@OpticNectar
Copy link

@dansiegel How do I use IPageLifecycleAware? This is the first time i'm hearing of it.

@brianlagunas
Copy link
Member Author

I wouldn't necessarily recommend IPageLifecycleAware over IActiveAware unless you need the advanced functionality to run code when changing tabs (both to and away). IActiveAware is useful for the simple case of when you just need to know if you are the selected tab or not.

@dansiegel
Copy link
Member

@OpticNectar IPageLifecycleAware hooks into the Page.OnAppearing and Page.OnDisappearing events, and works across the entire app. It's ultimately better than IActiveAware because it will trigger after OnNavigatingTo which means that you will always be assured that you can execute that code after the ViewModel has initialized with OnNavigatingTo, where IActiveAware.IsActive is set to true on your initial view before OnNavigatingTo has been called.

@brianlagunas
Copy link
Member Author

One is not better than the other. It depends on the functionality you need. Need to run code only when the view is rendered on screen, use IPageLifecycleAware. Need to run code when the tab has been selected regardless of the state of the rendered view, or if you just need a simple "selected tab" check, then IActiveAware.

@OpticNectar
Copy link

@dansiegel @brianlagunas I just need to run code when the tab is selected to load data. Either works, it's just confusing how to set either up properly since i'm not sure what I add to the page's code behind, what I need in the view model, and what I need, if anything, in the tab page for it all to work.

@OpticNectar
Copy link

OpticNectar commented Nov 1, 2017

@dansiegel @brianlagunas Quick question. I have a TabbedPage in a MasterDetail page. Each tab has a NavigationPage. How can I get from MasterDetail/TabPage/HomePage to MasterDetail/TabPage/LastPage?

I tried doing this and it does all sorts of weird things like load everything again in the current tab etc. I can build a sample project if you would like.

@OpticNectar
Copy link

@dansiegel @brianlagunas Any thoughts on this? Trying to figure out a way I can get this working so I can release the app i'm working on.

@brianlagunas
Copy link
Member Author

@OpticNectar your issue isn't really a Prism issue. but rather a very specific requirement for your app. You will need to use a custom implementation to achieve this. @dansiegel and I do have an hourly rate if you would like us to create a solution for you.

@OpticNectar
Copy link

@brianlagunas I'm a bit confused why it isn't a Prism issue. I'm just trying to navigate a TabbedPage. It's just that the TabbedPage is in a MasterDetail page. Is that not ever going to be supported in Prism? It seems odd to only support some types of navigation and not others.

@brianlagunas
Copy link
Member Author

It's not a prism issue because changing the selected tab is not navigation. An no, it is not planned implement a feature that allows you to change tabs without user interaction.

@OpticNectar
Copy link

@brianlagunas Sorry, I guess i'm really confused now. Isn't that what this change is? It literally says If you wish to select a tab, you will now use a parameter called "selectedTab" to indicate which tab you would like to select above. Does that not do what it says?

@brianlagunas
Copy link
Member Author

That only happens when you first navigate to a TabbedPage. I twill not support being on a tab in a TabbedPage, and then changing tabs again. It is only for an initial tab selection to get the TabbedPage in the correct state when it is first navigated to.

@OpticNectar
Copy link

@brianlagunas Oh ok. You may want to make a not of that in the docs then, since I assumed it would work across the app and not just on start up. I guess my next question would be, is there a way to navigate a specific tab without it being selected first? Even if i'm just using a messaging system, or does it need to be selected first before navigation will work?

@brianlagunas
Copy link
Member Author

Good point. We will be sure to clarify the feature when we actually get to writing some docs :)

Of course it's possible. You just need to find a solution that works for you. messaging might work for you. Remember, changing tabs is not navigation. So everything will work just fine.

@OpticNectar
Copy link

@brianlagunas Ok awesome. Thanks! Also, since you and @dansiegel have hourly rates, what is the best way to get in touch with you guys? We have app projects that need some custom components here and there and it would be good to have some experts to help out when we need it.

@brianlagunas
Copy link
Member Author

The best way is on our Slack Channel. You can direct message us privately there.

@randalvance
Copy link

randalvance commented Mar 3, 2018

@brianlagunas Can I navigate to a tabbed page tab within a tabbed page (nested tabbed page)?

Looking at the code, it looks like it terminates at the last tabbed page.

It would be great if we can do this:
TabbedPage?selectedTab=AnotherTabbedPage/AnotherTabbedPageTab

@VahidShir
Copy link

VahidShir commented Jul 20, 2019

Can someone tell me whether INavigationAware methods will be fired if a tab is tapped by user from tab bar? Currently those methods will only be fired if the tab is chosen programmatically i.e by this command using Prism 7.2.0.1347-pre:
NavigationService.SelectTabAsync(nameof(SecondPage));

@lock
Copy link

lock bot commented Jan 28, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants