-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve some life cycle issues with
TabbedPage
when nested inside a…
… `NavigationPage` (#11530) * Fix fragment manager life cycle with TabbbedPage * - add additional tests * - add more tests and fix a couple more found issues * - remove testing code * - fix up tabbedpage gallery * - fix up tests * - fix up fragment management * - cleanup * - add additional tests * - add delay * Update StackNavigationManager.cs * Update TabbedPageTests.cs * Update ControlsHandlerTestBase.cs * - remove disable nullable * - add comment fix traversal * - cleanup Destory checking code and add gallery tests * - cleanup handling of adapter key * - comment out ios * - fix scenarios where navpage gets disconnected mid navigation * Update MultiPageFragmentStateAdapter.cs
- Loading branch information
Showing
33 changed files
with
1,091 additions
and
353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageGalleryMainPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage Title="Tab 1" | ||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Maui.Controls.Sample.Pages.TabbedPageGalleryMainPage"> | ||
<ScrollView> | ||
<VerticalStackLayout> | ||
<Button Text="Set Tabbed Page as Root" Clicked="OnTabbedPageAsRoot"></Button> | ||
<Button Text="Toggle Bottom Tabs (Android)" Clicked="OnSetToBottomTabs"></Button> | ||
<Button Text="Change Tab Index" Clicked="OnChangeTabIndex"></Button> | ||
<Button Text="Toggle TabBar Background Color" Clicked="OnToggleTabBar"></Button> | ||
<Button Text="Toggle TabBar Text Color" Clicked="OnToggleTabBarTextColor"></Button> | ||
<Button Text="Toggle Tab Item Selected" Clicked="OnToggleTabItemSelectedColor"></Button> | ||
<Button Text="Toggle Tab Item UnselectedColor" Clicked="OnToggleTabItemUnSelectedColor"></Button> | ||
<Button Text="Add Tab" Clicked="OnAddTab"></Button> | ||
<Button Text="Remove Tab" Clicked="OnRemoveTab"></Button> | ||
<Button Text="Remove All New Tabs" Clicked="OnRemoveAllTabs"></Button> | ||
</VerticalStackLayout> | ||
</ScrollView> | ||
</ContentPage> |
116 changes: 116 additions & 0 deletions
116
src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageGalleryMainPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Page>(), | ||
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<Page>(), | ||
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}" }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.