[Bug] ListView HasUnevenRows was not working in iOS 10 (#6166)
authorSamantha Houts <samhouts@users.noreply.github.com>
Sat, 11 May 2019 19:08:21 +0000 (12:08 -0700)
committerGitHub <noreply@github.com>
Sat, 11 May 2019 19:08:21 +0000 (12:08 -0700)
* Add repro for #5888

Co-Authored-By: melimion <melimion@users.noreply.github.com>
* [iOS] Fix HasUnevenRows for iOS11+

Co-Authored-By: melimion <melimion@users.noreply.github.com>
fixes #5888

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5888.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs

diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5888.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5888.cs
new file mode 100644 (file)
index 0000000..d76843c
--- /dev/null
@@ -0,0 +1,26 @@
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+namespace Xamarin.Forms.Controls.Issues
+{
+       [Preserve(AllMembers = true)]
+       [Issue(IssueTracker.Github, 5888, "[Bug] ListView HasUnevenRows is not working in iOS 10", PlatformAffected.iOS)]
+       public class Issue5888 : TestContentPage 
+       {
+               protected override void Init()
+               {
+
+                       var stack2 = new StackLayout
+                       {
+                               Children = { new Label { Text = "Hi" }, new Label { Text = "Bye" }, new Label { Text = "Open" } }
+                       };
+                       var listview = new ListView
+                       {
+                               HasUnevenRows = true,
+                               ItemTemplate = new DataTemplate(() => new ViewCell { View = stack2 }),
+                               ItemsSource = new string[] { "mono", "monodroid" }
+                       };
+                       Content = new StackLayout { Children = { listview } };
+               }
+       }
+}
\ No newline at end of file
index 03d7d2d..d996581 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)Issue4356.cs">
       <DependentUpon>Issue4356.xaml</DependentUpon>
     </Compile>
+    <Compile Include="$(MSBuildThisFileDirectory)Issue5888.cs" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
index bbe0a77..613af35 100644 (file)
@@ -711,7 +711,7 @@ namespace Xamarin.Forms.Platform.iOS
 
                        if (_tableViewController != null)
                                _tableViewController.UpdateRefreshControlColor(color == Color.Default ? null : color.ToUIColor());
-    }
+               }
 
                void UpdateVerticalScrollBarVisibility()
                {
@@ -817,11 +817,11 @@ namespace Xamarin.Forms.Platform.iOS
 
                        protected override void UpdateEstimatedRowHeight(UITableView tableView)
                        {
-                               var estimatedRowheight  = GetEstimatedRowHeight(tableView);
+                               var estimatedRowHeight = GetEstimatedRowHeight(tableView);
                                //if we are providing 0 we are disabling EstimatedRowHeight,
                                //this works fine on newer versions, but iOS10 it will cause a crash so we leave the default value
-                               if (estimatedRowheight == 0 && Forms.IsiOS11OrNewer)
-                                       tableView.EstimatedRowHeight = estimatedRowheight;
+                               if (estimatedRowHeight > 0 || (estimatedRowHeight == 0 && Forms.IsiOS11OrNewer))
+                                       tableView.EstimatedRowHeight = estimatedRowHeight;
                        }
 
                        internal Cell GetPrototypicalCell(NSIndexPath indexPath)
@@ -1247,7 +1247,7 @@ namespace Xamarin.Forms.Platform.iOS
                        {
                                UpdateShortNameListener();
 
-                               if(List.OnThisPlatform().RowAnimationsEnabled())
+                               if (List.OnThisPlatform().RowAnimationsEnabled())
                                        _uiTableView.ReloadData();
                                else
                                        PerformWithoutAnimation(() => { _uiTableView.ReloadData(); });
@@ -1551,7 +1551,8 @@ namespace Xamarin.Forms.Platform.iOS
                public override void ViewWillAppear(bool animated)
                {
                        (TableView?.Source as ListViewRenderer.ListViewDataSource)?.Cleanup();
-                       if (!_list.IsRefreshing || !_refresh.Refreshing) return;
+                       if (!_list.IsRefreshing || !_refresh.Refreshing)
+                               return;
 
                        // Restart the refreshing to get the animation to trigger
                        UpdateIsRefreshing(false);