Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 71c62a5

Browse files
authored
[Bug] ListView HasUnevenRows was not working in iOS 10 (#6166)
* Add repro for #5888 Co-Authored-By: melimion <[email protected]> * [iOS] Fix HasUnevenRows for iOS11+ Co-Authored-By: melimion <[email protected]> fixes #5888
1 parent 77fda87 commit 71c62a5

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Xamarin.Forms.CustomAttributes;
2+
using Xamarin.Forms.Internals;
3+
4+
namespace Xamarin.Forms.Controls.Issues
5+
{
6+
[Preserve(AllMembers = true)]
7+
[Issue(IssueTracker.Github, 5888, "[Bug] ListView HasUnevenRows is not working in iOS 10", PlatformAffected.iOS)]
8+
public class Issue5888 : TestContentPage
9+
{
10+
protected override void Init()
11+
{
12+
13+
var stack2 = new StackLayout
14+
{
15+
Children = { new Label { Text = "Hi" }, new Label { Text = "Bye" }, new Label { Text = "Open" } }
16+
};
17+
var listview = new ListView
18+
{
19+
HasUnevenRows = true,
20+
ItemTemplate = new DataTemplate(() => new ViewCell { View = stack2 }),
21+
ItemsSource = new string[] { "mono", "monodroid" }
22+
};
23+
Content = new StackLayout { Children = { listview } };
24+
}
25+
}
26+
}

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems

+1
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@
892892
<Compile Include="$(MSBuildThisFileDirectory)Issue4356.cs">
893893
<DependentUpon>Issue4356.xaml</DependentUpon>
894894
</Compile>
895+
<Compile Include="$(MSBuildThisFileDirectory)Issue5888.cs" />
895896
</ItemGroup>
896897
<ItemGroup>
897898
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">

Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ void UpdateSpinnerColor()
711711

712712
if (_tableViewController != null)
713713
_tableViewController.UpdateRefreshControlColor(color == Color.Default ? null : color.ToUIColor());
714-
}
714+
}
715715

716716
void UpdateVerticalScrollBarVisibility()
717717
{
@@ -817,11 +817,11 @@ internal override void InvalidatingPrototypicalCellCache()
817817

818818
protected override void UpdateEstimatedRowHeight(UITableView tableView)
819819
{
820-
var estimatedRowheight = GetEstimatedRowHeight(tableView);
820+
var estimatedRowHeight = GetEstimatedRowHeight(tableView);
821821
//if we are providing 0 we are disabling EstimatedRowHeight,
822822
//this works fine on newer versions, but iOS10 it will cause a crash so we leave the default value
823-
if (estimatedRowheight == 0 && Forms.IsiOS11OrNewer)
824-
tableView.EstimatedRowHeight = estimatedRowheight;
823+
if (estimatedRowHeight > 0 || (estimatedRowHeight == 0 && Forms.IsiOS11OrNewer))
824+
tableView.EstimatedRowHeight = estimatedRowHeight;
825825
}
826826

827827
internal Cell GetPrototypicalCell(NSIndexPath indexPath)
@@ -1247,7 +1247,7 @@ public void UpdateGrouping()
12471247
{
12481248
UpdateShortNameListener();
12491249

1250-
if(List.OnThisPlatform().RowAnimationsEnabled())
1250+
if (List.OnThisPlatform().RowAnimationsEnabled())
12511251
_uiTableView.ReloadData();
12521252
else
12531253
PerformWithoutAnimation(() => { _uiTableView.ReloadData(); });
@@ -1551,7 +1551,8 @@ public void UpdateShowHideRefresh(bool shouldHide)
15511551
public override void ViewWillAppear(bool animated)
15521552
{
15531553
(TableView?.Source as ListViewRenderer.ListViewDataSource)?.Cleanup();
1554-
if (!_list.IsRefreshing || !_refresh.Refreshing) return;
1554+
if (!_list.IsRefreshing || !_refresh.Refreshing)
1555+
return;
15551556

15561557
// Restart the refreshing to get the animation to trigger
15571558
UpdateIsRefreshing(false);

0 commit comments

Comments
 (0)