[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
This commit is contained in:
adrianknight89 2019-10-08 10:44:49 -05:00 коммит произвёл Javier Suárez Ruiz
Родитель eff4e4090b
Коммит 51fb38f30b
5 изменённых файлов: 104 добавлений и 2 удалений

Просмотреть файл

@ -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>

Просмотреть файл

@ -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()
{
}
}
}

Просмотреть файл

@ -55,6 +55,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue7519Xaml.xaml.cs"> <Compile Include="$(MSBuildThisFileDirectory)Issue7519Xaml.xaml.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue7758.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue7593.xaml.cs"> <Compile Include="$(MSBuildThisFileDirectory)Issue7593.xaml.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
@ -1418,6 +1421,9 @@
<Compile Update="$(MSBuildThisFileDirectory)Issue7593.xaml.cs"> <Compile Update="$(MSBuildThisFileDirectory)Issue7593.xaml.cs">
<DependentUpon>Issue7593.xaml</DependentUpon> <DependentUpon>Issue7593.xaml</DependentUpon>
</Compile> </Compile>
<Compile Update="$(MSBuildThisFileDirectory)Issue7758.xaml.cs">
<DependentUpon>Issue7758.xaml</DependentUpon>
</Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue1455.xaml"> <EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue1455.xaml">
@ -1479,4 +1485,10 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue7758.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
</ItemGroup>
</Project> </Project>

Просмотреть файл

@ -140,8 +140,13 @@ namespace Xamarin.Forms.Platform.iOS
if (!_initialConstraintsSet) if (!_initialConstraintsSet)
{ {
ItemsViewLayout.ConstrainTo(CollectionView.Bounds.Size); ItemsViewLayout.ConstrainTo(CollectionView.Bounds.Size);
UpdateEmptyView();
_initialConstraintsSet = true; _initialConstraintsSet = true;
} }
else
{
ResizeEmptyView();
}
} }
protected virtual UICollectionViewDelegator CreateDelegator() protected virtual UICollectionViewDelegator CreateDelegator()
@ -267,6 +272,15 @@ namespace Xamarin.Forms.Platform.iOS
UpdateEmptyViewVisibility(ItemsSource?.ItemCount == 0); 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) protected void UpdateSubview(object view, DataTemplate viewTemplate, ref UIView uiView, ref VisualElement formsElement)
{ {
uiView?.RemoveFromSuperview(); uiView?.RemoveFromSuperview();

Просмотреть файл

@ -97,7 +97,6 @@ namespace Xamarin.Forms.Platform.iOS
SetNativeControl(ItemsViewController.View); SetNativeControl(ItemsViewController.View);
ItemsViewController.CollectionView.BackgroundColor = UIColor.Clear; ItemsViewController.CollectionView.BackgroundColor = UIColor.Clear;
ItemsViewController.UpdateEmptyView();
UpdateHorizontalScrollBarVisibility(); UpdateHorizontalScrollBarVisibility();
UpdateVerticalScrollBarVisibility(); UpdateVerticalScrollBarVisibility();