This is a migrated thread and some comments may be shown as answers.

IValueConverter on iOS called to often

6 Answers 82 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Julian
Top achievements
Rank 1
Julian asked on 30 Jan 2017, 04:13 PM

Hey guys, 

I am currently implementing the Telerik Listview into my Xamarin Forms application.

But I am running into a strange behaviour on iOS. Am using the following IValueConverter

public class ByteArrayToImageConverter : IValueConverter
   {
       public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
       {
           if (value != null)
           {
               return ImageSource.FromStream(() => new MemoryStream((byte[])value));
           }
           return null;
       }
 
       public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
       {
           throw new NotImplementedException();
       }
   }

 

My Listview looks like this:

<telerikDataControls:RadListView
    x:Name="LVUser "
    Grid.Column="0" Grid.Row="0">
      <telerikDataControls:RadListView.LayoutDefinition>
        <telerikListView:ListViewLinearLayout ItemLength="60" />
      </telerikDataControls:RadListView.LayoutDefinition>
      <telerikDataControls:RadListView.GroupHeaderTemplate>
        <DataTemplate>
          <ContentView Style="{StaticResource GroupingHeaderBar}">
            <Label
              Text="{Binding }"
              Style="{StaticResource GroupingHeaderLabel}" />
          </ContentView>
        </DataTemplate>
      </telerikDataControls:RadListView.GroupHeaderTemplate>
      <telerikDataControls:RadListView.ItemTemplate>
        <DataTemplate>
          <telerikListView:ListViewTemplateCell>
            <telerikListView:ListViewTemplateCell.View>
              <Grid Padding="5,1,0,1">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="48"/>
                  <ColumnDefinition Width="*"/>
                  <ColumnDefinition Width="10"/>
                </Grid.ColumnDefinitions>
 
                <ffimageloading:CachedImage
                  Grid.Column="0"
                  HeightRequest="48" WidthRequest="48"
                  x:Name="Picture"
                  Source="{Binding Picture, Converter={StaticResource ByteToImage}}"
                  HorizontalOptions="Start"
                />
 
                <Label
                  Text="{Binding Id, Converter={StaticResource NameConverter}}"
                  Style="{StaticResource MainLabel}"
                  Grid.Column="1"
                  VerticalOptions="CenterAndExpand"/>
 
                <FontAwesome:FontAwesomeIcon
                 x:Name="LblMore"
                 Text="ï„…"
                 Grid.Column="2"
                 Style="{StaticResource MainLabel}"
                 VerticalOptions="CenterAndExpand"
                 HorizontalOptions="EndAndExpand"
             />
 
              </Grid>
            </telerikListView:ListViewTemplateCell.View>
          </telerikListView:ListViewTemplateCell>
        </DataTemplate>
      </telerikDataControls:RadListView.ItemTemplate>
    </telerikDataControls:RadListView>

 

This runs perfectly on Android but on iOS the value converter get's called unlimited times. I am using the current stable nuget package.

The "NameConverter" get's called as often as the other one.

 

Can't I use IValueConverter's?

 

Best regards

Julian

6 Answers, 1 is accepted

Sort by
0
Sascha
Top achievements
Rank 1
answered on 31 Jan 2017, 10:01 AM

Hey Julian,

yes, i have a feeling that the iOS ListView implementation does too much. It slows down everything, and it could have something to do with calling the getter bindings too often.

 

You might try to not use the data binding here, but update the field when the binding context changes within your view.

0
Julian
Top achievements
Rank 1
answered on 31 Jan 2017, 10:06 AM

Hey Sascha, 

I gues you are write and its calling the getter to often.

I removed my IValueConverter's and replaced them with getter's in my Model. Effect stays the same.

Best regards

Julian

0
Julian
Top achievements
Rank 1
answered on 31 Jan 2017, 10:08 AM

Hey Sascha,

I guess you are right. I remoed my IValueConverter's and replaced them with getters in my model. The effect stays the same. 

Best regards

Julian

0
Sascha
Top achievements
Rank 1
answered on 01 Feb 2017, 06:50 AM

Yes, check my checkin for your problem in my POC repository

https://github.com/esskar/TelerikListViewPoc/commit/58b01dc554f09e047872188c9fe20cfd083f1268

if you ran the example, you'll see that the getter is called once for all items in the list during initialisation, and then again for all items that are visible. Adding an item is then worse as it calls the getter for all items again and more.

0
Julian
Top achievements
Rank 1
answered on 02 Feb 2017, 12:57 PM

Thanks for your example project Sascha.

Do you know if the Telerik team aware of this problem?

Best regards

Julian

0
Nikolay Demirev
Telerik team
answered on 02 Feb 2017, 03:31 PM
Hello Julian,

I was able to reproduce the issue, and it is related to the virtualization of the native iOS control. I have logged a public item in our Feedback portal which you can follow in order to receive updates on the matter.

Regards,
Nikolay Demirev
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ListView
Asked by
Julian
Top achievements
Rank 1
Answers by
Sascha
Top achievements
Rank 1
Julian
Top achievements
Rank 1
Nikolay Demirev
Telerik team
Share this question
or