Пример #1
0
        private async void DoLoadDrawable(ContentControl contentControl)
        {
            _lottieDrawable        = new LottieDrawable();
            contentControl.Content = _lottieDrawable;
            // var xurl =
            //     "https://raw.githubusercontent.com/wintb/lottie-example/master/LottieSample/src/androidTest/assets/LightBulb.json";
            // string s;
            // using (WebClient client = new WebClient())
            // {
            //  s = client.DownloadString(xurl);
            // }


            var assets = AvaloniaLocator.Current.GetService <IAssetLoader>();
            var getstr = assets.Open(new Uri("avares://Avalonia.Lottie.Sample/Assets/Gears.json"));
            var a      = await new StreamReader(getstr).ReadToEndAsync();

            var res = await LottieCompositionFactory.FromJsonString(a, "cache1");

            if (res is not null)
            {
                _lottieDrawable.SetComposition(res.Value);
                // _lottieDrawable.DirectScale = 0.45f;
                _lottieDrawable.RepeatCount = Int32.MaxValue;
                _lottieDrawable.Scale       = 1f;
                _lottieDrawable.Start();
            }
        }
Пример #2
0
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            var localDir = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync(@"Assets");

            var file = await localDir.GetFileAsync("test.json");

            var json = await FileIO.ReadTextAsync(file, Windows.Storage.Streams.UnicodeEncoding.Utf8);

            await LottieView.SetAnimationFromJsonAsync(json, "test");

            var compositionResult = await LottieCompositionFactory.FromJsonString(json, "test");

            if (compositionResult.Value != null)
            {
                LottieDrawable.SetComposition(compositionResult.Value);
                LottieDrawable.RepeatCount = -1;
                LottieDrawable.PlayAnimation();
            }

            LottieView.PlayAnimation();
        }
Пример #3
0
 public static async Task <LottieComposition> FromJsonStringAsync(string jsonString, CancellationToken cancellationToken = default(CancellationToken))
 {
     return((await LottieCompositionFactory.FromJsonString(jsonString, null, cancellationToken)).Value);
 }