-
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.
- make bottom tab smarter when removing/adding items
- Loading branch information
Showing
4 changed files
with
253 additions
and
41 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
71 changes: 71 additions & 0 deletions
71
src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Android.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,71 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using AndroidX.CoordinatorLayout.Widget; | ||
using Google.Android.Material.BottomNavigation; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Handlers; | ||
using Microsoft.Maui.Platform; | ||
using Xunit; | ||
|
||
namespace Microsoft.Maui.DeviceTests | ||
{ | ||
[Category(TestCategory.TabbedPage)] | ||
public partial class TabbedPageTests : ControlsHandlerTestBase | ||
{ | ||
[Fact] | ||
public async Task ChangingBottomTabAttributesDoesntRecreateBottomTabs() | ||
{ | ||
SetupBuilder(); | ||
|
||
var tabbedPage = CreateBasicTabbedPage(true, pages: new[] | ||
{ | ||
new ContentPage() { Title = "Tab 1", IconImageSource = "red.png" }, | ||
new ContentPage() { Title = "Tab 2", IconImageSource = "red.png" } | ||
}); | ||
|
||
await CreateHandlerAndAddToWindow<TabbedViewHandler>(tabbedPage, async (handler) => | ||
{ | ||
var menu = GetBottomNavigationView(handler).Menu; | ||
var menuItem1 = menu.GetItem(0); | ||
var menuItem2 = menu.GetItem(1); | ||
var icon1 = menuItem1.Icon; | ||
var icon2 = menuItem2.Icon; | ||
var title1 = menuItem1.TitleFormatted; | ||
var title2 = menuItem2.TitleFormatted; | ||
|
||
tabbedPage.Children[0].Title = "new Title 1"; | ||
tabbedPage.Children[0].IconImageSource = "blue.png"; | ||
|
||
tabbedPage.Children[1].Title = "new Title 2"; | ||
tabbedPage.Children[1].IconImageSource = "blue.png"; | ||
|
||
// let the icon and title propagate | ||
await AssertionExtensions.Wait(() => menuItem1.Icon != icon1); | ||
|
||
menu = GetBottomNavigationView(handler).Menu; | ||
Assert.Equal(menuItem1, menu.GetItem(0)); | ||
Assert.Equal(menuItem2, menu.GetItem(1)); | ||
|
||
menuItem1.Icon.AssertColorAtCenter(Android.Graphics.Color.Blue); | ||
menuItem2.Icon.AssertColorAtCenter(Android.Graphics.Color.Blue); | ||
|
||
Assert.NotEqual(icon1, menuItem1.Icon); | ||
Assert.NotEqual(icon2, menuItem2.Icon); | ||
Assert.NotEqual(title1, menuItem1.TitleFormatted); | ||
Assert.NotEqual(title2, menuItem2.TitleFormatted); | ||
}); | ||
} | ||
|
||
|
||
BottomNavigationView GetBottomNavigationView(TabbedViewHandler tabViewHandler) | ||
{ | ||
var layout = (tabViewHandler.PlatformView as Android.Views.IViewParent).FindParent((view) => view is CoordinatorLayout) | ||
as CoordinatorLayout; | ||
|
||
return layout.GetFirstChildOfType<BottomNavigationView>(); | ||
} | ||
} | ||
} |