Skip to content

Commit 4a76da8

Browse files
Minor clean-up and re-arrange.
1 parent 10a5a06 commit 4a76da8

File tree

6 files changed

+25
-40
lines changed

6 files changed

+25
-40
lines changed

samples/CommunityToolkit.Maui.Sample/Pages/Views/RatingView/RatingViewCsharpPage.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
using CommunityToolkit.Maui.Alerts;
44
using CommunityToolkit.Maui.Core;
5-
using CommunityToolkit.Maui.Core.Primitives;
65
using CommunityToolkit.Maui.Markup;
76
using CommunityToolkit.Maui.Sample.ViewModels.Views;
87
using CommunityToolkit.Maui.Views;

src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
</ItemGroup>
5151

5252
<ItemGroup>
53-
<PackageReference Include="Microsoft.Maui.Core" Version="[$(MauiPackageVersion),$(NextMauiPackageVersion))"/>
54-
<PackageReference Include="Microsoft.Maui.Essentials" Version="[$(MauiPackageVersion),$(NextMauiPackageVersion))"/>
53+
<PackageReference Include="Microsoft.Maui.Core" Version="[$(MauiPackageVersion),$(NextMauiPackageVersion))" />
54+
<PackageReference Include="Microsoft.Maui.Essentials" Version="[$(MauiPackageVersion),$(NextMauiPackageVersion))" />
5555
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" Condition=" '$(Configuration)'=='Release' " PrivateAssets="All" />
5656
<PackageReference Include="System.Speech" Version="9.0.0" Condition="'$(TargetFramework)' == '$(NetVersion)-windows10.0.19041.0'" />
5757
</ItemGroup>

src/CommunityToolkit.Maui.Core/Primitives/RatingViewShapeHandler.shared.cs renamed to src/CommunityToolkit.Maui.Core/Handlers/RatingView/RatingViewShapeHandler.shared.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace CommunityToolkit.Maui.Core.Primitives;
1+
namespace CommunityToolkit.Maui.Core.Handlers;
22

33
/// <summary>Shapes available for the rating view.</summary>
44
public sealed class RatingViewShapeHandler

src/CommunityToolkit.Maui.Core/Primitives/RatingViewShapes.shared.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Ignore Spelling: color
2-
namespace CommunityToolkit.Maui.Core.Primitives;
2+
namespace CommunityToolkit.Maui.Core;
33

44
/// <summary>Rating view shape enumerator.</summary>
55
public enum RatingViewShapes

src/CommunityToolkit.Maui.UnitTests/Views/RatingView/RatingViewTests.cs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
using System.ComponentModel;
44
using CommunityToolkit.Maui.Core;
5-
using CommunityToolkit.Maui.Core.Primitives;
65
using CommunityToolkit.Maui.Views;
76
using FluentAssertions;
87
using Microsoft.Maui.Controls.Shapes;
@@ -17,13 +16,13 @@ public void Defaults_BindingContext()
1716
{
1817
MockRatingViewViewModel vm = new();
1918
RatingView ratingViewWithBinding = new();
20-
19+
2120
ratingViewWithBinding.BindingContext.Should().BeNull();
2221
ratingViewWithBinding.RatingLayout.BindingContext.Should().BeNull();
2322
ratingViewWithBinding.RatingLayout.BindingContext.Should().BeEquivalentTo(ratingViewWithBinding.BindingContext);
24-
23+
2524
ratingViewWithBinding.BindingContext = vm;
26-
25+
2726
ratingViewWithBinding.BindingContext.Should().Be(vm);
2827
ratingViewWithBinding.RatingLayout.BindingContext.Should().Be(vm);
2928
ratingViewWithBinding.RatingLayout.BindingContext.Should().BeEquivalentTo(ratingViewWithBinding.BindingContext);
@@ -49,7 +48,7 @@ public void Defaults_ShapeDefaultsApplied()
4948
{
5049
RatingView ratingView = new();
5150
var firstItemShape = GetItemShape(ratingView, 0);
52-
51+
5352
firstItemShape.Should().NotBeNull();
5453
firstItemShape.Should().BeOfType<Microsoft.Maui.Controls.Shapes.Path>();
5554
firstItemShape.Aspect.Should().Be(Stretch.Uniform);
@@ -121,7 +120,7 @@ public void Events_RatingChanged_AddRemove()
121120
};
122121
ratingView.RatingChanged += OnRatingChanged;
123122
ratingView.Rating = expectedRating;
124-
receivedEvents.Should().HaveCount(1);
123+
receivedEvents.Should().ContainSingle();
125124
receivedEvents[0].Rating.Should().Be(expectedRating);
126125

127126
void OnRatingChanged(object? sender, RatingChangedEventArgs e)
@@ -242,7 +241,7 @@ public void Events_ShouldBeRaised_MaximumRatingChanged_BelowRating()
242241
};
243242
ratingView.RatingChanged += (sender, e) => receivedEvents.Add(e);
244243
ratingView.MaximumRating = (byte)expectedRating;
245-
receivedEvents.Should().HaveCount(1);
244+
receivedEvents.Should().ContainSingle();
246245
receivedEvents[0].Rating.Should().Be(expectedRating);
247246
}
248247

@@ -269,7 +268,7 @@ public void Events_ShouldNotBeRaised_MaximumRatingChanged_AboveRating()
269268
};
270269
ratingView.RatingChanged += (sender, e) => receivedEvents.Add(e);
271270
ratingView.MaximumRating = 4;
272-
receivedEvents.Should().HaveCount(0);
271+
receivedEvents.Should().BeEmpty();
273272
}
274273

275274
[Fact]
@@ -381,7 +380,7 @@ public void Properties_Change_EmptyColor_Item()
381380
ratingView.EmptyColor.Should().NotBe(emptyColor);
382381
ratingView.EmptyColor = emptyColor;
383382
ratingView.EmptyColor.Should().Be(emptyColor);
384-
383+
385384
var emptyRatingItem = (Microsoft.Maui.Controls.Shapes.Path) GetItemShape(ratingView, maximumRating - 1).GetVisualTreeDescendants()[0];
386385
emptyRatingItem.Fill.Should().Be(new SolidColorBrush(emptyColor));
387386
}
@@ -546,11 +545,11 @@ public void Properties_Change_ShapeBorderColor()
546545
var shapeBorderColor = Colors.Snow;
547546
Brush brush = new SolidColorBrush(shapeBorderColor);
548547
RatingView ratingView = new();
549-
548+
550549
ratingView.ShapeBorderColor.Should().NotBe(shapeBorderColor);
551550
ratingView.ShapeBorderColor = shapeBorderColor;
552551
ratingView.ShapeBorderColor.Should().Be(shapeBorderColor);
553-
552+
554553
var firstRatingItem = GetItemShape(ratingView, 0);
555554
firstRatingItem.Stroke.Should().BeOfType<SolidColorBrush>().And.Be(brush);
556555
}
@@ -563,7 +562,7 @@ public void Properties_Change_ShapeBorderThickness()
563562
ratingView.ShapeBorderThickness.Should().NotBe(shapeBorderThickness);
564563
ratingView.ShapeBorderThickness = shapeBorderThickness;
565564
ratingView.ShapeBorderThickness.Should().Be(shapeBorderThickness);
566-
565+
567566
var firstRatingItem = GetItemShape(ratingView, 0);
568567
firstRatingItem.StrokeThickness.Should().Be(shapeBorderThickness);
569568
}
@@ -576,7 +575,7 @@ public void Properties_Change_Size()
576575
ratingView.ItemShapeSize.Should().NotBe(itemShapeSize);
577576
ratingView.ItemShapeSize = itemShapeSize;
578577
ratingView.ItemShapeSize.Should().Be(itemShapeSize);
579-
578+
580579
var firstRatingItem = GetItemShape(ratingView, 0);
581580
firstRatingItem.WidthRequest.Should().Be(itemShapeSize);
582581
firstRatingItem.HeightRequest.Should().Be(itemShapeSize);
@@ -657,8 +656,8 @@ public void RatingViewDoesNotThrowsArgumentOutOfRangeExceptionWhenRatingSetBefor
657656
Rating = rating,
658657
};
659658

660-
Assert.Equal(rating, ratingView.Rating);
661-
Assert.Equal(maximumRating, ratingView.MaximumRating);
659+
ratingView.Rating.Should().Be(rating);
660+
ratingView.MaximumRating.Should().Be(maximumRating);
662661
}
663662

664663
[Fact]
@@ -726,7 +725,7 @@ public void ViewStructure_CorrectNumberOfChildren()
726725
MaximumRating = maximumRating
727726
};
728727

729-
Assert.NotNull(ratingView.ControlTemplate);
728+
ratingView.ControlTemplate.Should().NotBeNull();
730729
ratingView.RatingLayout.GetVisualTreeDescendants().Should().HaveCount((maximumRating * 2) + 1);
731730
ratingView.RatingLayout.Children.Should().HaveCount(maximumRating);
732731
}
@@ -747,7 +746,7 @@ public void ViewStructure_ItemChild_IsPath()
747746
ratingView.RatingLayout.Children[0].Should().BeOfType<Border>();
748747
var child = (Border)ratingView.RatingLayout.Children[0];
749748

750-
Assert.NotNull(child.Content);
749+
child.Content.Should().NotBeNull();
751750
child.Content.GetVisualTreeDescendants()[0].Should().BeOfType<Microsoft.Maui.Controls.Shapes.Path>();
752751
}
753752

@@ -758,10 +757,10 @@ public void ViewStructure_ItemChild_Path_Star()
758757
ratingView.RatingLayout.Children[0].Should().BeOfType<Border>();
759758
var child = (Border)ratingView.RatingLayout.Children[0];
760759

761-
Assert.NotNull(child.Content);
760+
child.Content.Should().NotBeNull();
762761

763762
var shape = (Microsoft.Maui.Controls.Shapes.Path)child.Content.GetVisualTreeDescendants()[0];
764-
shape.GetPath().Should().Be(Core.Primitives.RatingViewShapeHandler.Star.PathData);
763+
shape.GetPath().Should().Be(Core.Handlers.RatingViewShapeHandler.Star.PathData);
765764
}
766765

767766
[Fact]
@@ -839,7 +838,7 @@ public void ViewStructure_Spacing()
839838
static Microsoft.Maui.Controls.Shapes.Path GetItemShape(in RatingView ratingView, int itemIndex)
840839
{
841840
var border = (Border)ratingView.RatingLayout.Children[itemIndex];
842-
Assert.NotNull(border.Content);
841+
border.Content.Should().NotBeNull();
843842

844843
return (Microsoft.Maui.Controls.Shapes.Path)border.Content.GetVisualTreeDescendants()[0];
845844
}

src/CommunityToolkit.Maui/Views/RatingView/RatingView.shared.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Collections.ObjectModel;
44
using System.Diagnostics.CodeAnalysis;
55
using CommunityToolkit.Maui.Core;
6-
using CommunityToolkit.Maui.Core.Primitives;
6+
using CommunityToolkit.Maui.Core.Handlers;
77
using Microsoft.Maui.Controls.Shapes;
88
using Path = Microsoft.Maui.Controls.Shapes.Path;
99

@@ -199,7 +199,7 @@ public double Spacing
199199
set => SetValue(SpacingProperty, value);
200200
}
201201

202-
internal HorizontalStackLayout RatingLayout { get; } = new();
202+
internal HorizontalStackLayout RatingLayout { get; } = [];
203203

204204
static int GetRatingWhenMaximumRatingEqualsOne(double rating) => rating.Equals(0.0) ? 1 : 0;
205205

@@ -262,7 +262,6 @@ static bool IsMaximumRatingValid(BindableObject bindable, object value)
262262
static void OnIsReadOnlyChanged(BindableObject bindable, object oldValue, object newValue)
263263
{
264264
var ratingView = (RatingView)bindable;
265-
266265
foreach (var child in ratingView.RatingLayout.Children.Cast<Border>())
267266
{
268267
if (!ratingView.IsReadOnly)
@@ -280,11 +279,9 @@ static void OnIsReadOnlyChanged(BindableObject bindable, object oldValue, object
280279
static void OnMaximumRatingChange(BindableObject bindable, object oldValue, object newValue)
281280
{
282281
var ratingView = (RatingView)bindable;
283-
284282
var layout = ratingView.RatingLayout;
285283
var newMaximumRatingValue = (int)newValue;
286284
var oldMaximumRatingValue = (int)oldValue;
287-
288285
if (newMaximumRatingValue < oldMaximumRatingValue)
289286
{
290287
for (var lastElement = layout.Count - 1; lastElement >= newMaximumRatingValue; lastElement--)
@@ -369,7 +366,6 @@ static void OnCustomShapePropertyChanged(BindableObject bindable, object oldValu
369366
static void OnItemPaddingPropertyChanged(BindableObject bindable, object oldValue, object newValue)
370367
{
371368
var ratingView = (RatingView)bindable;
372-
373369
for (var element = 0; element < ratingView.RatingLayout.Count; element++)
374370
{
375371
((Border)ratingView.RatingLayout.Children[element]).Padding = (Thickness)newValue;
@@ -379,7 +375,6 @@ static void OnItemPaddingPropertyChanged(BindableObject bindable, object oldValu
379375
static void OnItemShapeBorderColorChanged(BindableObject bindable, object oldValue, object newValue)
380376
{
381377
var ratingView = (RatingView)bindable;
382-
383378
for (var element = 0; element < ratingView.RatingLayout.Count; element++)
384379
{
385380
var border = (Border)ratingView.RatingLayout.Children[element];
@@ -393,7 +388,6 @@ static void OnItemShapeBorderColorChanged(BindableObject bindable, object oldVal
393388
static void OnItemShapeBorderThicknessChanged(BindableObject bindable, object oldValue, object newValue)
394389
{
395390
var ratingView = (RatingView)bindable;
396-
397391
for (var element = 0; element < ratingView.RatingLayout.Count; element++)
398392
{
399393
var border = (Border)ratingView.RatingLayout.Children[element];
@@ -407,14 +401,12 @@ static void OnItemShapeBorderThicknessChanged(BindableObject bindable, object ol
407401
static void OnItemShapePropertyChanged(BindableObject bindable, object oldValue, object newValue)
408402
{
409403
var ratingView = (RatingView)bindable;
410-
411404
ratingView.ChangeRatingItemShape(ratingView.GetShapePathData((RatingViewShapes)newValue));
412405
}
413406

414407
static void OnItemShapeSizeChanged(BindableObject bindable, object oldValue, object newValue)
415408
{
416409
var ratingView = (RatingView)bindable;
417-
418410
for (var element = 0; element < ratingView.RatingLayout.Count; element++)
419411
{
420412
var border = (Border)ratingView.RatingLayout.Children[element];
@@ -489,7 +481,6 @@ void UpdateAllRatingsFills(RatingFillElement ratingFill)
489481
{
490482
var isShapeFill = ratingFill is RatingFillElement.Shape;
491483
var visualElements = GetVisualTreeDescendantsWithBorderAndShape((VisualElement)RatingLayout.GetVisualTreeDescendants()[0], isShapeFill);
492-
493484
if (isShapeFill)
494485
{
495486
UpdateAllRatingShapeFills(visualElements, Rating, FilledColor, EmptyColor);
@@ -504,7 +495,6 @@ static void UpdateAllRatingShapeFills(ReadOnlyCollection<VisualElement> ratingIt
504495
{
505496
var fullFillCount = (int)Math.Floor(rating); // Determine the number of fully filled shapes
506497
var partialFillCount = rating - fullFillCount; // Determine the fraction for the partially filled shape (if any)
507-
508498
for (var i = 0; i < ratingItems.Count; i++)
509499
{
510500
var ratingShape = (Shape)ratingItems[i];
@@ -527,9 +517,7 @@ static void UpdateRatingItemsFills(ReadOnlyCollection<VisualElement> ratingItems
527517
{
528518
var fullFillCount = (int)Math.Floor(rating); // Determine the number of fully filled rating items
529519
var partialFillCount = rating - fullFillCount; // Determine the fraction for the partially filled rating item (if any)
530-
531520
backgroundColor ??= Colors.Transparent;
532-
533521
for (var i = 0; i < ratingItems.Count; i++)
534522
{
535523
var border = (Border)ratingItems[i];
@@ -553,5 +541,4 @@ static void UpdateRatingItemsFills(ReadOnlyCollection<VisualElement> ratingItems
553541
}
554542
}
555543
}
556-
557544
}

0 commit comments

Comments
 (0)