public async Task TestLoadJsonUrl() { LottieResult <LottieComposition> result = await LottieCompositionFactory.FromUrlAsync(CanvasDevice.GetSharedDevice(), "https://www.lottiefiles.com/download/427"); Assert.Null(result.Exception); Assert.NotNull(result.Value); }
public void TestLoadInvalidAssetName() { LottieResult <LottieComposition> result = LottieCompositionFactory.FromAssetSync(null, "square2.json"); Assert.Equal(typeof(FileNotFoundException), result.Exception.GetType()); Assert.Null(result.Value); }
public void TestNonJsonAssetFile() { LottieResult <LottieComposition> result = LottieCompositionFactory.FromAssetSync(null, "not_json.txt"); Assert.NotNull(result.Exception); Assert.Null(result.Value); }
public void TestLoadInvalidJsonString() { LottieResult <LottieComposition> result = LottieCompositionFactory.FromJsonStringSync(_notJson, "not_json"); Assert.NotNull(result.Exception); Assert.Null(result.Value); }
/// <summary> /// Returns null if the animation doesn't exist in the cache. /// </summary> /// <returns></returns> private async Task <LottieComposition> FetchFromCacheAsync(CancellationToken cancellationToken = default(CancellationToken)) { var cacheResult = await _networkCache.FetchAsync(cancellationToken); if (cacheResult == null) { return(null); } var extension = cacheResult.Value.Key; using (var inputStream = cacheResult.Value.Value) { LottieResult <LottieComposition> result; if (extension == FileExtension.Zip) { result = await LottieCompositionFactory.FromZipStreamAsync(new ZipArchive(inputStream), _url); } else { result = await LottieCompositionFactory.FromJsonInputStreamAsync(inputStream, _url, cancellationToken); } if (result.Value != null) { return(result.Value); } } return(null); }
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(); } }
public static LottieComposition FromInputStreamSync(Stream stream, bool close) { if (close) { Debug.WriteLine("Lottie now auto-closes input stream!", LottieLog.Tag); } return(LottieCompositionFactory.FromJsonInputStreamSync(stream, null).Value); }
public void TestLoadInvalidJsonReader() { JsonReader reader = new JsonReader(new StringReader(_notJson)); LottieResult <LottieComposition> result = LottieCompositionFactory.FromJsonReaderSync(reader, "json"); Assert.NotNull(result.Exception); Assert.Null(result.Value); }
private async Task <LottieResult <LottieComposition> > FetchFromNetworkInternalAsync( CancellationToken cancellationToken = default) { Debug.WriteLine($"Fetching {_url}", LottieLog.Tag); using (var connection = new HttpClient()) { using (var response = await connection.GetAsync(_url, cancellationToken)) { if (!response.IsSuccessStatusCode) { return(new LottieResult <LottieComposition>(new ArgumentException( $"Unable to fetch {_url}. Failed with {response.StatusCode}\n{response.ReasonPhrase}"))); } //StorageFile file; FileExtension extension; LottieResult <LottieComposition> result; switch (response.Content.Headers.ContentType.MediaType) { case "application/zip": Debug.WriteLine("Handling zip response.", LottieLog.Tag); extension = FileExtension.Zip; //file = await _networkCache.WriteTempCacheFileAsync(await response.Content.ReadAsStreamAsync().AsAsyncOperation().AsTask(cancellationToken), extension, cancellationToken); //using (var stream = await file.OpenStreamForReadAsync().AsAsyncOperation().AsTask(cancellationToken)) //{ result = await LottieCompositionFactory.FromZipStreamAsync( ZipFile.Read(await response.Content.ReadAsStreamAsync()), _url); //} break; case "application/json": default: Debug.WriteLine("Received json response.", LottieLog.Tag); extension = FileExtension.Json; //file = await _networkCache.WriteTempCacheFileAsync(await response.Content.ReadAsStreamAsync().AsAsyncOperation().AsTask(cancellationToken), extension, cancellationToken); //using (var stream = await file.OpenStreamForReadAsync().AsAsyncOperation().AsTask(cancellationToken)) //{ result = await LottieCompositionFactory.FromJsonInputStreamAsync( await response.Content.ReadAsStreamAsync(), _url); //} break; } if (result.Value != null) { await _networkCache.RenameTempFileAsync(extension, cancellationToken); } Debug.WriteLine($"Completed fetch from network. Success: {result.Value != null}", LottieLog.Tag); return(result); } } }
public KeyPathTest() { var task = CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { _lottieDrawable = new LottieDrawable(); LottieComposition composition = LottieCompositionFactory.FromJsonStringSync(Fixtures.Squares, "squares").Value; _lottieDrawable.SetComposition(composition); }).AsTask(); task.Wait(); }
public Form1() { InitializeComponent(); var json = File.ReadAllText("data.json"); var result = LottieCompositionFactory.FromJsonStringSync(json, "lol"); _lottieDrawable.SetComposition(result.Value); _lottieDrawable.RepeatMode = RepeatMode.Restart; _lottieDrawable.RepeatCount = -1; //-1 == infinite _lottieDrawable.AnimatorUpdate += _lottieDrawable_AnimatorUpdate; _lottieDrawable.Start(); }
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(); }
public static LottieComposition FromJsonSync(JsonReader reader) { return(LottieCompositionFactory.FromJsonReaderSync(reader, null).Value); }
public static LottieComposition FromInputStreamSync(Stream stream) { return(LottieCompositionFactory.FromJsonInputStreamSync(stream, null).Value); }
public static LottieComposition FromFileSync(string fileName) { return(LottieCompositionFactory.FromAssetSync(null, fileName).Value); }
public static async Task <LottieComposition> FromJsonReaderAsync(JsonReader reader, CancellationToken cancellationToken = default(CancellationToken)) { return((await LottieCompositionFactory.FromJsonReader(reader, null, cancellationToken)).Value); }
public static async Task <LottieComposition> FromJsonStringAsync(string jsonString, CancellationToken cancellationToken = default(CancellationToken)) { return((await LottieCompositionFactory.FromJsonString(jsonString, null, cancellationToken)).Value); }
public static async Task <LottieComposition> FromInputStreamAsync(Stream stream, CancellationToken cancellationToken = default(CancellationToken)) { return((await LottieCompositionFactory.FromJsonInputStreamAsync(stream, null, cancellationToken)).Value); }
public static async Task <LottieComposition> FromAssetFileNameAsync(string fileName, CancellationToken cancellationToken = default(CancellationToken)) { return((await LottieCompositionFactory.FromAsset(null, fileName, cancellationToken)).Value); }