Xamarin.forms: Android/Forms Tabpage OnDisappearing firing minimized

Created on 20 Dec 2017  路  14Comments  路  Source: xamarin/Xamarin.Forms

Migrated from https://bugzilla.xamarin.com/show_bug.cgi?id=44211

Description

Steps to Reproduce

Run Sample for Tabs Android Forms.

Click Push Page2.
Click Push Tab

Tab Message:
Tab2Page2 Appear (OK)
TabPage1 Appear (OK)
TabPage1 Disappear (WHY? wrong)
TabPage1 Appear (WHY 2 times?)
Tabpage2 Disappear (WHY?)

Expected Behavior

What I think should happen.
TabPage1 Appear
TabPage2 Appear

Proposed solution: #354

Basic Information

  • Version with issue: 2.4.0.91020

Reproduction Link

FormsAppearDisappear.zip

Android bug

Most helpful comment

The issue is still present on latest stable version of Xamarin.Forms. Do you know if the version 2.5.1 is going to contain this fix?

btw, the issue is not only for the event onDisappearing but also the event onAppearing.

All 14 comments

how i can fix this behavior?

Hi Guys,

It is crazy, i posted a solution since last may 2017 on the PR 354.

It is seems nobody want really solve this problem.

If you comment lines 37 to 51 in FragmentContainer.cs, the events appears all normal....

public override bool UserVisibleHint
{
    get { return base.UserVisibleHint; }
    set
    {
        base.UserVisibleHint = value;
//      if (_isVisible == value)
//          return;
//      _isVisible = value;
//      if (_isVisible.Value)
//          PageController?.SendAppearing();
//      else
//          PageController?.SendDisappearing();
    }
}

In facts, if you comment thoses lines (UserVisibleHint), methods below, do their jobs.

public override void OnHiddenChanged(bool hidden)
{
    base.OnHiddenChanged(hidden);

    if (Page == null)
        return;

    if (hidden)
        PageController?.SendDisappearing();
    else
        PageController?.SendAppearing();
}

public override void OnPause()
{
    bool shouldSendEvent = Application.Current.OnThisPlatform().GetSendDisappearingEventOnPause();
    if (shouldSendEvent)
        SendLifecycleEvent(false);

    base.OnPause();
}

public override void OnResume()
{
    bool shouldSendEvent = Application.Current.OnThisPlatform().GetSendAppearingEventOnResume();
    if (shouldSendEvent)
        SendLifecycleEvent(true);

    base.OnResume();
}

Can someone confirm that ?
Best regards,
Paulin

Just to confirm that the bug is indeed hitting me too with latest XF 2.5.0.121934
Any clue of when that can be fixed?

This is happening for me too.

@JayShockwave @nbsoftware what0s the issue you are seeing? the only thing i see is that TabPage1 Appearing doesn't fire the 1st time with the latest 2.5.0

After some digging, I found that my issue was actually something else, unrelated to this one.
Sorry.

@rmarinho I spend a good part of this morning trying to reproduce the behavior in a simpler form to illustrate but I am unable to do so. Must be a bug in my code. Disregard my comment, thanks.

I can repro the case. And I have a very basic and simple sample.
I am using the Xamarin.Forms Version 2.5.0.122203!

Main Page launching TabbedPage with 2 pages Page1 and Page2

Page1::OnAppearing is called twice. Launch application. Click button. Debug output shows:

[0:] MainPage::OnAppearing
[0:] MainPage::OnTestClicked
[0:] Page1::OnAppearing
[0:] Page1::OnDisppearing
[0:] Page1::OnAppearing

DoubleOnAppear.zip

The issue is still present on latest stable version of Xamarin.Forms. Do you know if the version 2.5.1 is going to contain this fix?

btw, the issue is not only for the event onDisappearing but also the event onAppearing.

I just installed forms 2.5.1 into my project and the OnAppearing is still being called twice. Pretty sure there needs also to be a new issue "Android/Forms Tabpage OnAppearing firing minimized".

Hello,

May I ask why this one seems to be closed?

As far as I can see, I still have the issue with in latest XF 3.0.0.561731.

Is it because it is linked to #2240 which happens to be still opened (although it think it is not the exact same issue)?

This is very frustrating because I have a XF Map on the first tab and it refreshes in a very very ugly way when switching from another tab to this one - only in Android of course.

Hi @nbsoftware, please open a new issue with a sample project demonstrating the problem if you're issue doesn't appear to be solve in the latest 3.0.0.

Hi @davidortinau ,
Well you are correct, with the sample attached to this issue, it does work now.
After further investigation, my project involves a specific Android BottomBar implementation as well as NavigationPages for all tab pages.
In that context, the bug still appears in latest XF versions.
It does not if tab pages are simple pages.
But the weird thing is that it wasn't happening with some previous version of XF.
I'll try to take some time to build 2 samples demonstrating the problem and create a new issue.
Thanks

Hi everyone,
this bug is fixed in the latest Xamarin.Forms version. However, if you still might use the NuGet package ThriveGmbH.BottomNavigationBar.XF, you will still have this issue. To solve it you have to remove this NuGet package from all of your projects and use the Xamarin.Forms toolbar placement for Android which was introduced with Xamarin.Forms 3.1.

Solution:
Reference 1: https://blog.xamarin.com/xamarin-forms-3-1-improvments/#androidbottomtabs
Reference 2: https://montemagno.com/xamarin-forms-official-bottom-navigation-bottom-tabs-on-android/

It was less than 10 lines of code which I had to change to make it work.

Was this page helpful?
0 / 5 - 0 ratings