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

Commit

Permalink
Fix badge view default text "0" (#1959)
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoNembrini committed Apr 2, 2023
1 parent da30dde commit 89a363e
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 5 deletions.
32 changes: 32 additions & 0 deletions samples/XCT.Sample/Pages/TestCases/Issue1900.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<pages:BasePage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages"
xmlns:vm="clr-namespace:Xamarin.CommunityToolkit.Sample.ViewModels.TestCases"
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
x:Class="Xamarin.CommunityToolkit.Sample.Pages.TestCases.Issue1900Page">
<pages:BasePage.BindingContext>
<vm:Issue1900ViewModel />
</pages:BasePage.BindingContext>
<ContentPage.Content>
<Grid RowDefinitions="*, *, auto"
Padding="12">
<xct:BadgeView Text="{Binding Counter}"
AutoHide="False"
VerticalOptions="Center"
Grid.Row="0">
<Label Text="Badge should be visible and display 0 as text"
Margin="6" />
</xct:BadgeView>
<xct:BadgeView Text="{Binding Counter}"
VerticalOptions="Center"
Grid.Row="1">
<Label Text="Badge should not be visible"
Margin="6" />
</xct:BadgeView>
<Button Text="Increment"
Command="{Binding ClickCommand}"
Grid.Row="2" />
</Grid>
</ContentPage.Content>
</pages:BasePage>
20 changes: 20 additions & 0 deletions samples/XCT.Sample/Pages/TestCases/Issue1900.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace Xamarin.CommunityToolkit.Sample.Pages.TestCases
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Issue1900Page : BasePage
{
public Issue1900Page()
{
InitializeComponent();
}
}
}
29 changes: 29 additions & 0 deletions samples/XCT.Sample/ViewModels/TestCases/Issue1900ViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.CommunityToolkit.ObjectModel;

namespace Xamarin.CommunityToolkit.Sample.ViewModels.TestCases
{
public class Issue1900ViewModel : BaseViewModel
{
int counter;

public int Counter
{
get => counter;
set => SetProperty(ref counter, value);
}

public ICommand ClickCommand => new AsyncCommand(Click);

public Issue1900ViewModel()
{
}

Task Click()
{
Counter++;
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected override IEnumerable<SectionModel> CreateItems() => new[]
typeof(SnackBarActionExceptionPage),
"SnackBar Action Exception",
"Exception in SnackBar's action doesn't crash the app."),

new SectionModel(
typeof(Issue1883Page),
"SnackBar iOS issue GitHub #1883",
Expand All @@ -58,7 +58,12 @@ protected override IEnumerable<SectionModel> CreateItems() => new[]
new SectionModel(
typeof(DrawingViewInExpanderPage),
"DrawingView in expander",
"DrawingView in Expander Page")
"DrawingView in Expander Page"),

new SectionModel(
typeof(Issue1900Page),
"BadgeView Issue GitHub #1900",
"BadgeView default text")
};
}
}
7 changes: 4 additions & 3 deletions samples/XCT.Sample/Xamarin.CommunityToolkit.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Pages\TestCases\Issue1900.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Pages\TestCases\Popups\PopupModalPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
Expand All @@ -52,8 +55,6 @@
<ItemGroup>
<ProjectReference Include="..\..\src\CommunityToolkit\Xamarin.CommunityToolkit\Xamarin.CommunityToolkit.csproj" />
<ProjectReference Include="..\..\src\Markup\Xamarin.CommunityToolkit.Markup\Xamarin.CommunityToolkit.Markup.csproj" />
<ProjectReference Include="..\..\src\SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"/>
<ProjectReference Include="..\..\src\SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator\Xamarin.CommunityToolkit.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ public FontAttributes FontAttributes

protected override void OnControlInitialized(Grid control)
{
BadgeText.Text = Text;
BadgeIndicatorBackground.Content = BadgeText;

BadgeIndicatorContainer.Children.Add(BadgeIndicatorBackground);
Expand Down

0 comments on commit 89a363e

Please sign in to comment.