Skip to content

Commit

Permalink
Merge pull request #18677 from ajpinedam/fix/tabview.droid.header
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund authored Nov 15, 2024
2 parents 3e576c0 + d1ca282 commit ce498ef
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,12 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<!-- Uno workaround: On Android, the Height of ContentPresenters inside this Grid is not bing calculated correctly -->
<!-- It can be removed once this PR is merged: https://github.com/unoplatform/uno/pull/18261 -->
<android:Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</android:Grid.RowDefinitions>

<Viewbox x:Name="IconBox"
MaxWidth="{ThemeResource TabViewItemHeaderIconSize}"
MaxHeight="{ThemeResource TabViewItemHeaderIconSize}"
Expand Down
5 changes: 5 additions & 0 deletions src/Uno.UI.FluentTheme.v2/themeresources_v2.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22960,6 +22960,11 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- Uno workaround: On Android, the Height of ContentPresenters inside this Grid is not bing calculated correctly -->
<!-- It can be removed once this PR is merged: https://github.com/unoplatform/uno/pull/18261 -->
<android:Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</android:Grid.RowDefinitions>
<Viewbox x:Name="IconBox" MaxWidth="{ThemeResource TabViewItemHeaderIconSize}" MaxHeight="{ThemeResource TabViewItemHeaderIconSize}" Margin="{ThemeResource TabViewItemHeaderIconMargin}">
<ContentControl x:Name="IconControl" Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TabViewTemplateSettings.IconElement}" IsTabStop="False" Foreground="{ThemeResource TabViewItemIconForeground}" HighContrastAdjustment="None" />
</Viewbox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
using static Uno.UI.Extensions.ViewExtensions;
using static Private.Infrastructure.TestServices;

#if __IOS__
using UIKit;
#elif __MACOS__
using AppKit;
#endif

namespace Uno.UI.RuntimeTests.Tests.Microsoft_UI_Xaml_Controls;

[TestClass]
Expand Down Expand Up @@ -155,6 +161,45 @@ public async Task When_DataBinding()
Assert.AreEqual(0, SUT.SelectedIndex);
}

#if !WINAPPSDK // GetTemplateChild is protected in UWP while public in Uno.
[TestMethod]
public async Task When_Items_Should_ShowHeader()
{
var SUT = new TabView
{
TabItems =
{
new TabViewItem { Header = "Tab 1" },
new TabViewItem { Header = "Tab 2" }
}
};

await UITestHelper.Load(SUT);

var tabviewItem1 = SUT.ContainerFromIndex(0) as TabViewItem;
var headerPresenter1 = (ContentPresenter)tabviewItem1.GetTemplateChild("ContentPresenter");
Assert.IsTrue(headerPresenter1.ActualWidth > 0, "TabViewItem header for index 0 should have a non-zero width.");
Assert.IsTrue(headerPresenter1.ActualHeight > 0, "TabViewItem header for index 0 should have a non-zero height.");

var closeButton1 = (Button)tabviewItem1.GetTemplateChild("CloseButton");

var buttonLabel1 =
#if __IOS__ || __MACOS__
closeButton1.FindFirstChild<ImplicitTextBlock>();
#else
((ContentPresenter)closeButton1.GetTemplateChild("ContentPresenter")).FindFirstChild<ImplicitTextBlock>();
#endif

Assert.IsTrue(buttonLabel1.ActualWidth > 0, "TabViewItem Button for index 0 should have a non-zero width.");
Assert.IsTrue(buttonLabel1.ActualHeight > 0, "TabViewItem Button for index 0 should have a non-zero height.");

var tabviewItem2 = SUT.ContainerFromIndex(1) as TabViewItem;
var headerPresenter2 = (ContentPresenter)tabviewItem2.GetTemplateChild("ContentPresenter");
Assert.IsTrue(headerPresenter2.ActualWidth > 0, "TabViewItem header for index 1 should have a non-zero width.");
Assert.IsTrue(headerPresenter2.ActualHeight > 0, "TabViewItem header for index 1 should have a non-zero height.");
}
#endif

[TestMethod]
public async Task When_SelectedItem_Changed_Binding()
{
Expand Down

0 comments on commit ce498ef

Please sign in to comment.