-
Notifications
You must be signed in to change notification settings - Fork 29
chore: Use InfoBadge for TabBarItem badge support #1142
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
fbdfb56
f6636f4
c70012a
a7b9e3b
1f472f0
45eb8bc
849d233
c857c1a
cf18db6
6e6e74c
d030058
c83ea0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Windows.Input; | ||
using MUXC = Microsoft.UI.Xaml.Controls; | ||
|
||
#if IS_WINUI | ||
using Microsoft.UI.Xaml; | ||
|
@@ -29,26 +28,64 @@ public IconElement? Icon | |
DependencyProperty.Register(nameof(Icon), typeof(IconElement), typeof(TabBarItem), new PropertyMetadata(null, OnPropertyChanged)); | ||
#endregion | ||
|
||
// UNO TODO: Deprecate and remove BadgeVisibility and BadgeValue properties and use InfoBadge instead | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have an issue to track in Toolkit to do this for the next major version bump? Do we have docs written in the migration section for this deprecation or recommendation to use InfoBadge explicitly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @kazo0, I will take a look 👍 |
||
#region BadgeVisibility | ||
morning4coffe-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[Obsolete("This property is deprecated. Use InfoBadge instead.", false)] | ||
public Visibility BadgeVisibility | ||
{ | ||
get { return (Visibility)GetValue(BadgeVisibilityProperty); } | ||
set { SetValue(BadgeVisibilityProperty, value); } | ||
get => InfoBadge?.Visibility ?? (Visibility)GetValue(BadgeVisibilityProperty); | ||
set | ||
{ | ||
SetValue(BadgeVisibilityProperty, value); | ||
|
||
InfoBadge ??= new MUXC.InfoBadge(); | ||
InfoBadge.Visibility = value; | ||
} | ||
} | ||
|
||
[Obsolete("This property is deprecated. Use InfoBadge instead.", false)] | ||
public static readonly DependencyProperty BadgeVisibilityProperty = | ||
DependencyProperty.Register("BadgeVisibility", typeof(Visibility), typeof(TabBarItem), new PropertyMetadata(Visibility.Collapsed, OnPropertyChanged)); | ||
DependencyProperty.Register(nameof(BadgeVisibility), typeof(Visibility), typeof(TabBarItem), new PropertyMetadata(Visibility.Collapsed, OnPropertyChanged)); | ||
#endregion | ||
|
||
#region BadgeValue | ||
[Obsolete("This property is deprecated. Use InfoBadge instead.", false)] | ||
public string? BadgeValue | ||
{ | ||
get { return (string)GetValue(BadgeValueProperty); } | ||
set { SetValue(BadgeValueProperty, value); } | ||
get => (InfoBadge as MUXC.InfoBadge)?.Value.ToString() ?? (string)GetValue(BadgeValueProperty); | ||
set | ||
{ | ||
SetValue(BadgeValueProperty, value); | ||
|
||
InfoBadge ??= new MUXC.InfoBadge(); | ||
|
||
if (InfoBadge is MUXC.InfoBadge infoBadge) | ||
{ | ||
if (int.TryParse(value, out int intValue)) | ||
{ | ||
infoBadge.Value = intValue; | ||
} | ||
else | ||
{ | ||
infoBadge.IconSource = new MUXC.FontIconSource { Glyph = value }; | ||
} | ||
} | ||
} | ||
} | ||
|
||
[Obsolete("This property is deprecated. Use InfoBadge instead.", false)] | ||
public static readonly DependencyProperty BadgeValueProperty = | ||
DependencyProperty.Register("BadgeValue", typeof(string), typeof(TabBarItem), new PropertyMetadata(default(string?), OnPropertyChanged)); | ||
DependencyProperty.Register(nameof(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 | ||
|
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
Uh oh!
There was an error while loading. Please reload this page.