Skip to content

Commit

Permalink
Merge pull request #2342 from unoplatform/mergify/bp/release/beta/2.0…
Browse files Browse the repository at this point in the history
…/pr-2316

iOS image alignment were incorrect when size was specified directly on the <Image> control (bp #2316)
  • Loading branch information
jeromelaban authored Dec 17, 2019
2 parents 87ba833 + 299ec51 commit 4ee18c5
Show file tree
Hide file tree
Showing 30 changed files with 435 additions and 124 deletions.
1 change: 1 addition & 0 deletions doc/ReleaseNotes/_ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Release notes

### Features
* Add support for Automation SetDependencyPropertyValue in Uno.UITest
* [#2029](https://github.com/unoplatform/uno/pull/2029) Support for MenuFlyoutItem.Click
* support /[file]/[name] format in ResourceLoader.GetForCurrentView().GetString()
* [#2039] Added support for Xaml type conversions using CreateFromStringAttribute.
Expand Down
9 changes: 5 additions & 4 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
<PackageReference Update="Microsoft.TypeScript.MSBuild" Version="3.1.5" />
<PackageReference Update="NUnit" Version="3.12.0" />
<PackageReference Update="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Update="Uno.UITest" Version="1.0.0-dev.97" />
<PackageReference Update="Uno.UITest.Selenium" Version="1.0.0-dev.97" />
<PackageReference Update="Uno.UITest.Xamarin" Version="1.0.0-dev.97" />
<PackageReference Update="Uno.UITest.Helpers" Version="1.0.0-dev.97" />
<PackageReference Update="Uno.UITest" Version="1.0.0-dev.105" />
<PackageReference Update="Uno.UITest.Selenium" Version="1.0.0-dev.105" />
<PackageReference Update="Uno.UITest.Xamarin" Version="1.0.0-dev.105" />
<PackageReference Update="Uno.UITest.Helpers" Version="1.0.0-dev.105" />
<PackageReference Update="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/SamplesApp/SamplesApp.UITests/SampleControlUITestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@ private Platform[] GetActivePlatforms()
return Array.Empty<Platform>();
}

protected void Run(string metadataName, bool waitForSampleControl = true)
protected void Run(string metadataName, bool waitForSampleControl = true, bool skipInitialScreenshot = false, int sampleLoadTimeout = 5)
{
if (waitForSampleControl)
{
_app.WaitForElement("sampleControl");
_app.WaitForElement("sampleControl", timeout: TimeSpan.FromSeconds(sampleLoadTimeout));
}

var testRunId = _app.InvokeGeneric("browser:SampleRunner|RunTest", metadataName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public void Screenshots_Image_Stretch_Alignment_Equal()
RunScreenShots_Image_Alignment_page("Uno.UI.Samples.UITests.Image.Image_Stretch_Alignment_Equal");
}

[Test]
[AutoRetry]
public void Screenshots_Image_Stretch_Alignment_SizeOnControl()
{
RunScreenShots_Image_Alignment_page("UITests.Shared.Windows_UI_Xaml_Controls.ImageTests.Image_Stretch_Alignment_SizeOnControl");
}

[Test]
[AutoRetry]
public void Screenshots_Image_Stretch_Alignment_Smaller()
Expand All @@ -80,20 +87,21 @@ public void Screenshots_Image_Stretch_Alignment_Wider()

private void RunScreenShots_Image_Alignment_page(string testName)
{
Run(testName);
Run(testName, skipInitialScreenshot: true);

var picker = _app.Marked("modesPicker");

var currentModeButton = _app.Marked("currentMode");
_app.WaitForElement(currentModeButton);

var nextStretchButton = _app.Marked("nextStretch");
nextStretchButton.Tap();
_app.WaitForDependencyPropertyValue(currentModeButton, "Content", "00");

for (var i = 0; i < 4; i++)
{
// Use SetDependencyPropertyValue instead of Tap for performance on iOS/Android (Tap takes multiple seconds to complete)
picker.SetDependencyPropertyValue("Mode", "S" + i);
_app.WaitForDependencyPropertyValue(currentModeButton, "Content", (i * 16).ToString("00"));

base.TakeScreenshot("Mode-" + i);
nextStretchButton.Tap();
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ImageTests\Image_Stretch_Alignment_SizeOnControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ImageTests\Image_Stretch_Modes_Picker.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -3008,6 +3012,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ImageTests\Image_Stretch_Algmnt_Inf_Vertical.xaml.cs">
<DependentUpon>Image_Stretch_Algmnt_Inf_Vertical.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ImageTests\Image_Stretch_Alignment_SizeOnControl.xaml.cs">
<DependentUpon>Image_Stretch_Alignment_SizeOnControl.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ImageTests\Image_Stretch_Modes_Picker.xaml.cs">
<DependentUpon>Image_Stretch_Modes_Picker.xaml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<Page
x:Class="UITests.Shared.Windows_UI_Xaml_Controls.ImageTests.Image_Stretch_Alignment_SizeOnControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:not_win="http://uno.ui/"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="using:Uno.UI.Samples.UITests.Image"
mc:Ignorable="d not_win"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid HorizontalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<local:Image_Stretch_Modes_Picker x:Name="modesPicker" />
<ScrollViewer Grid.Row="1">
<ItemsControl ItemsSource="{Binding Items, ElementName=modesPicker}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<win:VariableSizedWrapGrid Orientation="Horizontal" />
<not_win:WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Width="150" Padding="5" Background="LightGreen" Margin="5">
<TextBlock FontSize="12">
<Run Text="{Binding Index}" />) s=<Run Text="{Binding Stretch}" FontWeight="Bold" />
<LineBreak />h=<Run Text="{Binding HorizontalAlignment}" FontWeight="Bold" />
<LineBreak />v=<Run Text="{Binding VerticalAlignment}" FontWeight="Bold" />
</TextBlock>
<Border BorderThickness="1"
Width="127"
Height="152"
BorderBrush="Black"
Background="DeepPink">
<Image Stretch="{Binding Stretch}"
VerticalAlignment="{Binding VerticalAlignment}"
HorizontalAlignment="{Binding HorizontalAlignment}"
Width="125"
Height="150"
Source="ms-appx:///Assets/test_image_100_100.png" />
</Border>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Windows.UI.Xaml.Controls;
using Uno.UI.Samples.Controls;

namespace UITests.Shared.Windows_UI_Xaml_Controls.ImageTests
{
[SampleControlInfo("Image")]
public sealed partial class Image_Stretch_Alignment_SizeOnControl : Page
{
public Image_Stretch_Alignment_SizeOnControl()
{
this.InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<UserControl
<Page
x:Class="Uno.UI.Samples.UITests.Image.Image_Stretch_Alignment_Smaller"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Expand Down Expand Up @@ -49,4 +49,4 @@
</ItemsControl>
</ScrollViewer>
</Grid>
</UserControl>
</Page>
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Windows.UI.Xaml.Controls;
using Uno.UI.Samples.Controls;

namespace Uno.UI.Samples.UITests.Image
{
[Controls.SampleControlInfo("Image")]
public sealed partial class Image_Stretch_Alignment_Smaller : UserControl
[SampleControlInfo("Image")]
public sealed partial class Image_Stretch_Alignment_Smaller : Page
{
public Image_Stretch_Alignment_Smaller()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,42 @@ public sealed partial class Image_Stretch_Modes_Picker : UserControl
public ComboBoxItem[] HorizontalAlignments { get; } = GetValues<HorizontalAlignment>().ToArray();
public ComboBoxItem[] VerticalAlignments { get; } = GetValues<VerticalAlignment>().ToArray();

public static readonly DependencyProperty ModeProperty = DependencyProperty.Register(
"Mode", typeof(string), typeof(Image_Stretch_Modes_Picker), new PropertyMetadata(default(string), ModeChanged));

public string Mode
{
get { return (string)GetValue(ModeProperty); }
set { SetValue(ModeProperty, value); }
}

public static readonly DependencyProperty ItemsProperty = DependencyProperty.Register(
"Items",
typeof(List<StretchModeItem>),
typeof(Image_Stretch_Modes_Picker),
new PropertyMetadata(default(List<StretchModeItem>)));

private static void ModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var picker = d as Image_Stretch_Modes_Picker;
var modeStr = e.NewValue as string ?? "";
if (modeStr.Length >= 1)
{
switch (modeStr[0])
{
case 'S':
picker.OnNextStretch(null, null);
break;
case 'H':
picker.OnNextHorizontal(null, null);
break;
case 'V':
picker.OnNextVertical(null, null);
break;
}
}
}

public List<StretchModeItem> Items
{
get { return (List<StretchModeItem>)GetValue(ItemsProperty); }
Expand Down
22 changes: 12 additions & 10 deletions src/Uno.Foundation/Point.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Uno.Extensions;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Globalization;
Expand All @@ -10,6 +11,7 @@

namespace Windows.Foundation
{
[DebuggerDisplay("{X},{Y}")]
public partial struct Point
{
public Point(double x, double y)
Expand Down Expand Up @@ -48,21 +50,21 @@ public override string ToString()
return new Point(p1.X - p2.X, p1.Y - p2.Y);
}

public static implicit operator Point(string point)
{
var parts = point
.Split(new[] { ',' })
.Select(value => double.Parse(value, CultureInfo.InvariantCulture))
.ToArray();
public static implicit operator Point(string point)
{
var parts = point
.Split(new[] { ',' })
.Select(value => double.Parse(value, CultureInfo.InvariantCulture))
.ToArray();

return new Point(parts[0], parts[1]);
}
return new Point(parts[0], parts[1]);
}

public override int GetHashCode() => X.GetHashCode() ^ Y.GetHashCode();
public override int GetHashCode() => X.GetHashCode() ^ Y.GetHashCode();

public override bool Equals(object obj)
{
if(obj is Point)
if (obj is Point)
{
var point = (Point)obj;

Expand Down
8 changes: 4 additions & 4 deletions src/Uno.Foundation/Rect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Windows.Foundation
{
[DebuggerDisplay("[Rect {X},{Y}-{Width}x{Height}]")]
[DebuggerDisplay("[Rect {Size}@{Location}]")]
public partial struct Rect
{
private const string _negativeErrorMessage = "Non-negative number required.";
Expand Down Expand Up @@ -88,7 +88,7 @@ public Rect(Point point1, Point point2)
public double Right => X + Width;
public double Bottom => Y + Height;

public bool IsEmpty => Empty.Equals(this);
public bool IsEmpty => Empty.Equals(this);

public static implicit operator Rect(string text)
{
Expand Down Expand Up @@ -206,7 +206,7 @@ public void Union(Rect rect)
this = new Rect(left, top, right - left, bottom - top);
}

public bool Equals(Rect value)
public bool Equals(Rect value)
=> value.X == X
&& value.Y == Y
&& value.Width == Width
Expand All @@ -218,7 +218,7 @@ public bool Equals(Rect value)

public static bool operator !=(Rect left, Rect right) => !left.Equals(right);

public override bool Equals(object obj)
public override bool Equals(object obj)
=> obj is Rect r ? r.Equals(this) : base.Equals(obj);
}
}
8 changes: 5 additions & 3 deletions src/Uno.Foundation/Size.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Security;

namespace Windows.Foundation
{
[DebuggerDisplay("{Width}x{Height}")]
[TypeConverter(typeof(SizeConverter))]
public partial struct Size
{
Expand All @@ -22,9 +24,9 @@ public Size(double width, double height)

public override bool Equals(object o)
{
if(o is Size other)
if (o is Size other)
{
return other.Width == Width
return other.Width == Width
&& other.Height == Height;
}

Expand All @@ -45,4 +47,4 @@ public bool Equals(Size value)

public static bool operator !=(Size size1, Size size2) => !size1.Equals(size2);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public async Task AdjustSize_Expected_Result(Stretch stretch, double availableWi
public async Task MeasureSource_Expected_Result(
Stretch stretch,
string alignment,
double imageNaturalWidth,
double imageNaturalHeight,
double imageNaturalWidth,
double imageNaturalHeight,
double finalWidth,
double finalHeight,
double expectedX,
Expand Down Expand Up @@ -139,12 +139,10 @@ public async Task MeasureSource_Expected_Result(
break;
}

var image = new Image {Stretch = stretch, HorizontalAlignment = horizontal, VerticalAlignment = vertical};
var image = new Image { Stretch = stretch, HorizontalAlignment = horizontal, VerticalAlignment = vertical };

var measuredRect = new Rect(default, imageNaturalSize);

image.MeasureSource(finalSize, ref measuredRect);
image.ArrangeSource(finalSize, ref measuredRect);
var containerRect = image.MeasureSource(finalSize, imageNaturalSize);
var measuredRect = image.ArrangeSource(finalSize, containerRect);

measuredRect.Should().Be(
expectedRect,
Expand Down
Loading

0 comments on commit 4ee18c5

Please sign in to comment.