From 279e4b01a329f59798e7a688e8501814c37e1385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Laval?= Date: Tue, 19 Apr 2016 02:55:42 -0400 Subject: [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. --- .../Renderers/FileImageSourceHandler.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'Xamarin.Forms.Platform.Android') 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 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 -- cgit v1.2.3