Skip to content

Commit f02aaab

Browse files
committed
Migrate to common pipelines, bump dependencies in demo
1 parent f6fbf1e commit f02aaab

File tree

6 files changed

+90
-111
lines changed

6 files changed

+90
-111
lines changed

.github/workflows/build-publish.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Build and publish
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
- release/**
9+
paths-ignore:
10+
- Material.Avalonia.Demo*/**
11+
tags:
12+
- v**
13+
14+
jobs:
15+
build-and-test:
16+
uses: SKProCH/CommonWorkflows/.github/workflows/build-publish.yml@main
17+
secrets:
18+
NUGET_KEY: ${{ secrets.NUGET_KEY }}
19+
with:
20+
publish-nightly: false
21+
dotnet-version: 8

.github/workflows/build.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

AsyncImageLoader.Avalonia.Demo/AsyncImageLoader.Avalonia.Demo.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>WinExe</OutputType>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
</PropertyGroup>
77
<ItemGroup>
88
<AvaloniaResource Include="Assets/avalonia-logo.ico" />
99
<None Remove=".gitignore" />
1010
</ItemGroup>
1111
<ItemGroup>
12-
<PackageReference Include="Avalonia" Version="11.0.0" />
13-
<PackageReference Include="Avalonia.Desktop" Version="11.0.0" />
14-
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.0" />
15-
<PackageReference Include="Avalonia.Diagnostics" Version="11.0.0" />
16-
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.0" />
12+
<PackageReference Include="Avalonia" Version="11.1.3" />
13+
<PackageReference Include="Avalonia.Desktop" Version="11.1.3" />
14+
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.3" />
15+
<PackageReference Include="Avalonia.Diagnostics" Version="11.1.3" />
16+
<PackageReference Include="Avalonia.ReactiveUI" Version="11.1.3" />
1717
</ItemGroup>
1818
<ItemGroup>
1919
<ProjectReference Include="..\AsyncImageLoader.Avalonia\AsyncImageLoader.Avalonia.csproj" />

AsyncImageLoader.Avalonia/AdvancedImage.axaml.cs

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using Avalonia.Media.Imaging;
99
using Avalonia.Platform;
1010

11-
namespace AsyncImageLoader;
11+
namespace AsyncImageLoader;
1212

1313
public class AdvancedImage : ContentControl
1414
{
@@ -177,16 +177,18 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
177177
base.OnPropertyChanged(change);
178178
}
179179

180-
private void ClearSourceIfUserProvideImage() {
181-
if (CurrentImage is not null and not ImageWrapper) {
180+
private void ClearSourceIfUserProvideImage()
181+
{
182+
if (CurrentImage is not null and not ImageWrapper)
183+
{
182184
// User provided image himself
183185
Source = null;
184186
}
185187
}
186188

187189
private async void UpdateImage(string? source, IAsyncImageLoader? loader)
188190
{
189-
var cancellationTokenSource = new CancellationTokenSource();
191+
var cancellationTokenSource = new CancellationTokenSource();
190192

191193
var oldCancellationToken = Interlocked.Exchange(ref _updateCancellationToken, cancellationTokenSource);
192194

@@ -197,59 +199,59 @@ private async void UpdateImage(string? source, IAsyncImageLoader? loader)
197199
catch (ObjectDisposedException)
198200
{
199201
}
200-
201-
if (source is null && CurrentImage is not ImageWrapper) {
202+
203+
if (source is null && CurrentImage is not ImageWrapper)
204+
{
202205
// User provided image himself
203206
return;
204207
}
205-
206-
IsLoading = true;
207-
CurrentImage = null;
208-
209-
210-
var bitmap = await Task.Run(async () =>
211-
{
212-
try
213-
{
214-
if (source == null)
215-
return null;
216-
217-
// A small delay allows to cancel early if the image goes out of screen too fast (eg. scrolling)
218-
// The Bitmap constructor is expensive and cannot be cancelled
219-
await Task.Delay(10, cancellationTokenSource.Token);
220-
221-
// Hack to support relative URI
222-
// TODO: Refactor IAsyncImageLoader to support BaseUri
223-
try
224-
{
225-
var uri = new Uri(source, UriKind.RelativeOrAbsolute);
226-
if (AssetLoader.Exists(uri, _baseUri))
208+
209+
IsLoading = true;
210+
CurrentImage = null;
211+
212+
213+
var bitmap = await Task.Run(async () =>
214+
{
215+
try
216+
{
217+
if (source == null)
218+
return null;
219+
220+
// A small delay allows to cancel early if the image goes out of screen too fast (eg. scrolling)
221+
// The Bitmap constructor is expensive and cannot be cancelled
222+
await Task.Delay(10, cancellationTokenSource.Token);
223+
224+
// Hack to support relative URI
225+
// TODO: Refactor IAsyncImageLoader to support BaseUri
226+
try
227+
{
228+
var uri = new Uri(source, UriKind.RelativeOrAbsolute);
229+
if (AssetLoader.Exists(uri, _baseUri))
227230
return new Bitmap(AssetLoader.Open(uri, _baseUri));
228-
}
229-
catch (Exception)
230-
{
231-
// ignored
232-
}
233-
234-
loader ??= ImageLoader.AsyncImageLoader;
235-
return await loader.ProvideImageAsync(source);
236-
}
237-
catch (TaskCanceledException)
238-
{
239-
return null;
240-
}
241-
finally
242-
{
243-
cancellationTokenSource.Dispose();
244-
}
245-
246-
}, CancellationToken.None);
247-
248-
if (cancellationTokenSource.IsCancellationRequested)
231+
}
232+
catch (Exception)
233+
{
234+
// ignored
235+
}
236+
237+
loader ??= ImageLoader.AsyncImageLoader;
238+
return await loader.ProvideImageAsync(source);
239+
}
240+
catch (TaskCanceledException)
241+
{
242+
return null;
243+
}
244+
finally
245+
{
246+
cancellationTokenSource.Dispose();
247+
}
248+
}, CancellationToken.None);
249+
250+
if (cancellationTokenSource.IsCancellationRequested)
249251
return;
250252
CurrentImage = bitmap is null ? null : new ImageWrapper(bitmap);
251253
IsLoading = false;
252-
}
254+
}
253255

254256
private void UpdateCornerRadius(CornerRadius radius)
255257
{
@@ -308,18 +310,23 @@ protected override Size ArrangeOverride(Size finalSize)
308310
? Stretch.CalculateSize(finalSize, CurrentImage.Size)
309311
: base.ArrangeOverride(finalSize);
310312
}
311-
312-
public sealed class ImageWrapper : IImage {
313+
314+
public sealed class ImageWrapper : IImage
315+
{
313316
public IImage ImageImplementation { get; }
314-
internal ImageWrapper(IImage imageImplementation) {
317+
318+
internal ImageWrapper(IImage imageImplementation)
319+
{
315320
ImageImplementation = imageImplementation;
316321
}
322+
317323
/// <inheritdoc />
318-
public void Draw(DrawingContext context, Rect sourceRect, Rect destRect) {
324+
public void Draw(DrawingContext context, Rect sourceRect, Rect destRect)
325+
{
319326
ImageImplementation.Draw(context, sourceRect, destRect);
320327
}
321328

322329
/// <inheritdoc />
323330
public Size Size => ImageImplementation.Size;
324331
}
325-
}
332+
}

AsyncImageLoader.Avalonia/AsyncImageLoader.Avalonia.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Nullable>enable</Nullable>
66
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
77
<RootNamespace>AsyncImageLoader</RootNamespace>
8-
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
8+
99
<Title>AsyncImageLoader.Avalonia</Title>
1010
<Authors>SKProCH</Authors>
1111
<Description>Provides way to asynchronous bitmap loading from web for Avalonia Image control and more</Description>
@@ -15,10 +15,6 @@
1515
<RepositoryType>git</RepositoryType>
1616
<PackageTags>image cross-platform avalonia avaloniaui c-sharp-library</PackageTags>
1717
<PackageReadmeFile>README.md</PackageReadmeFile>
18-
<Version>3.2.1</Version>
19-
<PackageReleaseNotes>
20-
- Fix ObjectDisposedException in Cancellation token access (#19)
21-
</PackageReleaseNotes>
2218
</PropertyGroup>
2319

2420
<ItemGroup>

0 commit comments

Comments
 (0)