Ejemplo n.º 1
0
        public static Task <UIImage> LoadViaNuke(ImageSource source, CancellationToken token, float scale)
        {
            try
            {
                switch (source)
                {
                case UriImageSource uriSource:
                    return(HandleUriSource(uriSource, token, scale));

                case FileImageSource fileSource:
                    return(FormsHandler.DisableFileImageSourceHandling
                            ? ImageSourceHandler.DefaultFileImageSourceHandler.LoadImageAsync(fileSource, token, scale)
                            : HandleFileSourceAsync(fileSource, token, scale));

                default:
                    FormsHandler.Warn($"Unhandled image source type {source.GetType().Name}");
                    break;
                }
            }
            catch (Exception exception)
            {
                FormsHandler.Warn($"Unexpected exception in Nuke image source handler: {exception}");
            }

            return(Task.FromResult(default(UIImage)));
        }
Ejemplo n.º 2
0
        public static async Task <UIImage> LoadViaNuke(ImageSource source, CancellationToken token)
        {
            try
            {
                switch (source)
                {
                case UriImageSource uriSource:
                    var urlString = uriSource.Uri.OriginalString;
                    if (String.IsNullOrEmpty(urlString))
                    {
                        return(null);
                    }

                    FormsHandler.Debug("Loading `{0}` as a web URL", urlString);
                    return(await LoadImageAsync(new NSUrl(urlString)));

                case FileImageSource fileSource:
                    var fileName = fileSource.File;
                    if (string.IsNullOrEmpty(fileName))
                    {
                        return(null);
                    }

                    FormsHandler.Debug("Loading `{0}` as a file", fileName);
                    NSUrl fileUrl = null;
                    if (File.Exists(fileName))
                    {
                        fileUrl = NSUrl.FromFilename(fileName);;
                    }
                    else
                    {
                        string name      = Path.GetFileNameWithoutExtension(fileName);
                        string extension = Path.GetExtension(fileName);
                        FormsHandler.Debug($"Loading as bundle resource name: {name} with type: {extension}");
                        fileUrl = NSBundle.MainBundle.GetUrlForResource(name, extension);
                        FormsHandler.Debug($"Bundle resource path: {fileUrl.AbsoluteString}");
                    }

                    return(await LoadImageAsync(fileUrl));

                //case StreamImageSource streamImageSource:
                //    FormsHandler.Debug("Loading Image as a stream");
                //    return await LoadStreamAsync(streamImageSource);

                default:
                    FormsHandler.Warn("Unhandled image source type {0}", source.GetType().Name);
                    break;
                }
            }
            catch (Exception exception)
            {
                //Since developers can't catch this themselves, I think we should log it and silently fail
                FormsHandler.Warn("Unexpected exception in FFImageLoading image source handler: {0}", exception);
            }

            return(default(UIImage));
        }
Ejemplo n.º 3
0
        private static Task <UIImage> LoadPlaceholderAsync()
        {
            switch (FormsHandler.PlaceholderImageSource)
            {
            case StreamImageSource streamImageSource:
                FormsHandler.Warn($"loading placeholder from resource");
                return(DefaultStreamImageSourceHandler.LoadImageAsync(streamImageSource));

                ;

            case FontImageSource fontImageSource:
                FormsHandler.Warn($"loading placeholder from Font");
                return(DefaultFontImageSourcehandler.LoadImageAsync(fontImageSource));

            default:
                FormsHandler.Warn($"no valid placeholder found");
                return(null);
            }
        }