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

Rating view #1706

Closed
wants to merge 11 commits into from
52 changes: 52 additions & 0 deletions src/CommunityToolkit.Maui.Core/Primitives/Defaults/RatingShape.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace CommunityToolkit.Maui.Core.Primitives.Defaults;

/// <summary>
/// The type of the shape to display on the rating view
/// </summary>
public readonly partial struct RatingShape(string pathData)
Eel2000 marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// the data path data from the svg
/// </summary>
public string PathData { get; } = pathData;
}

public partial struct RatingShape
{
/// <summary>
/// the default star shape
/// </summary>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let update this to describe the shape. Right now it is just repeating the property name.

public static RatingShape Star => new(PathShapes.Star);
Eel2000 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// The default heart shape
/// </summary>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let update this to describe the shape. Right now it is just repeating the property name.

public static RatingShape Heart => new(PathShapes.Heart);
Eel2000 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// The cirle shape
/// </summary>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reminder to add descriptive XML Comments

public static RatingShape Circle => new(PathShapes.Circle);
Eel2000 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// The Like shapes
/// </summary>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reminder to add descriptive XML Comments

public static RatingShape Like => new(PathShapes.Like);
Eel2000 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// The Dislike
/// </summary>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reminder to add descriptive XML Comments

public static RatingShape DisLike => new(PathShapes.Dislike);
Eel2000 marked this conversation as resolved.
Show resolved Hide resolved
Eel2000 marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
///
/// </summary>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reminder to add XML Comments

static class PathShapes
{
public const string Star = "M9 11.3l3.71 2.7-1.42-4.36L15 7h-4.55L9 2.5 7.55 7H3l3.71 2.64L5.29 14z";
public const string Heart = "M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z";
public const string Circle = "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2z";
public const string Like = "M1 21h4V9H1v12zm22-11c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-1.91l-.01-.01L23 10z";
public const string Dislike = "M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v1.91l.01.01L1 14c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L9.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm4 0v12h4V3h-4z";
}
11 changes: 11 additions & 0 deletions src/CommunityToolkit.Maui.Core/Primitives/Rating.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace CommunityToolkit.Maui.Core.Primitives;

///<summary></summary>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reminder to add descriptive XML Comments

public class Rating
{
///<summary></summary>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reminder to add descriptive XML Comments

public double? CurrentRating { get; set; }

///<summary></summary>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reminder to add descriptive XML Comments

public object? CommandParameter { get; set; }
Eel2000 marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task ByteArrayToImageSourceConverter()
}

[Theory]
[InlineData("Random String Value")]
[InlineData("Random String CurrentRating")]
brminnick marked this conversation as resolved.
Show resolved Hide resolved
[InlineData(3)]
[InlineData(5.5)]
[InlineData('c')]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public event EventHandler AnimationCompleted
}

/// <summary>
/// Value of <see cref="ProgressBar.Progress"/>, clamped to a minimum value of 0 and a maximum value of 1
/// CurrentRating of <see cref="ProgressBar.Progress"/>, clamped to a minimum value of 0 and a maximum value of 1
pictos marked this conversation as resolved.
Show resolved Hide resolved
brminnick marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public double Progress
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public string? ValuePropertyName
/// Allows the user to provide a custom <see cref="ICommand"/> that handles forcing validation. This is a bindable property.
/// </summary>
/// <remarks>
/// The Default Value for <see cref="ForceValidateCommand"/> has a <see cref="Type"/> of Command&lt;CancellationToken&gt; which requires a <see cref="CancellationToken"/> as a CommandParameter. See <see cref="Command{CancellationToken}"/> and <see cref="System.Windows.Input.ICommand.Execute(object)"/> for more information on passing a <see cref="CancellationToken"/> into <see cref="Command{T}"/> as a CommandParameter"
/// The Default CurrentRating for <see cref="ForceValidateCommand"/> has a <see cref="Type"/> of Command&lt;CancellationToken&gt; which requires a <see cref="CancellationToken"/> as a CommandParameter. See <see cref="Command{CancellationToken}"/> and <see cref="System.Windows.Input.ICommand.Execute(object)"/> for more information on passing a <see cref="CancellationToken"/> into <see cref="Command{T}"/> as a CommandParameter"
brminnick marked this conversation as resolved.
Show resolved Hide resolved
/// </remarks>
public ICommand ForceValidateCommand
{
Expand Down
4 changes: 2 additions & 2 deletions src/CommunityToolkit.Maui/CommunityToolkit.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)"/>
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiPackageVersion)"/>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiPackageVersion)" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/CommunityToolkit.Maui/Converters/BaseConverter.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public abstract class BaseConverter<TFrom, TTo, TParam> : ValueConverterExtensio
/// <summary>
/// Method that will be called by <see cref="IValueConverter.ConvertBack(object?, Type, object?, CultureInfo?)"/>.
/// </summary>
/// <param name="value">Value to be converted from <typeparamref name="TTo"/> to <typeparamref name="TFrom"/>.</param>
/// <param name="value">CurrentRating to be converted from <typeparamref name="TTo"/> to <typeparamref name="TFrom"/>.</param>
brminnick marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="parameter">Optional Parameters</param>
/// <param name="culture">Culture Info</param>
/// <returns>An object of type <typeparamref name="TFrom"/>.</returns>
Expand Down Expand Up @@ -134,7 +134,7 @@ public abstract class BaseConverter<TFrom, TTo> : ValueConverterExtension, IComm
/// <summary>
/// Method that will be called by <see cref="IValueConverter.ConvertBack(object?, Type, object?, CultureInfo?)"/>.
/// </summary>
/// <param name="value">Value to be converted from <typeparamref name="TTo"/> to <typeparamref name="TFrom"/>.</param>
/// <param name="value">CurrentRating to be converted from <typeparamref name="TTo"/> to <typeparamref name="TFrom"/>.</param>
brminnick marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="culture">Culture Info</param>
/// <returns>An object of type <typeparamref name="TFrom"/>.</returns>
public abstract TFrom ConvertBackTo(TTo value, CultureInfo? culture);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public override bool ConvertBackTo(TObject? value, CultureInfo? culture = null)

ArgumentNullException.ThrowIfNull(value);

throw new ArgumentException($"Value is not a valid {typeof(TObject).Name}", nameof(value));
throw new ArgumentException($"CurrentRating is not a valid {typeof(TObject).Name}", nameof(value));
brminnick marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public override int ConvertBackTo(object? value, Array parameter, CultureInfo? c
}
}

throw new ArgumentException("Value does not exist in the array.", nameof(value));
throw new ArgumentException("CurrentRating does not exist in the array.", nameof(value));
brminnick marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public IComparable? MinValue
set => SetValue(MinValueProperty, value);
}

/// <summary>Maximum value.</summary>
/// <summary>MaximumRating value.</summary>
brminnick marked this conversation as resolved.
Show resolved Hide resolved
public IComparable? MaxValue
{
get => (IComparable?)GetValue(MaxValueProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class MultiConverter : List<ICommunityToolkitValueConverter>, ICommunityT
/// <summary>
/// Uses the incoming converters to convert the value.
/// </summary>
/// <param name="value">Value to convert.</param>
/// <param name="value">CurrentRating to convert.</param>
brminnick marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="targetType">The type of the binding target property.</param>
/// <param name="parameter">Parameter to pass into subsequent converters.</param>
/// <param name="culture">The culture to use in the converter.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static partial class ColorAnimationExtensions
/// <param name="length">The duration, in milliseconds, of the animation</param>
/// <param name="easing">The easing function to be used in the animation</param>
/// <param name="token"><see cref="CancellationToken"/></param>
/// <returns>Value indicating if the animation completed successfully or not</returns>
/// <returns>CurrentRating indicating if the animation completed successfully or not</returns>
brminnick marked this conversation as resolved.
Show resolved Hide resolved
public static Task<bool> BackgroundColorTo(this VisualElement element, Color color, uint rate = 16u, uint length = 250u, Easing? easing = null, CancellationToken token = default)
{
ArgumentNullException.ThrowIfNull(element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private protected static void ValidateTargetType<TTarget>(Type targetType, bool
// Ensure TTo can be assigned to the given Target Type
if (!typeof(TTarget).IsAssignableFrom(targetType) // Ensure TTarget can be assigned from targetType. Eg TTarget is IEnumerable and targetType is IList
&& !IsValidTargetType<TTarget>(targetType) // Ensure targetType be converted to TTarget? Eg `Convert.ChangeType()` returns a non-null value
&& !(shouldAllowNullableValueTypes && typeof(TTarget).IsValueType && IsValidNullableValueType(targetType))) // Is TTarget a Value Type and targetType a Nullable Value Type? Eg TTarget is bool and targetType is bool?
&& !(shouldAllowNullableValueTypes && typeof(TTarget).IsValueType && IsValidNullableValueType(targetType))) // Is TTarget a CurrentRating Type and targetType a Nullable CurrentRating Type? Eg TTarget is bool and targetType is bool?
brminnick marked this conversation as resolved.
Show resolved Hide resolved
{
throw new ArgumentException($"targetType needs to be assignable from {typeof(TTarget)}.", nameof(targetType));
}
Expand All @@ -65,7 +65,7 @@ static bool IsValidNullableValueType(Type targetType)
private protected static TParam ConvertParameter<TParam>(object? parameter) => parameter switch
{
null when IsNullable<TParam>() => default,
null when !IsNullable<TParam>() => throw new ArgumentNullException(nameof(parameter), $"Value cannot be null because {nameof(TParam)} is not nullable."),
null when !IsNullable<TParam>() => throw new ArgumentNullException(nameof(parameter), $"CurrentRating cannot be null because {nameof(TParam)} is not nullable."),
brminnick marked this conversation as resolved.
Show resolved Hide resolved
TParam convertedParameter => convertedParameter,
_ => throw new ArgumentException($"Parameter needs to be of type {typeof(TParam)}", nameof(parameter))
};
Expand All @@ -75,9 +75,9 @@ null when IsNullable<TParam>() => default,
private protected static TValue ConvertValue<TValue>(object? value) => value switch
{
null when IsNullable<TValue>() => default,
null when !IsNullable<TValue>() => throw new ArgumentNullException(nameof(value), $"Value cannot be null because {nameof(TValue)} is not nullable"),
null when !IsNullable<TValue>() => throw new ArgumentNullException(nameof(value), $"CurrentRating cannot be null because {nameof(TValue)} is not nullable"),
brminnick marked this conversation as resolved.
Show resolved Hide resolved
TValue convertedValue => convertedValue,
_ => throw new ArgumentException($"Value needs to be of type {typeof(TValue)}", nameof(value))
_ => throw new ArgumentException($"CurrentRating needs to be of type {typeof(TValue)}", nameof(value))
brminnick marked this conversation as resolved.
Show resolved Hide resolved
};
#pragma warning restore CS8603 // Possible null reference return.

Expand Down
Loading