Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
Fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebaltazar committed Nov 25, 2024
1 parent 0de9283 commit dc89189
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
4 changes: 1 addition & 3 deletions Maui.CommunityToolkit.TabView.Compat/TabBadgeTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ public TabBadgeTemplate()
HorizontalOptions = LayoutOptions.Start;
VerticalOptions = LayoutOptions.Start;

var badgeBorder = new Frame
var badgeBorder = new Border
{
HasShadow = false,
IsClippedToBounds = false,
Padding = 2,
Margin = 6
};
Expand Down
31 changes: 19 additions & 12 deletions Maui.CommunityToolkit.TabView.Compat/TabBadgeView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using Microsoft.Maui.Controls.Shapes;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace Maui.CommunityToolkit.TabView.Compat;
Expand All @@ -8,7 +9,7 @@ public class TabBadgeView : TemplatedView
internal const string ElementBorder = "PART_Border";
internal const string ElementText = "PART_Text";

Frame? badgeBorder;
Border? badgeBorder;
Label? badgeText;
bool isVisible;

Expand Down Expand Up @@ -108,13 +109,16 @@ public string Text
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
try
{
badgeBorder = (Border)GetTemplateChild(ElementBorder);
badgeText = (Label)GetTemplateChild(ElementText);

badgeBorder = (Frame)GetTemplateChild(ElementBorder);
badgeText = (Label)GetTemplateChild(ElementText);

UpdateSize();
UpdatePosition(badgeBorder);
UpdateIsEnabled(badgeText);
UpdateSize();
UpdatePosition(badgeBorder);
UpdateIsEnabled(badgeText);
}
catch (Exception _) { }
}

protected override void OnPropertyChanged([CallerMemberName] string propertyName = "")
Expand All @@ -135,7 +139,7 @@ void UpdateIsEnabled(in Label badgeText)

void OnBadgeTextPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is nameof(Height) or nameof(Width) && badgeBorder is Frame frame)
if (e.PropertyName is nameof(Height) or nameof(Width) && badgeBorder is Border frame)
{
UpdateSize();
UpdatePosition(frame);
Expand All @@ -153,10 +157,13 @@ void UpdateSize()
badgeBorder.HeightRequest = badgeTextHeight;
badgeBorder.WidthRequest = badgeTextWidth;

badgeBorder.CornerRadius = (int)Math.Round(badgeTextHeight / 2);
badgeBorder.StrokeShape = new RoundRectangle
{
CornerRadius = new CornerRadius((int)Math.Round(badgeTextHeight / 2))
};
}

void UpdatePosition(Frame badgeBorder)
void UpdatePosition(Border badgeBorder)
{
if (PlacementTarget == null)
return;
Expand All @@ -178,7 +185,7 @@ void UpdateBackgroundColor(Color backgroundColor)
void UpdateBorderColor(Color borderColor)
{
if (badgeBorder != null)
badgeBorder.BorderColor = borderColor;
badgeBorder.Stroke = borderColor;
}

void UpdateTextColor(Color textColor)
Expand Down

0 comments on commit dc89189

Please sign in to comment.