Skip to content

Commit

Permalink
AOT compatibility for winui3 package (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
aborziak-ms authored Apr 10, 2024
1 parent 0443b1e commit e37426d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>net7.0-windows10.0.18362.0</TargetFramework>
<IsAotCompatible>true</IsAotCompatible>
<OutputType>Library</OutputType>

<PackageId>CommunityToolkit.WinUI.Lottie</PackageId>
Expand Down
38 changes: 29 additions & 9 deletions source/UIData/Tools/Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,38 @@ namespace CommunityToolkit.WinUI.Lottie.UIData.Tools
{
static class Properties
{
static IReadOnlyDictionary<string, PropertyId>? s_propertyIdFromNameMap;
static IReadOnlyDictionary<string, PropertyId> s_propertyIdFromNameMap = new Dictionary<string, PropertyId>
{
{ "BorderMode", PropertyId.BorderMode},
{ "CenterPoint", PropertyId.CenterPoint},
{ "Children", PropertyId.Children},
{ "Clip", PropertyId.Clip},
{ "Color", PropertyId.Color},
{ "Comment", PropertyId.Comment},
{ "IsVisible", PropertyId.IsVisible},
{ "Offset", PropertyId.Offset},
{ "Opacity", PropertyId.Opacity},
{ "Path", PropertyId.Path},
{ "Position", PropertyId.Position},
{ "Progress", PropertyId.Progress},
{ "Properties", PropertyId.Properties},
{ "RotationAngleInDegrees", PropertyId.RotationAngleInDegrees},
{ "RotationAxis", PropertyId.RotationAxis},
{ "Scale", PropertyId.Scale},
{ "Size", PropertyId.Size},
{ "StrokeEndCap", PropertyId.StrokeEndCap},
{ "StrokeDashCap", PropertyId.StrokeDashCap},
{ "StrokeLineJoin", PropertyId.StrokeLineJoin},
{ "StrokeMiterLimit", PropertyId.StrokeMiterLimit},
{ "StrokeStartCap", PropertyId.StrokeStartCap},
{ "TransformMatrix", PropertyId.TransformMatrix},
{ "TrimEnd", PropertyId.TrimEnd},
{ "TrimOffset", PropertyId.TrimOffset},
{ "TrimStart", PropertyId.TrimStart},
};

internal static PropertyId PropertyIdFromName(string value)
{
if (s_propertyIdFromNameMap is null)
{
s_propertyIdFromNameMap =
Enum.GetValues(typeof(PropertyId)).Cast<PropertyId>()
.Where(p => p != PropertyId.None)
.ToDictionary(p => Enum.GetName(typeof(PropertyId), p)!);
}

return s_propertyIdFromNameMap.TryGetValue(value, out var result)
? result
: PropertyId.None;
Expand Down
3 changes: 3 additions & 0 deletions source/UIData/Tools/PropertyId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@ enum PropertyId
TrimEnd = TransformMatrix << 1,
TrimOffset = TrimEnd << 1,
TrimStart = TrimOffset << 1,

// Any new value should also be added to UIData/Tools/Properties.cs
// This is needed to omit Enum.GetValues usage to be AOT compatible.
}
}

0 comments on commit e37426d

Please sign in to comment.