void OnSetImageSource(UIImage?image)
        {
            if (image == null)
            {
                PlatformView.SetImage(null, UIControlState.Normal);
            }
            else
            {
                var maxWidth  = PlatformView.Frame.Width * 0.5f;
                var maxHeight = PlatformView.Frame.Height * 0.5f;

                var resizedImage = MaxResizeSwipeItemIconImage(image, maxWidth, maxHeight);

                try
                {
                    PlatformView.SetImage(resizedImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate), UIControlState.Normal);
                    var tintColor = VirtualView.GetTextColor();

                    if (tintColor != null)
                    {
                        PlatformView.TintColor = tintColor.ToPlatform();
                    }
                }
                catch (Exception)
                {
                    // UIImage ctor throws on file not found if MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure is true;
                    MauiContext?.CreateLogger <SwipeItemMenuItemHandler>()?.LogWarning("Can not load SwipeItem Icon");
                }
            }
        }
Example #2
0
        internal static UIMenu ToPlatformMenu(
            this IList <IMenuElement> menuElements,
            string title,
            IImageSource?imageSource,
            IMauiContext mauiContext,
            IUIMenuBuilder?uIMenuBuilder)
        {
            uIMenuBuilder = uIMenuBuilder ??
                            MauiUIApplicationDelegate.Current.MenuBuilder !;

            UIMenu? platformMenu = null;
            UIImage?uiImage      = imageSource.GetPlatformMenuImage(mauiContext);

            // You can't have two menus at the same level with the same title
            // This locates an existing menu and then will just merge the users
            // menu into it
            if (Enum.TryParse(typeof(UIMenuIdentifier), title, out object?result))
            {
                if (result != null)
                {
                    platformMenu =
                        uIMenuBuilder.GetMenu(((UIMenuIdentifier)result).GetConstant());
                }
            }

            UIMenuElement[] platformMenuElements = new UIMenuElement[menuElements.Count];

            for (int i = 0; i < menuElements.Count; i++)
            {
                var item        = menuElements[i];
                var menuElement = (UIMenuElement)item.ToHandler(mauiContext) !.PlatformView !;
                platformMenuElements[i] = menuElement;
            }

            // This means we are merging into an existing menu
            if (platformMenu != null)
            {
                if (platformMenuElements.Length > 0)
                {
                    var menuContainer =
                        UIMenu.Create(String.Empty,
                                      uiImage,
                                      UIMenuIdentifier.None,
                                      UIMenuOptions.DisplayInline,
                                      platformMenuElements);

                    uIMenuBuilder.InsertChildMenuAtStart(menuContainer, platformMenu.GetIdentifier());
                }
            }
            else
            {
                // This means we are creating our own new menu/submenu
                platformMenu =
                    UIMenu.Create(title, uiImage, UIMenuIdentifier.None,
                                  UIMenuOptions.SingleSelection, platformMenuElements);
            }

            return(platformMenu);
        }
Example #3
0
 void OnSetImageSource(UIImage?image)
 {
     if (image != null)
     {
         PlatformView.SetImage(image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal);
     }
     else
     {
         PlatformView.SetImage(null, UIControlState.Normal);
     }
 }
        private void OnSetImageSourceDrawable(UIImage?image)
        {
            if (image != null)
            {
                NativeView.SetImage(image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal);
            }
            else
            {
                NativeView.SetImage(null, UIControlState.Normal);
            }

            VirtualView.ImageSourceLoaded();
        }
        public async Task <UIImage?> LoadImageAsync(ImageSource imagesource, CancellationToken cancelationToken = default, float scale = 1)
        {
            var fileInfo = await LoadInternal(imagesource, scale, GetCacheDirectory());

            UIImage?image = null;

            try
            {
                await semaphore.WaitAsync();

                if (fileInfo?.Exists ?? false)
                {
                    image = UIImage.FromFile(fileInfo.FullName);
                }
            }
            finally
            {
                semaphore.Release();
            }

            return(image);
        }
        public async Task <UIImage?> LoadImageAsync(ImageSource imagesource, CancellationToken cancelationToken = default(CancellationToken), float scale = 1f)
        {
            UIImage?image       = null;
            var     imageLoader = imagesource as AuthUriImageSource;

            if (imageLoader?.Uri != null)
            {
                using (var streamImage = await imageLoader.GetStreamAsync(cancelationToken).ConfigureAwait(false))
                {
                    if (streamImage != null)
                    {
                        image = UIImage.LoadFromData(NSData.FromStream(streamImage), scale);
                    }
                }
            }

            if (image == null)
            {
                Log.Warning(nameof(AuthUriImageSourceHandler), "Could not load image: {0}", imageLoader);
            }

            return(image);
        }
Example #7
0
 public static void UpdateSource(this UIImageView imageView, UIImage?uIImage, IImageSourcePart image)
 {
     imageView.Image = uIImage;
     imageView.UpdateIsAnimationPlaying(image);
 }
Example #8
0
 void OnSetImageSource(UIImage?obj)
 {
     PlatformView.Image = obj;
 }
 private protected override bool TryOpenSourceSync([NotNullWhen(true)] out UIImage?image)
 {
     image = UIImage.LoadFromData(NSData.FromArray(_buffer));
     return(image != null);
 }
Example #10
0
 void OnSetImageSource(UIImage?obj)
 {
     NativeView.Image = obj;
 }
Example #11
0
        public Builder WithImage(UIImage image)
        {
            _image = image;

            return(this);
        }
Example #12
0
 void OnSetImageSource(UIImage?obj)
 {
     NativeView.SetImage(obj?.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal);
     NativeView.HorizontalAlignment = UIControlContentHorizontalAlignment.Fill;
     NativeView.VerticalAlignment   = UIControlContentVerticalAlignment.Fill;
 }