Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Android/Forms Tabpage OnDisappearing firing minimized #1438

Closed
davidortinau opened this issue Dec 20, 2017 · 14 comments
Closed

Android/Forms Tabpage OnDisappearing firing minimized #1438

davidortinau opened this issue Dec 20, 2017 · 14 comments

Comments

@davidortinau
Copy link
Contributor

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

@brux88
Copy link

brux88 commented Dec 20, 2017

how i can fix this behavior?

@edecision-plaroche
Copy link

edecision-plaroche commented Dec 21, 2017

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

@nbsoftware
Copy link

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?

@ghost
Copy link

ghost commented Jan 1, 2018

This is happening for me too.

@rmarinho rmarinho self-assigned this Jan 9, 2018
@rmarinho
Copy link
Member

@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

@nbsoftware
Copy link

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

@ghost
Copy link

ghost commented Jan 10, 2018

@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.

@xMRi
Copy link

xMRi commented Jan 17, 2018

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

jsuarezruiz added a commit to XamarinFormsCommunity/Xamarin.Forms that referenced this issue Feb 28, 2018
* 'master' of https://github.com/xamarin/Xamarin.Forms: (23 commits)
  [C] use direct cast
  [Core, iOS, Android, UWP, WPF] Hide scroll view scroll bars (xamarin#1910)
  Allow users to specify resolution method for handlers, effects, and services (xamarin#1870) fixes xamarin#1739
  [Build] Update submodule
  Capitalization keyboard flag additions for Entry/Editor (xamarin#1683) (xamarin#1833)
  [Build] Don't specify .net sdk version
  Simplify event raising invocation pattern (xamarin#1971)
  [iOS Maps] Pin rendering customization (xamarin#1065)
  set csharp_space_after_keywords_in_control_flow_statements to true to fit our design guide lines (xamarin#1964)
  [iOS] Add shadow effect (xamarin#1896)
  Added support for ListView full width separators on iOS (xamarin#1854) fixes xamarin#1665
  Support CascadeInputTransparent to Tizen (xamarin#1916)
  [Android]?Remove UserVisibleHint (xamarin#1550) fixes xamarin#1438
  [iOS] ViewDidLayoutSubviews after removing page (xamarin#1532) fixes xamarin#1426
  Use relative URL to support recursive checkout in VSTS (xamarin#1926)
  [UITest] Fix test for UITest package update (xamarin#1923)
  Implemented MaxLength property on Entry and Editor (xamarin#1880)
  [Build]Fix master and build (xamarin#1920)
  [Build] Fix windows cert
  Fix to absolute URL
  ...

# Conflicts:
#	Xamarin.Forms.Controls/CoreGalleryPages/EditorCoreGalleryPage.cs
#	Xamarin.Forms.Controls/CoreGalleryPages/EntryCoreGalleryPage.cs
#	Xamarin.Forms.Core/InputView.cs
#	Xamarin.Forms.CustomAttributes/TestAttributes.cs
#	Xamarin.Forms.Platform.Android/Renderers/EditorRenderer.cs
#	Xamarin.Forms.Platform.Android/Renderers/EntryRenderer.cs
#	Xamarin.Forms.Platform.MacOS/Renderers/EditorRenderer.cs
#	Xamarin.Forms.Platform.MacOS/Renderers/EntryRenderer.cs
#	Xamarin.Forms.Platform.Tizen/Renderers/EditorRenderer.cs
#	Xamarin.Forms.Platform.Tizen/Renderers/EntryRenderer.cs
#	Xamarin.Forms.Platform.WPF/Renderers/EditorRenderer.cs
#	Xamarin.Forms.Platform.WPF/Renderers/EntryRenderer.cs
#	Xamarin.Forms.Platform.iOS/Renderers/EditorRenderer.cs
#	Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs
@vhugogarcia
Copy link

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.

@LeoJHarris
Copy link

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".

@nbsoftware
Copy link

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.

@davidortinau
Copy link
Contributor Author

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.

@nbsoftware
Copy link

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

@joshardt
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants