Xamarin: FFImageLoading not showing using inside list view on iOS

806 views Asked by At

I am currently using FFImageLoading library on a listView inside the custom data template.

<ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <ViewCell.ContextActions>
                                <MenuItem Clicked="OnDelete" CommandParameter="{Binding .}" Text="Delete" IsDestructive="True" />
                            </ViewCell.ContextActions>
                            <StackLayout
                                Padding="12,10,12,10" 
                                BackgroundColor="Transparent"
                                Orientation="Horizontal">
                                <Image
                                    DownsampleToViewSize="true"
                                    Aspect="AspectFit"
                                    Source="{Binding FileThumbnail, Converter={StaticResource mimeTypeToImageConverter}}"
                                    WidthRequest="60"
                                    HeightRequest="60">
                                </Image>

Inside the mimeTypeToImageConverter:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is string)
        {
            var file = (string)value;     

            if (FileUtilities.IsImageType(file))
            {
                //var fileImageSource = new FileImageSource();
                //fileImageSource.File = file;
                var imageSource = ImageSource.FromFile(file);
                return imageSource;
            } 
            else {
                return ImageSource.FromFile("ic_file_white.png");
            }

        } 
        return null;
    }

I used on android but android works fine. When I change back to Image control, the iOS will show the image.

I really need it to reduce the image size. Does any of you got that problem before.

2

There are 2 answers

0
bball On

Instead of using the Image Control, you need to use the FFImageLoading Control

Change

<Image>...</Image>

to

<forms:CachedImage>...</forms:CachedImage>

Also add the namespace

<ContentPage xmlns:forms="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms">

CachedImage should have all of the same properties as Image

Oops forgot to mention, you will need to add DownsampleHeight or DownsampleWidth to reduce the size as well.

1
Artem Zelinskiy On

Are trying do download images by http, not https?

You need to add folowing to your info.plist

<key>NSAppTransportSecurity</key>
<dict>
  <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>