xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

ListView iOS - height isn't updated if a child's visibility changed #4184

Open nk54 opened 6 years ago

nk54 commented 6 years ago

Description

ListView on iOS is still a nightmare... Having a sub element inside the cell's dataTemplate which has its visibility binded won't update its height... Tired of doing workaround or telling every Xamarin Forms haters that it will work someday...

Steps to Reproduce

Have a ListView bounded to a list of item where the item has a IsVisible or IsSelected property with INPC. Have a template like this :

<DataTemplate>

    <StackLayout>
        <!-- some content always visible -->
        <StackLayout IsVisible="{Binding IsVisible or IsSelected}">
            <!-- some contextual content-->
        </StackLayout>
    </StackLayout>
</DataTemplate>

You can replace the StackLayout with a Grid and rows with height="Auto" it will result the same.

Expected Behavior

The height of the cell should be updated. Or at least there should be an available property / event / method to tell the listView that a particularCell(object particularCell == SelectedItemIfNothingProvidedInParameter).

Actual Behavior

The height isn't updated and the contextual / additional content isn't displayed.

Basic Information

Screenshots

image

ianvink commented 5 years ago

I can confirm this also happens to our apps

AtosNicoS commented 5 years ago

I have a similar setup and the same problem - on android. Sometimes the items show up correctly, sometimes not. The weird thing is, if I comment out some unrelated code, the visibly property behaves differently. I am not happy about that statement, but I got no reproducible case that I could share with you :(

Edit: If I scrol up and down, so the list gets re-rendered it shows up correctly. Its definitely not a bug of my code :-/

adrianknight89 commented 5 years ago

Dynamic cell height does not work on iOS. This has been an ongoing issue that was never truly fixed. Similar issues that could be closed together:

https://github.com/xamarin/Xamarin.Forms/issues/4905 https://github.com/xamarin/Xamarin.Forms/issues/2555 https://github.com/xamarin/Xamarin.Forms/issues/2383

ianvink commented 5 years ago

I found a way (hack for now). After a value that needs the cell to recalculate height has been changed, I do this:

`
ListView.HasUnevenRows = false;

 ListView.HasUnevenRows = true;

`

kelvincwk commented 5 years ago

This is not an issue on the Android but only iOS.

The following have been tried:-

HasUnevenRows

I have similar problems and for once touching the ListView.HasUnevenRows=false then back to true it worked in XF 3.4.0.1008975 until recently we gave it an update to XF 3.6.0.293080, the list has gone messed up the all row heights are not calculated properly - hence HasUnevenRows is only making things worse.

ForceUpdateSize()

Another suggestion to call ForceUpdateSize on the viewcell of the list item. This gives me another problem depending on the caching strategy setting:-

If I set ListView.CachingStrategy = RetainElement, calling ForceUpdateSize() the 3rd or 4th time it freezes the UI;

If I set ListView.CachingStrategy = RecycleElement, calling ForceUpdateSize() the first few times works perfectly but as I scrolled down , calling it will cause the list jumping up and down.

The ForceUpdateSize() issue has been reported here https://forums.xamarin.com/discussion/123437/forceupdatesize-slows-ui and possibly at some other posts.

Attempted work around:-

Second thought would be to write ListViewRenderer custom renderer on iOS only. Use messaging pattern or custom bindable property to listen to changes and call ((UITableView) Control).ReloadData() to update table.

Would appreciate if there is any workaround or permanent fix that can be done better.

gregwoodsit commented 5 years ago

This issue is also affecting me after update to XF 3.6.0.293080.

ForceUpdateSize() and playing with heights seems to work on first load, however animation starts freezing after a couple of tries.

ivanicin commented 5 years ago

If it helps for a quicker fix, here is a sample code, I wanted to submit a new bug but I can see it is submitted already.

CellHeightTest.zip