3

I am having internet images in my datatemplate of listview as below. It is a simple mvvm binding, I don't use any code behind at all. When scroll fast on the listview, it gets frozen. it looks like it is caused by multiple downloads. maybe deadlock(?) I am using ffimageloading but I tried using XF image and problem occurs using it as well.

I see in the documentation of ffimageloading, it is mentioned about scrollstatechanged event but I cant find this in xamarin forms listview. It seems like suggested solution is native android level. Of course it makes sense not to have it in XF because of it is android specific. Question is How can I utilize this event if this is the solution? If not, Is there any other solution for this issue?

I tested in UWP, flinging doesn't cause any performance or freeze.

 <DataTemplate>
      <Grid ColumnSpacing="0" >
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*"></ColumnDefinition>
             <ColumnDefinition Width="2*"></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*"></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <ffimageloading:CachedImage  RetryCount="1"   TransparencyEnabled = "false"   CacheDuration = "120"
                                                              LoadingPlaceholder="loading.png"   FadeAnimationEnabled="True"    CacheType="Disk" 
                                                              InputTransparent="True"     ErrorPlaceholder="thumb.png"
                                                    Source="{Binding Images, Converter={StaticResource thumbnailConvertor}}"
                             Aspect="AspectFit"  Grid.Row="0" Grid.Column="0"  />
                                    <StackLayout Orientation="Vertical" Grid.Row="0" Grid.Column="1"  >
                                        <Label Text="{Binding name}"  FontSize="20" FontAttributes="Bold"                            

                                    </StackLayout>
                                </Grid>
                            </DataTemplate>

ScrollStateChanged event in Xamarin Android

_

myListView.ScrollStateChanged += (object sender, ScrollStateChangedEventArgs scrollArgs) => {
  switch (scrollArgs.ScrollState)
  {
    case ScrollState.Fling:
      ImageService.Instance.SetPauseWork(true); // all image loading requests will be silently canceled
      break;
    case ScrollState.Idle:
      ImageService.Instance.SetPauseWork(false); // loading requests are allowed again

      // Here you should have your custom method that forces redrawing visible list items
      _myListView.ForcePdfThumbnailsRedraw();
      break;
  }
};

EDIT: Xamarin forms USING 2.3.5 Pre6

I tried using latest pre release as xamarin claims improvements with fast renderers but it seems like things got even worse. listview is getting frozen instantly even without scrolling when the list appears.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Emil
  • 6,411
  • 7
  • 62
  • 112

1 Answers1

0

I know this is an old question, but maybe this can help someone. I can't comment on the ScrollStateChange implementation, but here is a suggestion based on the markup you've provided.

The docs for FFImageLoading suggest avoiding Binding the Source property of the CachedImage view, as it is very slow. Setting the image source at the OnBindingContextChanged event handler instead can have a big performance boost.

Usage in ListView with a lot of elements and ListViewCachingStrategy.RecycleElement enabled (default)