Skip to content

Commit

Permalink
Remove GetCurrentUapVersion function from WinAppSDK Lottie
Browse files Browse the repository at this point in the history
  • Loading branch information
getrou committed Dec 19, 2024
1 parent d7cb090 commit 3af6cf3
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions source/Lottie/Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@

namespace CommunityToolkit.WinUI.Lottie
{
#pragma warning disable SA1303 // Constants must begin with an upper case letter.

/// <summary>
/// Handles loading a composition from a Lottie file. The result of the load
/// is a <see cref="AnimatedVisualFactory"/> that can be used to instantiate a
/// Composition tree that will render the Lottie.
/// </summary>
abstract class Loader : IDisposable
{
// TODO: we do not support UAP above 14 in Lottie-Windows yet, only in LottieGen.
const uint c_maxContractVersion = 14u;

// Identifies the bound property names in SourceMetadata.
static readonly Guid s_propertyBindingNamesKey = new Guid("A115C46A-254C-43E6-A3C7-9DE516C3C3C8");

Expand Down Expand Up @@ -147,7 +152,13 @@ await Task.Run(() =>
{
TranslatePropertyBindings = makeColorsBindable,
GenerateColorBindings = makeColorsBindable,
#if WINAPPSDK
// The WindowsAppSDK has access to the latest APIs, and should not use
// fallback APIs based on which OS the app is running on.
TargetUapVersion = c_maxContractVersion,
#else
TargetUapVersion = GetCurrentUapVersion(),
#endif
});

wincompDataRootVisual = translationResult.RootVisual;
Expand Down Expand Up @@ -211,17 +222,13 @@ static IReadOnlyList<Issue> ToIssues(IEnumerable<(string Code, string Descriptio
static IReadOnlyList<Issue> ToIssues(IEnumerable<TranslationIssue> issues)
=> issues.Select(issue => new Issue(code: issue.Code, description: issue.Description)).ToArray();

#if !WINAPPSDK
/// <summary>
/// Gets the highest UAP version supported by the current process.
/// </summary>
/// <returns>The highest UAP version supported by the current process.</returns>
static uint GetCurrentUapVersion()
{
#if WINAPPSDK
// The WindowsAppSDK has access to all APIs up to version 14, and should not use fallback APIs
// based on which OS the app is running on.
return 14;
#else
// Start testing on version 2. We know that at least version 1 is supported because
// we are running in UAP code.
var versionToTest = 1u;
Expand All @@ -233,13 +240,12 @@ static uint GetCurrentUapVersion()
versionToTest++;
}

// TODO: we do not support UAP above 14 in Lottie-Windows yet, only in LottieGen.
versionToTest = Math.Min(versionToTest, 14);
versionToTest = Math.Min(versionToTest, c_maxContractVersion);

// Query failed on versionToTest. Return the previous version.
return versionToTest;
#endif
}
#endif

// Specializes the Stopwatch to do just the one thing we need of it - get the time
// elapsed since the last call then restart the Stopwatch to start measuring again.
Expand Down

0 comments on commit 3af6cf3

Please sign in to comment.