Windows 平台支持——UWP / WinUI 3 / Flutter
官方 Windows 支持
Airbnb 在 2018 年为 Windows 平台开源了 lottie-windows 库,支持:
- UWP(Universal Windows Platform)—— Windows 10/11 应用、Xbox、HoloLens。
- 底层渲染用 DirectComposition,性能可以接受。
Windows 平台安装方式
UWP(官方)
<!-- Package.appxmanifest -->
<PackageReference Include="LottieUWP" Version="2.5.0" />
或者 NuGet 包管理器里搜索 LottieUWP。
使用:
using LottieUWP;
// XAML
<lottie:LottieAnimationView x:Name="MyAnimationView" />
// C#
MyAnimationView.SetAnimation("loading.json");
MyAnimationView.PlayAnimation();
WinUI 3(社区封装)
WinUI 3 是 Windows App SDK 的现代 UI 框架,官方 UWP 库不直接支持 WinUI 3,但社区有维护:
- CommunityToolkit.Lottie:Windows Community Toolkit 团队维护,支持 WinUI 3。
- 安装:NuGet 搜索
CommunityToolkit.Lottie.WinUI3。
.NET MAUI(跨平台)
<PackageReference Include="CommunityToolkit.Lottie.MAUI" Version="*" />
在 MAUI 里一套代码同时跑 Windows + Android + iOS + macOS。
Flutter
Flutter 社区有成熟的 lottie-flutter 包:
# pubspec.yaml
dependencies:
lottie: ^3.0.0
import 'package:lottie/lottie.dart';
Lottie.asset('assets/loading.json')
Flutter 的优势是一套代码跑 Android / iOS / Web / Windows / macOS / Linux / Fuchsia——如果你的产品需要这么多平台,Lottie + Flutter 组合是性价比极高的选择。
Windows 特有的注意事项
API 限制
Windows 上有些特性不完全支持:
- 某些 AE 表达式和高级 Layer Effects 不支持。
- 文字图层需要 Convert to Outlines(转轮廓)后才能稳定渲染。
- 位图图层的遮罩(Mask)支持有限。
性能
Windows PC 的硬件配置跨度很大——从低配笔记本到高配工作站。建议:
- 动画保持矢量为主(避免大量位图)。
- 图层数量控制在 100 以内。
- 在低端设备上测试性能。
Lottie Viewer
微软官方提供了一个 Lottie Viewer 应用(Microsoft Store 可下载),可以在 Windows 设备上预览 Lottie 动画、生成 C# / C++ 代码片段——和 Android 的 Sample App 类似,快速验错和生成集成代码。
跨平台选型建议
| 目标平台 | 推荐技术栈 |
|---|---|
| iOS + Android | React Native / Flutter + Lottie |
| iOS + Android + Web | Flutter Web + Lottie 或 React (Web) + React Native + Lottie |
| 纯 Web | lottie-web / lottie-player |
| Windows 桌面优先 | .NET MAUI + CommunityToolkit.Lottie |
| 全平台(iOS/Android/Web/Windows/macOS/Linux) | Flutter + lottie-flutter |