Skip to content

Commit 2e8ca56

Browse files
getrouaborziak-ms
andauthored
Don't use fallback APIs based on OS version when running on WinAppSDK (#566)
* Don't use fallback APIs based on OS version when running on WinAppSDK * Remove GetCurrentUapVersion function from WinAppSDK Lottie * Separate contract version into UAP contract version and WinAppSDK contract version --------- Co-authored-by: aborziak-ms <[email protected]>
1 parent 675fc58 commit 2e8ca56

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

source/Lottie/Loader.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,20 @@
2525

2626
namespace CommunityToolkit.WinUI.Lottie
2727
{
28+
#pragma warning disable SA1303 // Constants must begin with an upper case letter.
29+
2830
/// <summary>
2931
/// Handles loading a composition from a Lottie file. The result of the load
3032
/// is a <see cref="AnimatedVisualFactory"/> that can be used to instantiate a
3133
/// Composition tree that will render the Lottie.
3234
/// </summary>
3335
abstract class Loader : IDisposable
3436
{
37+
// TODO: we do not support versions above 14 in Lottie-Windows yet, only in LottieGen.
38+
// Mostly this is because Lottie-Windows does not yet support custom AnimationControllers.
39+
const uint c_maxUapContractVersion = 14u;
40+
const uint c_maxWinAppSDKContractVersion = 14u;
41+
3542
// Identifies the bound property names in SourceMetadata.
3643
static readonly Guid s_propertyBindingNamesKey = new Guid("A115C46A-254C-43E6-A3C7-9DE516C3C3C8");
3744

@@ -147,7 +154,14 @@ await Task.Run(() =>
147154
{
148155
TranslatePropertyBindings = makeColorsBindable,
149156
GenerateColorBindings = makeColorsBindable,
157+
#if WINAPPSDK
158+
// The WindowsAppSDK has access to the latest APIs, and should not use
159+
// fallback APIs based on which OS the app is running on. In the future
160+
// Lottie might be able to target specific WinAppSDK versions.
161+
TargetUapVersion = c_maxWinAppSDKContractVersion,
162+
#else
150163
TargetUapVersion = GetCurrentUapVersion(),
164+
#endif
151165
});
152166

153167
wincompDataRootVisual = translationResult.RootVisual;
@@ -211,6 +225,7 @@ static IReadOnlyList<Issue> ToIssues(IEnumerable<(string Code, string Descriptio
211225
static IReadOnlyList<Issue> ToIssues(IEnumerable<TranslationIssue> issues)
212226
=> issues.Select(issue => new Issue(code: issue.Code, description: issue.Description)).ToArray();
213227

228+
#if !WINAPPSDK
214229
/// <summary>
215230
/// Gets the highest UAP version supported by the current process.
216231
/// </summary>
@@ -228,12 +243,12 @@ static uint GetCurrentUapVersion()
228243
versionToTest++;
229244
}
230245

231-
// TODO: we do not support UAP above 14 in Lottie-Windows yet, only in LottieGen.
232-
versionToTest = Math.Min(versionToTest, 14);
246+
versionToTest = Math.Min(versionToTest, c_maxUapContractVersion);
233247

234248
// Query failed on versionToTest. Return the previous version.
235249
return versionToTest;
236250
}
251+
#endif
237252

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

0 commit comments

Comments
 (0)