Shapes on iOS fail to render if the bounds of the view is set prior to renderer creation (#13284) fixes #12245 fixes #13225 fixes #12911 fixes #13096 fixes #13164 fixes #11924 fixes #11656 fixes #12844 fixes #12521 fixes #13407
* UI Test * Render Shape if it has an initial size already set * - fix ui tests * Unified issues with the same fix. Co-authored-by: Javier Suárez Ruiz <javiersuarezruiz@hotmail.com>
This commit is contained in:
Родитель
4438439991
Коммит
26a9f00c0e
|
@ -0,0 +1,87 @@
|
|||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
using Xamarin.Forms.Shapes;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.Forms.Core.UITests;
|
||||
using Xamarin.UITest;
|
||||
using NUnit.Framework;
|
||||
#endif
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
{
|
||||
#if UITEST
|
||||
[Category(UITestCategories.Shape)]
|
||||
#endif
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Github, 11924, "[Bug] Shapes not loading in Xamarin ShellContent Tab once it is navigated back from other Tab",
|
||||
PlatformAffected.All)]
|
||||
public class Issue11924 : TestShell
|
||||
{
|
||||
const string Test1 = "Test 1";
|
||||
const string Test2 = "Test 2";
|
||||
|
||||
public Issue11924()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
AddBottomTab(CreatePage1(Test1), Test1);
|
||||
AddBottomTab(CreatePage2(Test2), Test2);
|
||||
|
||||
static ContentPage CreatePage1(string title)
|
||||
{
|
||||
var layout = new StackLayout();
|
||||
|
||||
var instructions = new Label
|
||||
{
|
||||
Padding = 12,
|
||||
BackgroundColor = Color.Black,
|
||||
TextColor = Color.White,
|
||||
Text = "Navigate to the second Tab"
|
||||
};
|
||||
|
||||
var ellipse = new Ellipse
|
||||
{
|
||||
HorizontalOptions = LayoutOptions.Start,
|
||||
HeightRequest = 50,
|
||||
WidthRequest = 100,
|
||||
Fill = Brush.Red
|
||||
};
|
||||
|
||||
layout.Children.Add(instructions);
|
||||
layout.Children.Add(ellipse);
|
||||
|
||||
return new ContentPage
|
||||
{
|
||||
Title = title,
|
||||
Content = layout
|
||||
};
|
||||
}
|
||||
|
||||
static ContentPage CreatePage2(string title)
|
||||
{
|
||||
var layout = new StackLayout();
|
||||
|
||||
var instructions = new Label
|
||||
{
|
||||
Padding = 12,
|
||||
BackgroundColor = Color.Black,
|
||||
TextColor = Color.White,
|
||||
Text = "Navigate back to the first tab, and verify if the Ellipse is rendering or not."
|
||||
};
|
||||
|
||||
layout.Children.Add(instructions);
|
||||
|
||||
return new ContentPage
|
||||
{
|
||||
Title = title,
|
||||
Content = layout
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<controls:TestContentPage
|
||||
xmlns:controls="clr-namespace:Xamarin.Forms.Controls"
|
||||
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"
|
||||
mc:Ignorable="d"
|
||||
x:Class="Xamarin.Forms.Controls.Issues.Issue12521"
|
||||
Title="Issue 12521">
|
||||
<StackLayout>
|
||||
<Label
|
||||
Padding="12"
|
||||
BackgroundColor="Black"
|
||||
TextColor="White"
|
||||
Text="Scroll the list up and down. If the shapes not disappear, the test has passed."/>
|
||||
<ListView
|
||||
SelectionMode="None"
|
||||
SeparatorColor="Transparent"
|
||||
BackgroundColor="Transparent"
|
||||
HasUnevenRows="True">
|
||||
<ListView.ItemsSource>
|
||||
<x:Array Type="{x:Type x:String}">
|
||||
<x:String>1</x:String>
|
||||
<x:String>2</x:String>
|
||||
<x:String>3</x:String>
|
||||
<x:String>4</x:String>
|
||||
<x:String>5</x:String>
|
||||
<x:String>6</x:String>
|
||||
<x:String>7</x:String>
|
||||
<x:String>8</x:String>
|
||||
<x:String>9</x:String>
|
||||
<x:String>10</x:String>
|
||||
<x:String>11</x:String>
|
||||
<x:String>12</x:String>
|
||||
<x:String>13</x:String>
|
||||
<x:String>14</x:String>
|
||||
<x:String>15</x:String>
|
||||
<x:String>16</x:String>
|
||||
<x:String>17</x:String>
|
||||
<x:String>18</x:String>
|
||||
<x:String>19</x:String>
|
||||
<x:String>20</x:String>
|
||||
</x:Array>
|
||||
</ListView.ItemsSource>
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell>
|
||||
<!-- Bug -->
|
||||
<Frame>
|
||||
<Path
|
||||
Aspect="Uniform"
|
||||
Data="M79.832501,980.76073L94.683501,965.90873 102.8065,974.03373 106.00049,946.36273 78.328501,949.55573 86.453501,957.67873 71.600501,972.53073C54.154501,959.13273 28.988501,960.40073 13.021501,976.36773 -4.34050019999999,993.73073 -4.34050019999999,1021.9787 13.021501,1039.3407 30.382501,1056.7027 58.632501,1056.7027 75.994501,1039.3407 91.959501,1023.3737 93.230501,998.20573 79.832501,980.76073z M21.251501,1031.1087C8.42850079999999,1018.2867 8.42750079999999,997.42273 21.251501,984.59773 34.073501,971.77573 54.938501,971.77573 67.762501,984.59773 80.585501,997.42273 80.585501,1018.2867 67.762501,1031.1087 54.938501,1043.9317 34.074501,1043.9317 21.251501,1031.1087z"
|
||||
Fill="Black"
|
||||
HeightRequest="24"
|
||||
HorizontalOptions="Start"
|
||||
VerticalOptions="Start"
|
||||
WidthRequest="24" />
|
||||
</Frame>
|
||||
<!-- Non bug -->
|
||||
<!--
|
||||
<Grid>
|
||||
<Path
|
||||
Aspect="Uniform"
|
||||
Data="M79.832501,980.76073L94.683501,965.90873 102.8065,974.03373 106.00049,946.36273 78.328501,949.55573 86.453501,957.67873 71.600501,972.53073C54.154501,959.13273 28.988501,960.40073 13.021501,976.36773 -4.34050019999999,993.73073 -4.34050019999999,1021.9787 13.021501,1039.3407 30.382501,1056.7027 58.632501,1056.7027 75.994501,1039.3407 91.959501,1023.3737 93.230501,998.20573 79.832501,980.76073z M21.251501,1031.1087C8.42850079999999,1018.2867 8.42750079999999,997.42273 21.251501,984.59773 34.073501,971.77573 54.938501,971.77573 67.762501,984.59773 80.585501,997.42273 80.585501,1018.2867 67.762501,1031.1087 54.938501,1043.9317 34.074501,1043.9317 21.251501,1031.1087z"
|
||||
Fill="Black"
|
||||
HeightRequest="24"
|
||||
HorizontalOptions="Start"
|
||||
VerticalOptions="Start"
|
||||
WidthRequest="24" />
|
||||
</Grid>
|
||||
-->
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</StackLayout>
|
||||
</controls:TestContentPage>
|
|
@ -0,0 +1,37 @@
|
|||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
using Xamarin.UITest.Queries;
|
||||
using NUnit.Framework;
|
||||
using Xamarin.Forms.Core.UITests;
|
||||
#endif
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
{
|
||||
#if UITEST
|
||||
[Category(UITestCategories.Shape)]
|
||||
#endif
|
||||
#if APP
|
||||
[XamlCompilation(XamlCompilationOptions.Compile)]
|
||||
#endif
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Github, 12521, "[Bug][iOS] Shapes disappear in a Frame in a ListView when scrolled",
|
||||
PlatformAffected.iOS)]
|
||||
public partial class Issue12521 : TestContentPage
|
||||
{
|
||||
public Issue12521()
|
||||
{
|
||||
#if APP
|
||||
InitializeComponent();
|
||||
#endif
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<local: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"
|
||||
mc:Ignorable="d"
|
||||
xmlns:local="using:Xamarin.Forms.Controls"
|
||||
x:Class="Xamarin.Forms.Controls.Issues.Issue12911"
|
||||
Title="Issue 12911">
|
||||
<ScrollView>
|
||||
<StackLayout>
|
||||
<Label
|
||||
Padding="12"
|
||||
BackgroundColor="Black"
|
||||
TextColor="White"
|
||||
Text="Open the SwipeView, if can see the Red Shape, the test has passed."/>
|
||||
<StackLayout
|
||||
Padding="12">
|
||||
<CollectionView x:Name="CollectionView">
|
||||
<CollectionView.ItemsSource>
|
||||
<x:Array Type="{x:Type x:String}">
|
||||
<x:String>Item 1</x:String>
|
||||
<x:String>Item 2</x:String>
|
||||
<x:String>Item 3</x:String>
|
||||
</x:Array>
|
||||
</CollectionView.ItemsSource>
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackLayout Spacing="0">
|
||||
<SwipeView Padding="0">
|
||||
<SwipeView.LeftItems>
|
||||
<SwipeItems>
|
||||
<SwipeItemView>
|
||||
<Grid
|
||||
HeightRequest="60"
|
||||
WidthRequest="100"
|
||||
RowSpacing="0"
|
||||
ColumnSpacing="0"
|
||||
Padding="0"
|
||||
Margin="0"
|
||||
BackgroundColor="LightGray">
|
||||
<StackLayout
|
||||
Orientation="Horizontal"
|
||||
Padding="0"
|
||||
Margin="0"
|
||||
Spacing="0">
|
||||
<Label
|
||||
Text="Left"
|
||||
HorizontalOptions="Center"
|
||||
VerticalOptions="Center" />
|
||||
<Path
|
||||
HorizontalOptions="EndAndExpand"
|
||||
Fill="Red"
|
||||
Stroke="Red"
|
||||
Aspect="Fill"
|
||||
Data="m0.19956,-0.20844l14.43749,0l0,0c7.97347,0 14.43748,6.51981 14.43748,14.56254c0,8.04265 -6.464,14.5625 -14.43748,14.5625l-14.43749,0l0,-29.12504z" >
|
||||
<Path.RenderTransform>
|
||||
<RotateTransform
|
||||
CenterX="14.637"
|
||||
CenterY="14.3541"
|
||||
Angle="180" />
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
</StackLayout>
|
||||
</Grid>
|
||||
</SwipeItemView>
|
||||
</SwipeItems>
|
||||
</SwipeView.LeftItems>
|
||||
<SwipeView.RightItems>
|
||||
<SwipeItems>
|
||||
<SwipeItemView>
|
||||
<Grid
|
||||
HeightRequest="60"
|
||||
WidthRequest="100"
|
||||
RowSpacing="0"
|
||||
ColumnSpacing="0"
|
||||
BackgroundColor="LightGray">
|
||||
<StackLayout
|
||||
Orientation="Horizontal">
|
||||
<Path
|
||||
Fill="Red"
|
||||
Stroke="Red"
|
||||
Aspect="Fill"
|
||||
Data="m-0.05044,-0.08344l14.43749,0l0,0c7.97347,0 14.43748,6.51981 14.43748,14.56254c0,8.04265 -6.464,14.5625 -14.43748,14.5625l-14.43749,0l0,-29.12504z" />
|
||||
<Label
|
||||
Text="Right"
|
||||
HorizontalOptions="Center"
|
||||
VerticalOptions="Center" />
|
||||
</StackLayout>
|
||||
</Grid>
|
||||
</SwipeItemView>
|
||||
</SwipeItems>
|
||||
</SwipeView.RightItems>
|
||||
<StackLayout
|
||||
Padding="10"
|
||||
BackgroundColor="White">
|
||||
<Label
|
||||
Text="{Binding}"/>
|
||||
</StackLayout>
|
||||
</SwipeView>
|
||||
<BoxView
|
||||
HeightRequest="0.5"
|
||||
BackgroundColor="LightGray"
|
||||
VerticalOptions="End"/>
|
||||
</StackLayout>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
</local:TestContentPage>
|
|
@ -0,0 +1,32 @@
|
|||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.Forms.Core.UITests;
|
||||
using Xamarin.UITest;
|
||||
using NUnit.Framework;
|
||||
#endif
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
{
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Github, 12911, "[Bug] Shapes in SwipeView of a CollectionView/ListView has several issues",
|
||||
PlatformAffected.Android | PlatformAffected.iOS)]
|
||||
#if UITEST
|
||||
[NUnit.Framework.Category(UITestCategories.Brush)]
|
||||
#endif
|
||||
public partial class Issue12911 : TestContentPage
|
||||
{
|
||||
public Issue12911()
|
||||
{
|
||||
#if APP
|
||||
InitializeComponent();
|
||||
#endif
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
using Xamarin.Forms.Shapes;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.Forms.Core.UITests;
|
||||
using Xamarin.UITest;
|
||||
using NUnit.Framework;
|
||||
#endif
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
{
|
||||
#if UITEST
|
||||
[Category(UITestCategories.Shape)]
|
||||
#endif
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Github, 13164, "[Bug] Shapes broken in Xamarin if used within NavigationPage once and navigated back",
|
||||
PlatformAffected.Android | PlatformAffected.iOS)]
|
||||
public class Issue13164 : TestContentPage
|
||||
{
|
||||
Issue13164SecondPage _issue13164SecondPage;
|
||||
|
||||
public Issue13164()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
Title = "Issue 13164";
|
||||
|
||||
var layout = new StackLayout();
|
||||
|
||||
var instructions = new Label
|
||||
{
|
||||
Padding = 12,
|
||||
BackgroundColor = Color.Black,
|
||||
TextColor = Color.White,
|
||||
Text = "Tap the Button to navigate to the details page with some Shapes."
|
||||
};
|
||||
|
||||
var navigateButton = new Button
|
||||
{
|
||||
Text = "Navigate"
|
||||
};
|
||||
|
||||
layout.Children.Add(instructions);
|
||||
layout.Children.Add(navigateButton);
|
||||
|
||||
Content = layout;
|
||||
|
||||
navigateButton.Clicked += (sender, args) =>
|
||||
{
|
||||
if (_issue13164SecondPage == null)
|
||||
{
|
||||
_issue13164SecondPage = new Issue13164SecondPage();
|
||||
}
|
||||
|
||||
var navPage = new NavigationPage(_issue13164SecondPage);
|
||||
Navigation.PushAsync(navPage);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[Preserve(AllMembers = true)]
|
||||
public class Issue13164SecondPage : ContentPage
|
||||
{
|
||||
public Issue13164SecondPage()
|
||||
{
|
||||
var layout = new StackLayout();
|
||||
|
||||
var instructions = new Label
|
||||
{
|
||||
Padding = 12,
|
||||
BackgroundColor = Color.Black,
|
||||
TextColor = Color.White,
|
||||
Text = "Navigate back, and navigate again to this page several times. If shapes are always rendered, the test has passed."
|
||||
};
|
||||
|
||||
var ellipse = new Ellipse
|
||||
{
|
||||
HorizontalOptions = LayoutOptions.Start,
|
||||
Stroke = Brush.DarkBlue,
|
||||
Fill = Brush.BlueViolet,
|
||||
HeightRequest = 50,
|
||||
WidthRequest = 100
|
||||
};
|
||||
|
||||
var rectangle = new Shapes.Rectangle
|
||||
{
|
||||
HorizontalOptions = LayoutOptions.Start,
|
||||
StrokeThickness = 3,
|
||||
Stroke = Brush.DarkOliveGreen,
|
||||
Fill = Brush.Orange,
|
||||
HeightRequest = 80,
|
||||
WidthRequest = 120
|
||||
};
|
||||
|
||||
layout.Children.Add(instructions);
|
||||
layout.Children.Add(ellipse);
|
||||
layout.Children.Add(rectangle);
|
||||
|
||||
Content = layout;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -658,6 +658,34 @@ namespace Xamarin.Forms.Controls
|
|||
content.Route = content.Title;
|
||||
}
|
||||
|
||||
public ContentPage AddBottomTab(ContentPage page, string title, string icon = null)
|
||||
{
|
||||
if (Items.Count == 0)
|
||||
{
|
||||
var item = AddContentPage(page);
|
||||
item.Items[0].Items[0].Title = title ?? page.Title;
|
||||
item.Items[0].Title = title ?? page.Title;
|
||||
return page;
|
||||
}
|
||||
|
||||
Items[0].Items.Add(new ShellSection()
|
||||
{
|
||||
AutomationId = title,
|
||||
Route = title,
|
||||
Title = title,
|
||||
Icon = icon,
|
||||
Items =
|
||||
{
|
||||
new ShellContent()
|
||||
{
|
||||
ContentTemplate = new DataTemplate(() => page),
|
||||
Title = title
|
||||
}
|
||||
}
|
||||
});
|
||||
return page;
|
||||
}
|
||||
|
||||
public ContentPage AddBottomTab(string title, string icon = null)
|
||||
{
|
||||
ContentPage page = new ContentPage();
|
||||
|
|
|
@ -1696,6 +1696,10 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)Issue8833.xaml.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue10086.xaml.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue13136.xaml.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue13164.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue11924.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue12521.xaml.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue12911.xaml.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ShellFlyoutBackground.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ShellFlyoutContentOffest.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ShellFlyoutContentWithZeroMargin.cs" />
|
||||
|
@ -2086,6 +2090,12 @@
|
|||
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue13136.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue12521.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue12911.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla27417Xaml.xaml">
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Xamarin.Forms.Platform.Android
|
|||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<Ellipse> args)
|
||||
{
|
||||
if (Control == null)
|
||||
if (Control == null && args.NewElement != null)
|
||||
{
|
||||
SetNativeControl(new EllipseView(Context));
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Xamarin.Forms.Platform.Android
|
|||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<Line> args)
|
||||
{
|
||||
if (Control == null)
|
||||
if (Control == null && args.NewElement != null)
|
||||
{
|
||||
SetNativeControl(new LineView(Context));
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Xamarin.Forms.Platform.Android
|
|||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<Path> args)
|
||||
{
|
||||
if (Control == null)
|
||||
if (Control == null && args.NewElement != null)
|
||||
{
|
||||
SetNativeControl(new PathView(Context));
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Xamarin.Forms.Platform.Android
|
|||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<Polygon> args)
|
||||
{
|
||||
if (Control == null)
|
||||
if (Control == null && args.NewElement != null)
|
||||
{
|
||||
SetNativeControl(new PolygonView(Context));
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Xamarin.Forms.Platform.Android
|
|||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<Polyline> args)
|
||||
{
|
||||
if (Control == null)
|
||||
if (Control == null && args.NewElement != null)
|
||||
{
|
||||
SetNativeControl(new PolylineView(Context));
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Xamarin.Forms.Platform.Android
|
|||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<FormsRectangle> args)
|
||||
{
|
||||
if (Control == null)
|
||||
if (Control == null && args.NewElement != null)
|
||||
{
|
||||
SetNativeControl(new RectView(Context));
|
||||
}
|
||||
|
|
|
@ -41,6 +41,13 @@ namespace Xamarin.Forms.Platform.Android
|
|||
UpdateStrokeLineCap();
|
||||
UpdateStrokeLineJoin();
|
||||
UpdateStrokeMiterLimit();
|
||||
|
||||
if (!args.NewElement.Bounds.IsEmpty)
|
||||
{
|
||||
_height = Element.Height;
|
||||
_width = Element.Width;
|
||||
UpdateSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using CoreGraphics;
|
||||
using NUnit.Framework;
|
||||
using UIKit;
|
||||
|
@ -14,6 +15,13 @@ namespace Xamarin.Forms.Platform.iOS.UnitTests
|
|||
return $"Expected {expectedColor} at point {x},{y} in renderered view. This is what it looked like:<img>{imageAsString}</img>";
|
||||
}
|
||||
|
||||
public static string CreateColorError(this UIImage bitmap, string message)
|
||||
{
|
||||
var data = bitmap.AsPNG();
|
||||
var imageAsString = data.GetBase64EncodedString(Foundation.NSDataBase64EncodingOptions.None);
|
||||
return $"{message}. This is what it looked like:<img>{imageAsString}</img>";
|
||||
}
|
||||
|
||||
public static UIImage ToBitmap(this UIView view)
|
||||
{
|
||||
var imageRect = new CGRect(0, 0, view.Frame.Width, view.Frame.Height);
|
||||
|
@ -151,5 +159,53 @@ namespace Xamarin.Forms.Platform.iOS.UnitTests
|
|||
var bitmap = view.ToBitmap();
|
||||
return bitmap.AssertColorAtTopRight(expectedColor);
|
||||
}
|
||||
|
||||
public static UIImage AssertContainsColor(this UIView view, UIColor expectedColor)
|
||||
{
|
||||
return view.ToBitmap().AssertContainsColor(expectedColor);
|
||||
}
|
||||
|
||||
public static UIImage AssertContainsColor(this UIImage bitmap, UIColor expectedColor)
|
||||
{
|
||||
for (int x = 0; x < bitmap.Size.Width; x++)
|
||||
{
|
||||
for (int y = 0; y < bitmap.Size.Height; y++)
|
||||
{
|
||||
if (ColorComparison.ARGBEquivalent(bitmap.ColorAtPoint(x, y), expectedColor))
|
||||
{
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Assert.Fail(CreateColorError(bitmap, $"Color {expectedColor} not found."));
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public static async Task AssertEqualsAsync(this UIImage expectedBitmap, UIImage actualBitmap)
|
||||
{
|
||||
if(!actualBitmap.AsPNG().IsEqual(expectedBitmap.AsPNG()))
|
||||
{
|
||||
string failureMessage = null;
|
||||
await Device.InvokeOnMainThreadAsync(() =>
|
||||
{
|
||||
var view = new UIView();
|
||||
UIImageView actualView = new UIImageView() { Image = actualBitmap };
|
||||
UIImageView expectedView = new UIImageView() { Image = expectedBitmap };
|
||||
|
||||
actualView.Frame = new CGRect(0, 0, actualBitmap.Size.Width, actualBitmap.Size.Height);
|
||||
expectedView.Frame = new CGRect(0, actualBitmap.Size.Height + 40, expectedBitmap.Size.Width, expectedBitmap.Size.Height);
|
||||
|
||||
view.Frame = new CGRect(0, 0,
|
||||
actualView.Frame.Width + expectedView.Frame.Width,
|
||||
actualView.Frame.Height + expectedView.Frame.Height);
|
||||
|
||||
view.AddSubviews(actualView, expectedView);
|
||||
failureMessage = CreateColorError(view.ToBitmap(), "Actual (top) vs Expected (bottom)");
|
||||
});
|
||||
|
||||
Assert.Fail(failureMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
using System.Collections;
|
||||
using System.Threading.Tasks;
|
||||
using NUnit.Framework;
|
||||
using UIKit;
|
||||
using Xamarin.Forms.Shapes;
|
||||
using static Xamarin.Forms.Core.UITests.NumericExtensions;
|
||||
using static Xamarin.Forms.Core.UITests.ParsingUtils;
|
||||
|
||||
namespace Xamarin.Forms.Platform.iOS.UnitTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ShapeTests : PlatformTestFixture
|
||||
{
|
||||
public ShapeTests()
|
||||
{
|
||||
}
|
||||
|
||||
[Test, Category("Shape")]
|
||||
[Description("Reused ShapeView Renderers Correctly")]
|
||||
public async Task ReusedShapeViewReRenderers()
|
||||
{
|
||||
var view = new Xamarin.Forms.Shapes.Rectangle
|
||||
{
|
||||
Fill = SolidColorBrush.Purple,
|
||||
HeightRequest = 21,
|
||||
WidthRequest = 21,
|
||||
Stroke = SolidColorBrush.Purple
|
||||
};
|
||||
|
||||
var expected = await GetRendererProperty(view, (ver) => ver.NativeView.ToBitmap(), requiresLayout: true);
|
||||
|
||||
var actual = await GetRendererProperty(view, (ver) => ver.NativeView.ToBitmap(), requiresLayout: true);
|
||||
|
||||
await expected.AssertEqualsAsync(actual);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -69,6 +69,7 @@
|
|||
<Compile Include="BackgroundTests.cs" />
|
||||
<Compile Include="TimePickerTests.cs" />
|
||||
<Compile Include="TransformationTests.cs" />
|
||||
<Compile Include="ShapeTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Xamarin.Forms.Core\Xamarin.Forms.Core.csproj">
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace Xamarin.Forms.Platform.MacOS
|
|||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<Ellipse> args)
|
||||
{
|
||||
if (Control == null)
|
||||
if (Control == null && args.NewElement != null)
|
||||
{
|
||||
SetNativeControl(new EllipseView());
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace Xamarin.Forms.Platform.MacOS
|
|||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<Line> args)
|
||||
{
|
||||
if (Control == null)
|
||||
if (Control == null && args.NewElement != null)
|
||||
{
|
||||
SetNativeControl(new LineView());
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Xamarin.Forms.Platform.MacOS
|
|||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<Path> args)
|
||||
{
|
||||
if (Control == null)
|
||||
if (Control == null && args.NewElement != null)
|
||||
{
|
||||
SetNativeControl(new PathView());
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace Xamarin.Forms.Platform.MacOS
|
|||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<Polygon> args)
|
||||
{
|
||||
if (Control == null)
|
||||
if (Control == null && args.NewElement != null)
|
||||
{
|
||||
SetNativeControl(new PolygonView());
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace Xamarin.Forms.Platform.MacOS
|
|||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<Polyline> args)
|
||||
{
|
||||
if (Control == null)
|
||||
if (Control == null && args.NewElement != null)
|
||||
{
|
||||
SetNativeControl(new PolylineView());
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace Xamarin.Forms.Platform.MacOS
|
|||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<FormsRectangle> args)
|
||||
{
|
||||
if (Control == null)
|
||||
if (Control == null && args.NewElement != null)
|
||||
{
|
||||
SetNativeControl(new RectangleView());
|
||||
}
|
||||
|
|
|
@ -37,6 +37,13 @@ namespace Xamarin.Forms.Platform.MacOS
|
|||
UpdateStrokeLineCap();
|
||||
UpdateStrokeLineJoin();
|
||||
UpdateStrokeMiterLimit();
|
||||
|
||||
if (!args.NewElement.Bounds.IsEmpty)
|
||||
{
|
||||
_height = Element.Height;
|
||||
_width = Element.Width;
|
||||
UpdateSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче