IValueConverter on iOS called to often

7 posts, 0 answers
  1. Julian
    Julian avatar
    17 posts
    Member since:
    Aug 2015

    Posted 30 Jan Link to this post

    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

  2. Sascha
    Sascha avatar
    13 posts
    Member since:
    Jan 2017

    Posted 31 Jan in reply to Julian Link to this post

    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.

  3. Julian
    Julian avatar
    17 posts
    Member since:
    Aug 2015

    Posted 31 Jan in reply to Sascha Link to this post

    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

  4. Julian
    Julian avatar
    17 posts
    Member since:
    Aug 2015

    Posted 31 Jan in reply to Sascha Link to this post

    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

  5. Sascha
    Sascha avatar
    13 posts
    Member since:
    Jan 2017

    Posted 01 Feb Link to this post

    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.

  6. Julian
    Julian avatar
    17 posts
    Member since:
    Aug 2015

    Posted 02 Feb Link to this post

    Thanks for your example project Sascha.

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

    Best regards

    Julian

  7. Nikolay Demirev
    Admin
    Nikolay Demirev avatar
    136 posts

    Posted 02 Feb Link to this post

    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
Back to Top