From 51fb38f30b7593bffc2cd25b221599010d42c0f9 Mon Sep 17 00:00:00 2001 From: adrianknight89 Date: Tue, 8 Oct 2019 10:44:49 -0500 Subject: [PATCH] [iOS] Alternative proposal for PR 7794 (#7811) * emptyview fix * fix * added collectionview flag * added using for List * fix formatting * fix formatting 2 * fix formatting 3 * fixes * fix test --- .../Issue7758.xaml | 52 ++++++++++++++++++++++ .../Issue7758.xaml.cs | 25 +++++++++++ .../Xamarin.Forms.Controls.Issues.Shared.projitems | 14 +++++- .../CollectionView/ItemsViewController.cs | 14 ++++++ .../CollectionView/ItemsViewRenderer.cs | 1 - 5 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7758.xaml create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7758.xaml.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7758.xaml b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7758.xaml new file mode 100644 index 0000000..3546c7b --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7758.xaml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7758.xaml.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7758.xaml.cs new file mode 100644 index 0000000..2794be7 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7758.xaml.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 7758, "[iOS] EmptyView is not rendered in screen center", PlatformAffected.iOS)] + public partial class Issue7758 : TestContentPage + { + public Issue7758() + { +#if APP + Device.SetFlags(new List { CollectionView.CollectionViewExperimental }); + + InitializeComponent(); +#endif + } + + protected override void Init() + { + + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 9b18114..e11cdf5 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -55,6 +55,9 @@ Code + + Code + Code @@ -1418,6 +1421,9 @@ Issue7593.xaml + + Issue7758.xaml + @@ -1479,4 +1485,10 @@ MSBuild:Compile - + + + Designer + MSBuild:Compile + + + \ No newline at end of file diff --git a/Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewController.cs b/Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewController.cs index f1c9e3d..2066359 100644 --- a/Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewController.cs +++ b/Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewController.cs @@ -140,8 +140,13 @@ namespace Xamarin.Forms.Platform.iOS if (!_initialConstraintsSet) { ItemsViewLayout.ConstrainTo(CollectionView.Bounds.Size); + UpdateEmptyView(); _initialConstraintsSet = true; } + else + { + ResizeEmptyView(); + } } protected virtual UICollectionViewDelegator CreateDelegator() @@ -267,6 +272,15 @@ namespace Xamarin.Forms.Platform.iOS UpdateEmptyViewVisibility(ItemsSource?.ItemCount == 0); } + void ResizeEmptyView() + { + if (_emptyUIView != null) + _emptyUIView.Frame = CollectionView.Frame; + + if (_emptyViewFormsElement != null) + _emptyViewFormsElement.Layout(CollectionView.Frame.ToRectangle()); + } + protected void UpdateSubview(object view, DataTemplate viewTemplate, ref UIView uiView, ref VisualElement formsElement) { uiView?.RemoveFromSuperview(); diff --git a/Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewRenderer.cs b/Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewRenderer.cs index 630351e..837b1d4 100644 --- a/Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewRenderer.cs @@ -97,7 +97,6 @@ namespace Xamarin.Forms.Platform.iOS SetNativeControl(ItemsViewController.View); ItemsViewController.CollectionView.BackgroundColor = UIColor.Clear; - ItemsViewController.UpdateEmptyView(); UpdateHorizontalScrollBarVisibility(); UpdateVerticalScrollBarVisibility(); -- 2.7.4