Skip to content

Tabs on TabbedPage gone after popping Modal in background - fix - #30452

Closed
kubaflo wants to merge 1 commit into
dotnet:mainfrom
kubaflo:fix-22444
Closed

kubaflo wants to merge 1 commit into
dotnet:mainfrom
kubaflo:fix-22444

Conversation

@kubaflo

@kubaflo kubaflo commented Jul 6, 2025 •

Copy link
Copy Markdown
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

This is an extension of PR #19532

Issues Fixed

Fixes #22444

Before After
Screen.Recording.2025-07-06.at.19.58.02.mov
Screen.Recording.2025-07-06.at.19.56.43.mov
public partial class MainPage : TabbedPage
{
	public MainPage()
	{
		Children.Add(new ContentPage
		{
			Title = "Tab 1",
			Content = new StackLayout
			{
				Children =
			{
				new Button
				{
					Text = "Open Modal Page",
					Command = new Command(() => {
						Navigation.PushModalAsync(new ContentPage
						{
							Title = "Modal Page",
							Content = new StackLayout
							{
								Children =
								{
									new Label { Text = "This is a modal page." },
									new Button
									{
										Text = "Close",
										Command = new Command(async() =>
										{
											await Task.Delay(2000);
											await Navigation.PopModalAsync();
										})
									}
								}
							}
						});
					})
				}
			}
			}
		});

		Children.Add(new ContentPage { Title = "Tab 2" });
	}
}

Copilot AI review requested due to automatic review settings July 6, 2025 18:02
@kubaflo
kubaflo requested a review from a team as a code owner July 6, 2025 18:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures that when a fragment is destroyed, the stored resume callback is invoked after disconnecting, restoring any necessary UI state (e.g., tabs on a TabbedPage).

  • Cache and invoke the _onResume callback after OnFragmentDestroyed
  • Ensures tabs reappear when a modal is popped in the background
Comments suppressed due to low confidence (2)

src/Core/src/Platform/Android/FragmentManagerExtensions.cs:121

  • [nitpick] The variable name resume is a bit generic. Consider renaming it to resumeCallback or similar to clarify its purpose.
				var resume = _onResume;

src/Core/src/Platform/Android/FragmentManagerExtensions.cs:123

  • Add automated tests in both TestCases.HostApp and TestCases.Shared.Tests to verify that the _onResume callback is invoked and that tabs are correctly restored when a modal is popped.
				resume?.Invoke(fm);

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@kubaflo! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@jsuarezruiz jsuarezruiz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you include a related Test?
In an UITest can move the App to background using App.BackgroundApp(); and restore it to foreground using App.ForegroundApp();

@pictos

pictos commented Jul 7, 2025

Copy link
Copy Markdown
Contributor

I believe #30290 already fixes this and also fixes the issue related with tabs being removed during modal navigations

@kubaflo

kubaflo commented Jul 7, 2025

Copy link
Copy Markdown
Contributor Author

I believe #30290 already fixes this and also fixes the issue related with tabs being removed during modal navigations

@pictos @PureWeen yeah it does, but in a different way. IDK which one is better, though.

@PureWeen

Copy link
Copy Markdown
Member

Closing this PR in favor of #30290

Calling code that expects to run during resume from ondestroy feels risky

If this is an approach we want to where code will run regardless if the fragment is destroyed or not then we should probably add an additional overload for the method that takes an action like "RunOnResumeOrDestroy"

@PureWeen PureWeen closed this Jul 25, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 25, 2025
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.

Tabs on TabbedPage gone after popping Modal in background

5 participants