merge tweaks
authorShaneN <shane94@hotmail.com>
Mon, 29 Apr 2019 20:14:45 +0000 (14:14 -0600)
committerShaneN <shane94@hotmail.com>
Mon, 29 Apr 2019 20:14:45 +0000 (14:14 -0600)
Xamarin.Forms.Platform.MacOS/Extensions/NSImageExtensions.cs
Xamarin.Forms.Platform.Tizen/Shell/ShellRenderer.cs
Xamarin.Forms.Platform.iOS/Renderers/ImageElementManager.cs

index 5b59237..24ba4ef 100644 (file)
@@ -22,124 +22,5 @@ namespace Xamarin.Forms.Platform.MacOS
                        resizedImage.UnlockFocus();
                        return resizedImage;
                }
-
-               internal static async Task<NSImage> GetNativeImageAsync(this ImageSource source, CancellationToken cancellationToken = default(CancellationToken))
-               {
-                       if (source == null || source.IsEmpty)
-                               return null;
-
-                       var handler = Internals.Registrar.Registered.GetHandlerForObject<IImageSourceHandler>(source);
-                       if (handler == null)
-                               return null;
-
-                       try
-                       {
-                               return await handler.LoadImageAsync(source, scale: (float)NSScreen.MainScreen.BackingScaleFactor, cancelationToken: cancellationToken);
-                       }
-                       catch (OperationCanceledException)
-                       {
-                               Log.Warning("Image loading", "Image load cancelled");
-                       }
-                       catch (Exception ex)
-                       {
-                               Log.Warning("Image loading", $"Image load failed: {ex}");
-                       }
-
-                       return null;
-               }
-
-               internal static Task ApplyNativeImageAsync(this IVisualElementRenderer renderer, BindableProperty imageSourceProperty, Action<NSImage> onSet, Action<bool> onLoading = null, CancellationToken cancellationToken = default(CancellationToken))
-               {
-                       return renderer.ApplyNativeImageAsync(null, imageSourceProperty, onSet, onLoading, cancellationToken);
-               }
-
-               internal static async Task ApplyNativeImageAsync(this IVisualElementRenderer renderer, BindableObject bindable, BindableProperty imageSourceProperty, Action<NSImage> onSet, Action<bool> onLoading = null, CancellationToken cancellationToken = default(CancellationToken))
-               {
-                       _ = renderer ?? throw new ArgumentNullException(nameof(renderer));
-                       _ = imageSourceProperty ?? throw new ArgumentNullException(nameof(imageSourceProperty));
-                       _ = onSet ?? throw new ArgumentNullException(nameof(onSet));
-
-                       // TODO: it might be good to make sure the renderer has not been disposed
-
-                       // makse sure things are good before we start
-                       var element = bindable ?? renderer.Element;
-
-                       var nativeRenderer = renderer as IVisualNativeElementRenderer;
-
-                       if (element == null || renderer.NativeView == null || (nativeRenderer != null && nativeRenderer.Control == null))
-                               return;
-
-                       onLoading?.Invoke(true);
-                       if (element.GetValue(imageSourceProperty) is ImageSource initialSource && !initialSource.IsEmpty)
-                       {
-                               try
-                               {
-                                       using (var drawable = await initialSource.GetNativeImageAsync(cancellationToken))
-                                       {
-                                               // TODO: it might be good to make sure the renderer has not been disposed
-
-                                               // we are back, so update the working element
-                                               element = bindable ?? renderer.Element;
-
-                                               // makse sure things are good now that we are back
-                                               if (element == null || renderer.NativeView == null || (nativeRenderer != null && nativeRenderer.Control == null))
-                                                       return;
-
-                                               // only set if we are still on the same image
-                                               if (element.GetValue(imageSourceProperty) == initialSource)
-                                                       onSet(drawable);
-                                       }
-                               }
-                               finally
-                               {
-                                       if (element != null && onLoading != null)
-                                       {
-                                               // only mark as finished if we are still on the same image
-                                               if (element.GetValue(imageSourceProperty) == initialSource)
-                                                       onLoading.Invoke(false);
-                                       }
-                               }
-                       }
-                       else
-                       {
-                               onSet(null);
-                               onLoading?.Invoke(false);
-                       }
-               }
-
-               internal static async Task ApplyNativeImageAsync(this BindableObject bindable, BindableProperty imageSourceProperty, Action<NSImage> onSet, Action<bool> onLoading = null, CancellationToken cancellationToken = default(CancellationToken))
-               {
-                       _ = bindable ?? throw new ArgumentNullException(nameof(bindable));
-                       _ = imageSourceProperty ?? throw new ArgumentNullException(nameof(imageSourceProperty));
-                       _ = onSet ?? throw new ArgumentNullException(nameof(onSet));
-
-                       onLoading?.Invoke(true);
-                       if (bindable.GetValue(imageSourceProperty) is ImageSource initialSource)
-                       {
-                               try
-                               {
-                                       using (var nsimage = await initialSource.GetNativeImageAsync(cancellationToken))
-                                       {
-                                               // only set if we are still on the same image
-                                               if (bindable.GetValue(imageSourceProperty) == initialSource)
-                                                       onSet(nsimage);
-                                       }
-                               }
-                               finally
-                               {
-                                       if (onLoading != null)
-                                       {
-                                               // only mark as finished if we are still on the same image
-                                               if (bindable.GetValue(imageSourceProperty) == initialSource)
-                                                       onLoading.Invoke(false);
-                                       }
-                               }
-                       }
-                       else
-                       {
-                               onSet(null);
-                               onLoading?.Invoke(false);
-                       }
-               }
        }
 }
\ No newline at end of file
index 6563fcc..3e9be95 100644 (file)
@@ -156,9 +156,9 @@ namespace Xamarin.Forms.Platform.Tizen
                                        else if (flyoutGroup[j] is MenuItem menuItem)
                                        {
                                                title = menuItem.Text;
-                                               if (menuItem.Icon != null)
+                                               if (menuItem.IconImageSource is FileImageSource source)
                                                {
-                                                       icon = menuItem.Icon.File;
+                                                       icon = source.File;
                                                }
                                        }
 
index a6137a4..1989d91 100644 (file)
@@ -3,7 +3,6 @@ using System.ComponentModel;
 using System.Threading;
 using System.Threading.Tasks;
 using Foundation;
-using UIKit;
 using Xamarin.Forms.Internals;
 
 #if __MOBILE__
@@ -165,12 +164,14 @@ namespace Xamarin.Forms.Platform.MacOS
                        try
                        {
 
+
 #if __MOBILE__
-                                       float scale = (float)UIScreen.MainScreen.Scale;
+                               float scale = (float)UIScreen.MainScreen.Scale;
 #else
-                                       float scale = (float)NSScreen.MainScreen.BackingScaleFactor;
+                               float scale = (float)NSScreen.MainScreen.BackingScaleFactor;
 #endif
-                               return await handler.LoadImageAsync(source, scale: (float)UIScreen.MainScreen.Scale, cancelationToken: cancellationToken);
+
+                               return await handler.LoadImageAsync(source, scale: scale, cancelationToken: cancellationToken);
                        }
                        catch (OperationCanceledException)
                        {
@@ -184,6 +185,7 @@ namespace Xamarin.Forms.Platform.MacOS
                        return null;
                }
 
+#if __MOBILE__
                internal static Task ApplyNativeImageAsync(this IShellContext shellContext, BindableObject bindable, BindableProperty imageSourceProperty, Action<UIImage> onSet, Action<bool> onLoading = null, CancellationToken cancellationToken = default(CancellationToken))
                {
                        _ = shellContext ?? throw new ArgumentNullException(nameof(shellContext));
@@ -191,13 +193,13 @@ namespace Xamarin.Forms.Platform.MacOS
 
                        return renderer.ApplyNativeImageAsync(bindable, imageSourceProperty, onSet, onLoading, cancellationToken);
                }
-
-               internal static Task ApplyNativeImageAsync(this IVisualElementRenderer renderer, BindableProperty imageSourceProperty, Action<UIImage> onSet, Action<bool> onLoading = null, CancellationToken cancellationToken = default(CancellationToken))
+#endif
+               internal static Task ApplyNativeImageAsync(this IVisualElementRenderer renderer, BindableProperty imageSourceProperty, Action<NativeImage> onSet, Action<bool> onLoading = null, CancellationToken cancellationToken = default(CancellationToken))
                {
                        return renderer.ApplyNativeImageAsync(null, imageSourceProperty, onSet, onLoading, cancellationToken);
                }
 
-               internal static async Task ApplyNativeImageAsync(this IVisualElementRenderer renderer, BindableObject bindable, BindableProperty imageSourceProperty, Action<UIImage> onSet, Action<bool> onLoading = null, CancellationToken cancellationToken = default(CancellationToken))
+               internal static async Task ApplyNativeImageAsync(this IVisualElementRenderer renderer, BindableObject bindable, BindableProperty imageSourceProperty, Action<NativeImage> onSet, Action<bool> onLoading = null, CancellationToken cancellationToken = default(CancellationToken))
                {
                        _ = renderer ?? throw new ArgumentNullException(nameof(renderer));
                        _ = imageSourceProperty ?? throw new ArgumentNullException(nameof(imageSourceProperty));
@@ -251,7 +253,7 @@ namespace Xamarin.Forms.Platform.MacOS
                        }
                }
 
-               internal static async Task ApplyNativeImageAsync(this BindableObject bindable, BindableProperty imageSourceProperty, Action<UIImage> onSet, Action<bool> onLoading = null, CancellationToken cancellationToken = default(CancellationToken))
+               internal static async Task ApplyNativeImageAsync(this BindableObject bindable, BindableProperty imageSourceProperty, Action<NativeImage> onSet, Action<bool> onLoading = null, CancellationToken cancellationToken = default(CancellationToken))
                {
                        _ = bindable ?? throw new ArgumentNullException(nameof(bindable));
                        _ = imageSourceProperty ?? throw new ArgumentNullException(nameof(imageSourceProperty));