Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Use InfoBadge for TabBarItem badge support #1142

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sample="using:Uno.Toolkit.Samples"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:utu="using:Uno.Toolkit.UI"
mc:Ignorable="d">

Expand Down Expand Up @@ -47,11 +48,18 @@
<utu:TabBarItem.Icon>
<FontIcon Glyph="&#xE8F2;" />
</utu:TabBarItem.Icon>
<utu:TabBarItem.InfoBadge>
<muxc:InfoBadge Style="{StaticResource MaterialSmallInfoBadgeBottomTabBarItemStyle}" />
</utu:TabBarItem.InfoBadge>
</utu:TabBarItem>
<utu:TabBarItem Content="ABOUT">
<utu:TabBarItem.Icon>
<FontIcon Glyph="&#xE946;" />
</utu:TabBarItem.Icon>
<utu:TabBarItem.InfoBadge>
<muxc:InfoBadge Value="42"
Style="{StaticResource MaterialLargeInfoBadgeBottomTabBarItemStyle}" />
</utu:TabBarItem.InfoBadge>
</utu:TabBarItem>

</utu:TabBar.Items>
Expand Down
11 changes: 11 additions & 0 deletions src/Uno.Toolkit.UI/Controls/TabBar/TabBarItem.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ public string? BadgeValue
DependencyProperty.Register("BadgeValue", typeof(string), typeof(TabBarItem), new PropertyMetadata(default(string?), OnPropertyChanged));
#endregion

#region InfoBadge
MartinZikmund marked this conversation as resolved.
Show resolved Hide resolved
morning4coffe-dev marked this conversation as resolved.
Show resolved Hide resolved
public Control InfoBadge
{
get => (Control)GetValue(InfoBadgeProperty);
set => SetValue(InfoBadgeProperty, value);
}

public static readonly DependencyProperty InfoBadgeProperty =
DependencyProperty.Register(nameof(InfoBadge), typeof(Control), typeof(TabBarItem), new PropertyMetadata(null, OnPropertyChanged));
morning4coffe-dev marked this conversation as resolved.
Show resolved Hide resolved
#endregion

#region IsSelectable
public bool IsSelectable
{
Expand Down
72 changes: 72 additions & 0 deletions src/library/Uno.Toolkit.Material/Styles/Controls/v2/InfoBadge.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d">

<!-- InfoBadge BottomTabBarItem Resources and Styles -->

<!-- Common -->
<StaticResource x:Key="MaterialInfoBadgeBottomTabBarItemBackground"
ResourceKey="ErrorBrush" />
<StaticResource x:Key="MaterialInfoBadgeBottomTabBarItemForeground"
ResourceKey="OnErrorBrush" />

<!-- Small InfoBadge-->
<x:Double x:Key="MaterialSmallInfoBadgeBottomTabBarItemHeight">6</x:Double>
<x:Double x:Key="MaterialSmallInfoBadgeBottomTabBarItemWidth">6</x:Double>
<Thickness x:Key="MaterialSmallInfoBadgeBottomTabBarItemMargin">0,4,20,0</Thickness>


<!-- Large InfoBadge-->
<x:Double x:Key="MaterialLargeInfoBadgeBottomTabBarItemHeight">16</x:Double>
<Thickness x:Key="MaterialLargeInfoBadgeBottomTabBarItemMargin">32,4,0,0</Thickness>
<CornerRadius x:Key="MaterialLargeInfoBadgeBottomTabBarItemCornerRadius">8</CornerRadius>
Comment on lines +11 to +25
Copy link
Contributor

Choose a reason for hiding this comment

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

These need to be inside of ThemeDictionaries to be able to be overridden via lightweight styling


<Style x:Key="MaterialSmallInfoBadgeBottomTabBarItemStyle"
TargetType="muxc:InfoBadge">
<Setter Property="Background"
Value="{ThemeResource MaterialInfoBadgeBottomTabBarItemBackground}" />
<Setter Property="HorizontalAlignment"
Value="Right" />
<Setter Property="VerticalAlignment"
Value="Top" />
<Setter Property="Height"
Value="{ThemeResource MaterialSmallInfoBadgeBottomTabBarItemHeight}" />
<Setter Property="Width"
Value="{ThemeResource MaterialSmallInfoBadgeBottomTabBarItemWidth}" />
<Setter Property="Margin"
Value="{ThemeResource MaterialSmallInfoBadgeBottomTabBarItemMargin}" />
</Style>

<Style x:Key="MaterialLargeInfoBadgeBottomTabBarItemStyle"
TargetType="muxc:InfoBadge">
<Setter Property="Background"
Value="{ThemeResource MaterialInfoBadgeBottomTabBarItemBackground}" />
<Setter Property="Foreground"
Value="{ThemeResource MaterialInfoBadgeBottomTabBarItemForeground}" />
<Setter Property="HorizontalAlignment"
Value="Left" />
<Setter Property="VerticalAlignment"
Value="Top" />
<Setter Property="VerticalContentAlignment"
Value="Center" />
<Setter Property="Height"
Value="{ThemeResource MaterialLargeInfoBadgeBottomTabBarItemHeight}" />
<Setter Property="Margin"
Value="{ThemeResource MaterialLargeInfoBadgeBottomTabBarItemMargin}" />
<Setter Property="CornerRadius"
Value="{ThemeResource MaterialLargeInfoBadgeBottomTabBarItemCornerRadius}" />
<!-- Label ExtraSmall -->
<Setter Property="FontFamily"
Value="{StaticResource MaterialLabelSmallFontFamily}" />
<Setter Property="FontWeight"
Value="{StaticResource MaterialLabelSmallFontWeight}" />
<Setter Property="FontSize"
Value="{StaticResource MaterialLabelSmallFontSize}" />
<Setter Property="CharacterSpacing"
Value="{StaticResource MaterialLabelSmallCharacterSpacing}" />
</Style>

</ResourceDictionary>
40 changes: 6 additions & 34 deletions src/library/Uno.Toolkit.Material/Styles/Controls/v2/TabBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -702,40 +702,12 @@
<!-- See this commit for the implementation: c935919b2c390014dd8509cc50e16b1549511ffa -->
<!-- (Related Branch: dev/agzi/I274-InfoBadgeImplementationForTBI) -->

<Grid Visibility="{TemplateBinding BadgeVisibility}">
<!-- Small Badge -->
<Ellipse
Width="{ThemeResource NavigationTabBarItemSmallBadgeWidth}"
Height="{ThemeResource NavigationTabBarItemSmallBadgeHeight}"
Margin="{ThemeResource NavigationTabBarItemSmallBadgeMargin}"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Fill="{ThemeResource NavigationTabBarItemErrorBrush}"
Visibility="{Binding BadgeValue, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource EmptyOrNullToVisibleConverter}}" />

<!-- Large Badge -->
<Border
Height="{ThemeResource NavigationTabBarItemLargeBadgeHeight}"
MinWidth="{ThemeResource NavigationTabBarItemLargeBadgeMinWidth}"
Margin="{ThemeResource NavigationTabBarItemLargeBadgeMargin}"
Padding="{ThemeResource NavigationTabBarItemLargeBadgePadding}"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Background="{ThemeResource NavigationTabBarItemErrorBrush}"
CornerRadius="{ThemeResource NavigationTabBarItemLargeBadgeCornerRadius}"
Visibility="{Binding BadgeValue, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource EmptyOrNullToCollapsedConverter}}">
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="{ThemeResource NavigationTabBarItemOnErrorBrush}"
MaxLines="1"
Style="{StaticResource LabelExtraSmall}"
Text="{TemplateBinding BadgeValue}"
TextAlignment="Center" />
</Border>
</Grid>

</Grid>
<!-- InfoBadge Presenter -->
<ContentPresenter x:Name="InfoBadgePresenter"
Content="{TemplateBinding InfoBadge}"
Visibility="{Binding InfoBadge, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource MaterialEmptyOrNullToCollapsed}}" />

</Grid>

<ContentPresenter
x:Name="ContentPresenter"
Expand Down
Loading