-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
ImageSourceServiceResult.cs
85 lines (67 loc) · 1.76 KB
/
ImageSourceServiceResult.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#nullable enable
using System;
#if __IOS__ || MACCATALYST
using PlatformView = UIKit.UIImage;
#elif ANDROID
using PlatformView = Android.Graphics.Drawables.Drawable;
#elif WINDOWS
using PlatformView = Microsoft.UI.Xaml.Media.ImageSource;
#elif TIZEN
using PlatformView = Microsoft.Maui.Platform.MauiImageSource;
#elif (NETSTANDARD || !PLATFORM) || (NET6_0_OR_GREATER && !IOS && !ANDROID && !TIZEN)
using PlatformView = System.Object;
#endif
namespace Microsoft.Maui
{
public class ImageSourceServiceLoadResult : IImageSourceServiceResult
{
Action? _dispose;
public ImageSourceServiceLoadResult()
{
}
public ImageSourceServiceLoadResult(Action? dispose = null)
: this(false, dispose)
{
}
public ImageSourceServiceLoadResult(bool resolutionDependent, Action? dispose = null)
{
IsResolutionDependent = resolutionDependent;
_dispose = dispose;
}
public bool IsResolutionDependent { get; }
public bool IsDisposed { get; private set; }
public void Dispose()
{
if (IsDisposed)
return;
IsDisposed = true;
_dispose?.Invoke();
_dispose = null;
}
}
public class ImageSourceServiceResult : IImageSourceServiceResult<PlatformView>
{
Action? _dispose;
public ImageSourceServiceResult(PlatformView image, Action? dispose = null)
: this(image, false, dispose)
{
}
public ImageSourceServiceResult(PlatformView image, bool resolutionDependent, Action? dispose = null)
{
Value = image;
IsResolutionDependent = resolutionDependent;
_dispose = dispose;
}
public PlatformView Value { get; }
public bool IsResolutionDependent { get; }
public bool IsDisposed { get; private set; }
public void Dispose()
{
if (IsDisposed)
return;
IsDisposed = true;
_dispose?.Invoke();
_dispose = null;
}
}
}