[iOS] Alternative proposal for PR 7794 (#7811)
authoradrianknight89 <adrianknight89@outlook.com>
Tue, 8 Oct 2019 15:44:49 +0000 (10:44 -0500)
committerJavier Suárez Ruiz <javiersuarezruiz@hotmail.com>
Tue, 8 Oct 2019 15:44:49 +0000 (17:44 +0200)
* emptyview fix

* fix

* added collectionview flag

* added using for List

* fix formatting

* fix formatting 2

* fix formatting 3

* fixes

* fix test

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7758.xaml [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7758.xaml.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/CollectionView/ItemsViewController.cs
Xamarin.Forms.Platform.iOS/CollectionView/ItemsViewRenderer.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 (file)
index 0000000..3546c7b
--- /dev/null
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<controls:TestContentPage  
+    xmlns="http://xamarin.com/schemas/2014/forms"
+    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+    xmlns:d="http://xamarin.com/schemas/2014/forms/design"
+    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+    xmlns:controls="clr-namespace:Xamarin.Forms.Controls"
+    mc:Ignorable="d"
+    x:Class="Xamarin.Forms.Controls.Issues.Issue7758">
+    <ContentPage.Resources>
+        <ResourceDictionary>
+            <Style TargetType="StackLayout" x:Key="StackLayoutStyle">
+                <Setter Property="Orientation" Value="Vertical"/>
+                <Setter Property="HorizontalOptions" Value="Center"/>
+                <Setter Property="VerticalOptions" Value="Center"/>
+                <Setter Property="Padding" Value="20, 0"/>
+                <Setter Property="Spacing" Value="10"/>
+                <Setter Property="BackgroundColor" Value="Wheat"/>
+            </Style>
+        </ResourceDictionary>
+    </ContentPage.Resources>
+    <Grid RowSpacing="0">
+        <Grid.RowDefinitions>
+            <RowDefinition Height="Auto"/>
+            <RowDefinition/>
+            <RowDefinition Height="Auto"/>
+        </Grid.RowDefinitions>
+        
+        <Grid Grid.Row="0" BackgroundColor="Black" Padding="10">
+            <Label Text="If the red line is not between Item 3 and Item 4, the test has failed. Change device orientation to landscape. If the red line is not between Item 3 and Item 4, the test has failed. If there is a visible white background during orientation change, the test has failed." TextColor="White"/>
+        </Grid>
+        
+        <CollectionView Grid.Row="1">
+            <CollectionView.EmptyView>
+                <ContentView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="Beige">
+                    <StackLayout Style="{x:StaticResource StackLayoutStyle}">
+                        <Label Text="Text1" HorizontalTextAlignment="Center" FontAttributes="Bold" FontSize="14.5"/>
+                        <Label Text="Text2" HorizontalTextAlignment="Center" TextColor="#636571" FontSize="14.5"/>
+                        <Label Text="Text3" HorizontalTextAlignment="Center" FontAttributes="Bold" FontSize="14.5"/>
+                        <Label Text="Text4" HorizontalTextAlignment="Center" TextColor="#636571" FontSize="14.5"/>
+                        <Label Text="Text5" HorizontalTextAlignment="Center" FontAttributes="Bold" FontSize="14.5"/>
+                        <Label Text="Text6" HorizontalTextAlignment="Center" TextColor="#636571" FontSize="14.5"/>
+                    </StackLayout>
+                </ContentView>
+            </CollectionView.EmptyView>
+        </CollectionView>
+        
+        <Grid Grid.Row="2" BackgroundColor="Black" HeightRequest="50"/>
+        
+        <Grid Grid.Row="1" BackgroundColor="Red" HeightRequest="5" VerticalOptions="Center"/>
+    </Grid>
+</controls:TestContentPage> 
\ 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 (file)
index 0000000..2794be7
--- /dev/null
@@ -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<string> { CollectionView.CollectionViewExperimental });
+
+                       InitializeComponent();
+#endif
+               }
+
+               protected override void Init()
+               {
+
+               }
+    }
+}
\ No newline at end of file
index 9b18114..e11cdf5 100644 (file)
@@ -55,6 +55,9 @@
     <Compile Include="$(MSBuildThisFileDirectory)Issue7519Xaml.xaml.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="$(MSBuildThisFileDirectory)Issue7758.xaml.cs">
+      <SubType>Code</SubType>
+    </Compile>
     <Compile Include="$(MSBuildThisFileDirectory)Issue7593.xaml.cs">
       <SubType>Code</SubType>
     </Compile>
     <Compile Update="$(MSBuildThisFileDirectory)Issue7593.xaml.cs">
       <DependentUpon>Issue7593.xaml</DependentUpon>
     </Compile>
+    <Compile Update="$(MSBuildThisFileDirectory)Issue7758.xaml.cs">
+      <DependentUpon>Issue7758.xaml</DependentUpon>
+    </Compile>
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue1455.xaml">
       <Generator>MSBuild:Compile</Generator>
     </EmbeddedResource>
   </ItemGroup>
-</Project>
+  <ItemGroup>
+    <EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue7758.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </EmbeddedResource>
+  </ItemGroup>
+</Project>
\ No newline at end of file
index f1c9e3d..2066359 100644 (file)
@@ -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();
index 630351e..837b1d4 100644 (file)
@@ -97,7 +97,6 @@ namespace Xamarin.Forms.Platform.iOS
 
                        SetNativeControl(ItemsViewController.View);
                        ItemsViewController.CollectionView.BackgroundColor = UIColor.Clear;
-                       ItemsViewController.UpdateEmptyView();
                        UpdateHorizontalScrollBarVisibility();
                        UpdateVerticalScrollBarVisibility();