diff --git a/src/Compatibility/Core/src/Android/AppCompat/FlyoutPageContainer.cs b/src/Compatibility/Core/src/Android/AppCompat/FlyoutPageContainer.cs
index 3f78667948e4..d1ae9d6c44e0 100644
--- a/src/Compatibility/Core/src/Android/AppCompat/FlyoutPageContainer.cs
+++ b/src/Compatibility/Core/src/Android/AppCompat/FlyoutPageContainer.cs
@@ -222,7 +222,7 @@ protected override void Dispose(bool disposing)
if (disposing)
{
- if (_currentFragment != null && !FragmentManager.IsDestroyed)
+ if (_currentFragment != null && !FragmentManager.IsDestroyed(Context))
{
FragmentTransaction transaction = FragmentManager.BeginTransactionEx();
transaction.RemoveEx(_currentFragment);
diff --git a/src/Compatibility/Core/src/Android/AppCompat/FormsFragmentPagerAdapter.cs b/src/Compatibility/Core/src/Android/AppCompat/FormsFragmentPagerAdapter.cs
index 965aaed98ef5..992b18c70a8c 100644
--- a/src/Compatibility/Core/src/Android/AppCompat/FormsFragmentPagerAdapter.cs
+++ b/src/Compatibility/Core/src/Android/AppCompat/FormsFragmentPagerAdapter.cs
@@ -84,7 +84,7 @@ protected override void Dispose(bool disposing)
_page = null;
- if (!_fragmentManager.IsDestroyed)
+ if (!_fragmentManager.IsDestroyed(_page?.Handler?.MauiContext?.Context))
{
FragmentTransaction transaction = _fragmentManager.BeginTransactionEx();
diff --git a/src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageGallery.xaml b/src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageGallery.xaml
index 0ec45a7e3e32..fb03f1294eca 100644
--- a/src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageGallery.xaml
+++ b/src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageGallery.xaml
@@ -3,16 +3,9 @@
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Pages.TabbedPageGallery"
+ xmlns:views="clr-namespace:Maui.Controls.Sample.Pages"
Title="Tabbed Page">
-
-
-
-
-
-
-
-
-
-
-
+
+
+
\ No newline at end of file
diff --git a/src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageGallery.xaml.cs b/src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageGallery.xaml.cs
index 61b189504f44..53d7807573e1 100644
--- a/src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageGallery.xaml.cs
+++ b/src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageGallery.xaml.cs
@@ -14,77 +14,5 @@ public TabbedPageGallery()
this.Children.Add(new NavigationGallery());
this.Children.Add(new NavigationPage(new NavigationGallery()) { Title = "With Nav Page" });
}
-
- void OnTabbedPageAsRoot(object sender, EventArgs e)
- {
- var topTabs =
- new TabbedPage()
- {
- Children =
- {
- Handler.MauiContext.Services.GetRequiredService(),
- new NavigationPage(new Pages.NavigationGallery()) { Title = "Navigation Gallery" }
- }
- };
-
- this.Handler?.DisconnectHandler();
- Application.Current.MainPage?.Handler?.DisconnectHandler();
- Application.Current.MainPage = topTabs;
- }
-
- void OnSetToBottomTabs(object sender, EventArgs e)
- {
- var bottomTabs = new TabbedPage()
- {
- Children =
- {
- Handler.MauiContext.Services.GetRequiredService(),
- new NavigationPage(new Pages.NavigationGallery()) { Title = "Navigation Gallery" }
- }
- };
-
- this.Handler?.DisconnectHandler();
- Application.Current.MainPage?.Handler?.DisconnectHandler();
-
- AndroidSpecific.TabbedPage.SetToolbarPlacement(bottomTabs, AndroidSpecific.ToolbarPlacement.Bottom);
- Application.Current.MainPage = bottomTabs;
- }
-
- void OnChangeTabIndex(object sender, EventArgs e)
- {
- CurrentPage = Children[1];
- }
-
- void OnToggleTabBar(object sender, EventArgs e)
- {
- if ((this.BarBackground as SolidColorBrush)?.Color == SolidColorBrush.Purple.Color)
- this.BarBackground = null;
- else
- this.BarBackground = SolidColorBrush.Purple;
- }
-
- void OnToggleTabBarTextColor(object sender, EventArgs e)
- {
- if (this.BarTextColor == Colors.Green)
- this.BarTextColor = null;
- else
- this.BarTextColor = Colors.Green;
- }
-
- void OnToggleTabItemUnSelectedColor(object sender, EventArgs e)
- {
- if (this.UnselectedTabColor == Colors.Blue)
- this.UnselectedTabColor = null;
- else
- this.UnselectedTabColor = Colors.Blue;
- }
-
- void OnToggleTabItemSelectedColor(object sender, EventArgs e)
- {
- if (this.SelectedTabColor == Colors.Pink)
- this.SelectedTabColor = null;
- else
- this.SelectedTabColor = Colors.Pink;
- }
}
}
\ No newline at end of file
diff --git a/src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageGalleryMainPage.xaml b/src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageGalleryMainPage.xaml
new file mode 100644
index 000000000000..ffc91f8dd240
--- /dev/null
+++ b/src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageGalleryMainPage.xaml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageGalleryMainPage.xaml.cs b/src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageGalleryMainPage.xaml.cs
new file mode 100644
index 000000000000..4ef4abb0b0b4
--- /dev/null
+++ b/src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageGalleryMainPage.xaml.cs
@@ -0,0 +1,116 @@
+using System;
+using System.Linq;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Maui.Controls;
+using Microsoft.Maui.Graphics;
+using AndroidSpecific = Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;
+
+namespace Maui.Controls.Sample.Pages
+{
+ public partial class TabbedPageGalleryMainPage
+ {
+ public TabbedPageGalleryMainPage()
+ {
+ InitializeComponent();
+ }
+
+ TabbedPage _tabbedPage;
+ TabbedPage GetTabbedPage() => _tabbedPage ??= (TabbedPage)Parent;
+
+ void SetNewMainPage(Page page)
+ {
+ Application.Current.Windows[0].Page = page;
+ }
+
+ void OnTabbedPageAsRoot(object sender, EventArgs e)
+ {
+ var topTabs =
+ new TabbedPage()
+ {
+ Children =
+ {
+ Handler.MauiContext.Services.GetRequiredService(),
+ new NavigationPage(new Pages.NavigationGallery()) { Title = "Navigation Gallery" }
+ }
+ };
+
+ SetNewMainPage(topTabs);
+ }
+
+ void OnSetToBottomTabs(object sender, EventArgs e)
+ {
+ var bottomTabs = new TabbedPage()
+ {
+ Children =
+ {
+ Handler.MauiContext.Services.GetRequiredService(),
+ new NavigationPage(new Pages.NavigationGallery()) { Title = "Navigation Gallery" }
+ }
+ };
+
+ SetNewMainPage(bottomTabs);
+ AndroidSpecific.TabbedPage.SetToolbarPlacement(bottomTabs, AndroidSpecific.ToolbarPlacement.Bottom);
+ Application.Current.MainPage = bottomTabs;
+ }
+
+ void OnChangeTabIndex(object sender, EventArgs e)
+ {
+ GetTabbedPage().CurrentPage = GetTabbedPage().Children[1];
+ }
+
+ void OnToggleTabBar(object sender, EventArgs e)
+ {
+ if ((GetTabbedPage().BarBackground as SolidColorBrush)?.Color == SolidColorBrush.Purple.Color)
+ GetTabbedPage().BarBackground = null;
+ else
+ GetTabbedPage().BarBackground = SolidColorBrush.Purple;
+ }
+
+ void OnToggleTabBarTextColor(object sender, EventArgs e)
+ {
+ if (GetTabbedPage().BarTextColor == Colors.Green)
+ GetTabbedPage().BarTextColor = null;
+ else
+ GetTabbedPage().BarTextColor = Colors.Green;
+ }
+
+ void OnToggleTabItemUnSelectedColor(object sender, EventArgs e)
+ {
+ if (GetTabbedPage().UnselectedTabColor == Colors.Blue)
+ GetTabbedPage().UnselectedTabColor = null;
+ else
+ GetTabbedPage().UnselectedTabColor = Colors.Blue;
+ }
+
+ void OnToggleTabItemSelectedColor(object sender, EventArgs e)
+ {
+ if (GetTabbedPage().SelectedTabColor == Colors.Pink)
+ GetTabbedPage().SelectedTabColor = null;
+ else
+ GetTabbedPage().SelectedTabColor = Colors.Pink;
+ }
+
+ void OnRemoveTab(object sender, EventArgs e)
+ {
+ if (GetTabbedPage().Children.LastOrDefault() is TabbedPageGalleryMainPage mainPage)
+ {
+ GetTabbedPage().Children.Remove(mainPage);
+ }
+ }
+
+ void OnRemoveAllTabs(object sender, EventArgs e)
+ {
+ while (GetTabbedPage().Children.LastOrDefault() is TabbedPageGalleryMainPage mainPage)
+ {
+ GetTabbedPage().Children.Remove(mainPage);
+ }
+ }
+
+ void OnAddTab(object sender, EventArgs e)
+ {
+ GetTabbedPage()
+ .Children
+ .Add(new TabbedPageGalleryMainPage() { Title = $"Tab {GetTabbedPage().Children.Count}" });
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFragmentContainer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFragmentContainer.cs
index 8907188e6015..e766431077d0 100644
--- a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFragmentContainer.cs
+++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFragmentContainer.cs
@@ -23,32 +23,9 @@ public ShellFragmentContainer(ShellContent shellContent, IMauiContext mauiContex
public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
_page = ((IShellContentController)ShellContentTab).GetOrCreateContent();
+ _page.ToPlatform(_mauiContext, RequireContext(), inflater, ChildFragmentManager);
- IMauiContext mauiContext = null;
-
- // If the page has already been created with a handler then we just let it retain the same
- // Handler and MauiContext
- // But we want to update the inflater and ChildFragmentManager to match
- // the handlers new home
- if (_page.Handler?.MauiContext is MauiContext scopedMauiContext)
- {
- // If this page comes to us from a different activity then don't reuse it
- // disconnect the handler so it can recreate against new MauiContext
- if (scopedMauiContext.GetActivity() == Context.GetActivity())
- {
- scopedMauiContext.AddWeakSpecific(ChildFragmentManager);
- scopedMauiContext.AddWeakSpecific(inflater);
- mauiContext = scopedMauiContext;
- }
- else
- {
- _page.Handler.DisconnectHandler();
- }
- }
-
- mauiContext ??= _mauiContext.MakeScoped(layoutInflater: inflater, fragmentManager: ChildFragmentManager);
-
- return new ShellPageContainer(RequireContext(), (IPlatformViewHandler)_page.ToHandler(mauiContext), true)
+ return new ShellPageContainer(RequireContext(), (IPlatformViewHandler)_page.Handler, true)
{
LayoutParameters = new LP(LP.MatchParent, LP.MatchParent)
};
diff --git a/src/Controls/src/Core/HandlerImpl/NavigationPage/NavigationPage.Impl.cs b/src/Controls/src/Core/HandlerImpl/NavigationPage/NavigationPage.Impl.cs
index d0c45a7b042d..6b92d1609f61 100644
--- a/src/Controls/src/Core/HandlerImpl/NavigationPage/NavigationPage.Impl.cs
+++ b/src/Controls/src/Core/HandlerImpl/NavigationPage/NavigationPage.Impl.cs
@@ -181,32 +181,36 @@ async Task SendHandlerUpdateAsync(
// Wait for pending navigation tasks to finish
await SemaphoreSlim.WaitAsync();
- var currentNavRequestTaskSource = new TaskCompletionSource