Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ForceUpdateSize ListView issue on iOS

I have a custom ListView using custom ViewCells with radio buttons. On clicking of each of the radio buttons the ListView dynamically resizes its height to hide/show a comment box.

On using ForceUpdateSize in iOS platform, the ListView performance slows down rapidly on clicking the radio buttons. The app eventually hangs and stops responding.

Is there an alternative solution to use instead of ForceUpdateSize to dynamically expand the ListView row at runtime?

like image 858
Apurva19 Avatar asked Jan 10 '18 08:01

Apurva19


1 Answers

Define a ViewCell Size Change event wherever you need to change your ViewCell size

public static event Action ViewCellSizeChangedEvent; 

In your case, it should be triggered by your radio button. Call it like this:

ViewCellSizeChangedEvent?.Invoke();

It will then use the ListView renderer to update the iOS TableView.

public class CustomListViewRenderer : ListViewRenderer
{
    public CustomListViewRenderer()
    {
        WhatEverContentView.ViewCellSizeChangedEvent += UpdateTableView;
    }

    private void UpdateTableView()
    {
        var tv = Control as UITableView;
        if (tv == null) return;
        tv.BeginUpdates();
        tv.EndUpdates();
    }
}

It should solve your performance problem while keep using your Xaml instead of creating a custom ViewCell which is not needed.

like image 155
Duke Y Avatar answered Sep 23 '22 21:09

Duke Y