The current Xamarin Forms Tabbed Page is very limited and restrictive in nature.
Listing out a few common problems faced by developers
IList<Page>
inside TabbedPage
is rendered at a go before loading, which leads to a huge performance issue in apps where the landing page is TabbedPage
.eg. Scenario, If there are 5 tabbed pages, and each page has enough custom controls, or complex control like Maps, the initial load of the tabbed page will take comparatively more time to load.
etc are still hard
<TabbedPage LazyLoadEnabled="True">
<ContentPage Title="A"/>
<ContentPage Title="B"/>
</TabbedPage>
Once LazyLoadEnabled
flag is set, the pages should only be created once it's selected instead of creating all at the same time. By Default, the flag should be False
so that updating won't affect existing apps.
I have created Custom Renderer to meet a few of the scenarios mentioned in the second problem statement. Although in-built options would delight many users. (Reference https://github.com/muhaym/ElegantTabs)
This is to be really discussed by all the Xamarin.Forms user, because it will be super cool to have on inbuilt in Xamarin Forms. Syncfusion / Grial UI kit has one.
https://grialkit.com/features/ (Custom Tab Control)
https://help.syncfusion.com/xamarin/sftabview/getting-started
This are very initial thought processes, let's discuss to make the best possible outcome for the entire Xamarin Forms community.
But the first (Lazy Loading) should be something of a higher priority because it's an issue plaguing in multiple Xamarin Forms project I believe.
I like your idea
I agree with you, tabbed page needs some love.
The most important thing is the lazy loading of pages. Currently i'm developing 2 simple apps with tabbed as a starting page. The loading performance is very, very poor (expecially on Android, ofc. But we know all this).
I made some research and i found this awesome post by @andreinitescu :
https://enginecore.blogspot.com/2019/01/xamarin-forms-lazy-load-tabs-in_10.html
@Evolutionlab yeah, I saw a Spanish article of code level implementation for same for Prism somewhere. Guess we need to set this simply using inbuilt functionality because of the performance implication of tabbed page
@muhaym Is this what you mean?
@rredoh Yes, tried it, not a ultimate solution though!
Is your ElegantTabs support lazy loading tab?
@rredoh It doesn't support lazy loading. ElegantTabs is just a renderer for a bit more flexibility in Icon, Selected Icons, and handling / deferring tab clicks and handling it manually
@muhaym Ok then.. Thanks for the insight :)
@davidortinau
What are your ideas about implementing ContentTemplate concept as in Shell for TabbedPage.
It will help in performance enhancements.
Any plan to support Lazy Loading Tab
? @samhouts
All the pages IList
inside TabbedPage is rendered at a go before loading, which leads to a huge performance issue in apps where the landing page is TabbedPage.
From what I remember, this is only true on Android. You can actually control this behavior with the OffscreenPageLimit platform specific, although the minimum you can set here is 1. That will significantly improve your initial loading performance, but will, of course, degrade your experience upon switching between tabs.
At this time, we have no plans to work on lazy loading in the core platform. We understand that this reduces the time it takes for your app to load; we're currently focusing on reducing the time it takes for your app to load AND be fully usable.
That said, I'm loving the conversation on this issue, and we're happy to keep this under consideration. Thanks!!
@samhouts , are you saying you can only do one or the other? Could you or one of your colleagues at least do a thorough video on this? Tabs are one of the most popular trends right now, but no one is going to wait 7-10 seconds for a tabbed page to load.
@jamesmontemagno , are you familiar enough with this to put it in your show? Hearing a lot of complaints about the tabbed page speed out here. ):
Thanks to all of you for doing what you have.
As a workaround I created a new class extending the Xamarin.Forms.TabbedPage and I send a message every time one of the tabs is clicked (or in general is diplayed)
public enum TabbedPages
{
MyPage1 = 0,
MyPage2 = 1,
MyPage3 = 2,
}
public class BottomBarPage : Xamarin.Forms.TabbedPage
{
protected override void OnCurrentPageChanged()
{
base.OnCurrentPageChanged();
var newCurrentPage = (TabbedPages)Children.IndexOf(CurrentPage);
MessagingCenter.Send<Xamarin.Forms.TabbedPage>(this, newCurrentPage.ToString("g"));
}
}
and then on the view models (used for each page loaded when clicking on the tab) I subscribe to the message and call my APIs
public class MyPage2ViewModel
{
public MyPage2ViewModel()
{
MessagingCenter.Subscribe<TabbedPage>(this, TabbedPages.MyPage2 .ToString("g"), async (obj) =>
{
//API call
});
}
}
Most helpful comment
I agree with you, tabbed page needs some love.
The most important thing is the lazy loading of pages. Currently i'm developing 2 simple apps with tabbed as a starting page. The loading performance is very, very poor (expecially on Android, ofc. But we know all this).
I made some research and i found this awesome post by @andreinitescu :
https://enginecore.blogspot.com/2019/01/xamarin-forms-lazy-load-tabs-in_10.html