-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Android/Forms Tabpage OnAppearing being called twice #2240
Comments
Fully agree @LeoJHarris, I have TabbedPage with 4 tabs, and all of them call OnAppearing method at the same time the app start, it's make the app slower at starup. |
@xamarindevelopervietnam they get called when Android decides to load the renderers for the tabs. Android keeps a certain amount of pages in cache in order to make side scrolling fast. There probably should be a way to configure this behavior. |
I am unable to reproduce this issue on 2.5.1 stable. Can you please confirm it still happens on there and if so produce a small reproduction case? |
Issue still happening see attached repo. OnAppearing method is being called twice within the first inserted tabbed page. See the output and page content labels that also output the number of times methods being called. Doesn't seem right to me. |
Hello, We have TabbedPage and each child of TabbedPage is a NavigationPage which is causing different behaviour in Android. If i remove the NavigationPage wrapper then it is working as expected. Layout is like this In this Layout which is created dynamically in cs file and added as children to TabbedPage, the following difference is found in terms of lifecycle activity calls Page Load - Android Please find the attached sample project |
@sriram15 and @xamarindevelopervietnam: I'm afraid your experience is unrelated to the initial discussion. As @jassmith mentioned, this is expected behavior on Android. The ViewPager preloads a minimum of 1 page on either side of the selected tab. The default is 3 pages. This is configurable via platform specific: using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
namespace TabbedPageTest
{
public partial class TabbedPageTestPage : Xamarin.Forms.TabbedPage
{
public TabbedPageTestPage()
{
InitializeComponent();
On<Android>().SetOffscreenPageLimit(1);
Children.Add(new NavigationPage(new TabPage1()));
Children.Add(new NavigationPage(new TabPage2()));
Children.Add(new NavigationPage(new TabPage3()));
}
... If you attempt to set the
We can't prevent it from preloading the renderers for at least one tab on either side of the selected tab. Android does this for user experience, and it apparently will not let us make that decision for it. However, we can discuss what you expect from the event lifecycle. We have discussed this before on https://forums.xamarin.com/discussion/84510/improved-life-cycle-support and other threads, and I think it's worth adding to that discussion that the OS may force those events on us in somewhat unexpected ways. TLDR; We fully expect there to be Appearing events called for Tabs that are not necessarily visible on the screen. We do not expect the events to be called more than once for a single tab, as @LeoJHarris describes. |
Hello, Not sure it is directly related to this issue (although it looks pretty much the same), I've encountered a regression in my app. Using the attached samples, please find below the behaviour, which is not the same depending on the version of XF. Nothing else is changed in the source code (apart the namespaces from BottomBarOK to BottomBarKO). BottomBarOK - Forms 2.5.0.280555
BottomBarKO - Forms 3.0.0.561731
Any explanation? |
Just to mention that XF 2.5.0.280555 is the last known working version. |
Anyone? Should I create a new issue or is it in the right place? |
Update: it now seems to work as intended, i.e. without me changing anything but the nuget package, with latest XF 3.1.0.583944! |
I still have the issue even with XF 3.1.0.583944. Not on Tab page though, it is a normal content page. |
tabbed pages appears fine now regarding the onappearing, cant comment on non tab pages though. |
Consolidating OnAppearing issues here |
https://bugzilla.xamarin.com/show_bug.cgi?id=51574
Correct me if I am wrong but pretty certain this issue below is similar but not the same as it is regarding the OnDisappearing (see below):
#1438
Description
The OnAppearing method is being called twice for the child tab contentpage that is being displayed when TabbedPage is set as main page of application.
Steps to Reproduce
Expected Behavior
Tab1Page Constructor called.
Tab2Page Constructor called.
Tab1Page OnAppearing method called first time.
Tab2Page OnAppearing method called first time.
Actual Behavior
Tab1Page Constructor called.
Tab2Page Constructor called.
Tab1Page OnAppearing method called first time.
Tab1Page OnDisappearing method called first time.
Tab1Page OnAppearing method called second time.
Tab2Page OnAppearing method called first time.
Basic Information
The text was updated successfully, but these errors were encountered: