diff options
author | Jérémie Laval <jeremie.laval@gmail.com> | 2016-04-19 02:55:42 -0400 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-04-18 23:55:42 -0700 |
commit | 279e4b01a329f59798e7a688e8501814c37e1385 (patch) | |
tree | 09e560aa1f183c599e646ac0622558f75a9c47a2 /Xamarin.Forms.Platform.Android/Renderers | |
parent | cae3b1a53aa1108cd2ffc07d368b633b52e7d8de (diff) | |
download | xamarin-forms-279e4b01a329f59798e7a688e8501814c37e1385.tar.gz xamarin-forms-279e4b01a329f59798e7a688e8501814c37e1385.tar.bz2 xamarin-forms-279e4b01a329f59798e7a688e8501814c37e1385.zip |
[Android] Allow designer to disable asynchronicity in image loading. (#111)
The XF Previewer doesn't support async operations as it loads a layout and immediately tries to snapshot it.
This commit adds a new property to let designer reflect onto so that the behavior can be specifically made synchronous and image will appear in the final preview.
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Renderers')
-rw-r--r-- | Xamarin.Forms.Platform.Android/Renderers/FileImageSourceHandler.cs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/FileImageSourceHandler.cs b/Xamarin.Forms.Platform.Android/Renderers/FileImageSourceHandler.cs index edf7dc37..93124fef 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/FileImageSourceHandler.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/FileImageSourceHandler.cs @@ -8,10 +8,19 @@ namespace Xamarin.Forms.Platform.Android { public sealed class FileImageSourceHandler : IImageSourceHandler { + // This is set to true when run under designer context + internal static bool DecodeSynchronously { + get; + set; + } + public async Task<Bitmap> LoadImageAsync(ImageSource imagesource, Context context, CancellationToken cancelationToken = default(CancellationToken)) { string file = ((FileImageSource)imagesource).File; - return await (File.Exists(file) ? BitmapFactory.DecodeFileAsync(file) : context.Resources.GetBitmapAsync(file)).ConfigureAwait(false); + if (File.Exists (file)) + return !DecodeSynchronously ? (await BitmapFactory.DecodeFileAsync (file).ConfigureAwait (false)) : BitmapFactory.DecodeFile (file); + else + return !DecodeSynchronously ? (await context.Resources.GetBitmapAsync (file).ConfigureAwait (false)) : context.Resources.GetBitmap (file); } } }
\ No newline at end of file |