This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bug] Correct the transformation calculation of views (#11933)
* Added the test case * Do not scale the translation * Fix the ordering of the scale/rotate/translate matrices Co-authored-by: Kangho Hur <rookiejava@gmail.com>
- Loading branch information
1 parent
bef121f
commit 36741b9
Showing
13 changed files
with
329 additions
and
19 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11931.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<controls:TestContentPage xmlns="http://xamarin.com/schemas/2014/forms" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:controls="clr-namespace:Xamarin.Forms.Controls" | ||
x:Class="Xamarin.Forms.Controls.Issues.Issue11931" | ||
Title="Issue 11931"> | ||
|
||
<controls:TestContentPage.Resources> | ||
<ResourceDictionary> | ||
<Style TargetType="Button"> | ||
<Setter Property="HorizontalOptions" Value="Start" /> | ||
<Setter Property="WidthRequest" Value="100" /> | ||
<Setter Property="BackgroundColor" Value="#EE888888" /> | ||
<Setter Property="FontSize" Value="12" /> | ||
<Setter Property="HeightRequest" Value="32" /> | ||
<Setter Property="Padding" Value="0" /> | ||
<Setter Property="Margin" Value="0" /> | ||
<Setter Property="CornerRadius" Value="0" /> | ||
<Setter Property="Rotation" Value="{Binding Value, Source={x:Reference rotation}}" /> | ||
</Style> | ||
<Style TargetType="BoxView"> | ||
<Setter Property="VerticalOptions" Value="Fill" /> | ||
<Setter Property="HorizontalOptions" Value="Start" /> | ||
<Setter Property="WidthRequest" Value="1" /> | ||
<Setter Property="Color" Value="LightGray" /> | ||
</Style> | ||
<Style TargetType="Label"> | ||
<Setter Property="HorizontalOptions" Value="Start" /> | ||
</Style> | ||
</ResourceDictionary> | ||
</controls:TestContentPage.Resources> | ||
|
||
<StackLayout> | ||
<Label Padding="12" BackgroundColor="Black" TextColor="White" | ||
HorizontalOptions="Fill" | ||
Text="The buttons should completely cover the bright red boxes" /> | ||
|
||
<Slider x:Name="rotation" Minimum="-180" Maximum="180" /> | ||
|
||
<ScrollView VerticalOptions="FillAndExpand" Orientation="Both"> | ||
<Grid Margin="0" Padding="55,5,5,5"> | ||
<BoxView Margin="0,0,0,0" /> | ||
<BoxView Margin="50,0,0,0" /> | ||
<BoxView Margin="100,0,0,0" Color="Black" /> | ||
<BoxView Margin="150,0,0,0" /> | ||
<BoxView Margin="200,0,0,0" Color="Black" WidthRequest="3" /> | ||
<BoxView Margin="250,0,0,0" /> | ||
<BoxView Margin="300,0,0,0" Color="Black" /> | ||
<BoxView Margin="350,0,0,0" /> | ||
|
||
<Grid> | ||
<Label Text="0" /> | ||
<Label Text="50" Margin="50,0,0,0" /> | ||
<Label Text="100" Margin="100,0,0,0" /> | ||
<Label Text="150" Margin="150,0,0,0" /> | ||
<Label Text="200" Margin="200,0,0,0" /> | ||
<Label Text="250" Margin="250,0,0,0" /> | ||
<Label Text="300" Margin="300,0,0,0" /> | ||
<Label Text="350" Margin="350,0,0,0" /> | ||
</Grid> | ||
|
||
<Grid Margin="0,30,0,0"> | ||
<StackLayout Spacing="6"> | ||
<Label Text=" " /> | ||
|
||
<BoxView Color="Red" Margin="0,0,0,0" WidthRequest="100" HeightRequest="32" /> | ||
<BoxView Color="Red" Margin="-50,0,0,0" WidthRequest="200" HeightRequest="32" /> | ||
<BoxView Color="Red" Margin="0,0,0,0" WidthRequest="200" HeightRequest="32" /> | ||
|
||
<Label Text=" " /> | ||
|
||
<BoxView Color="Red" Margin="200,0,0,0" WidthRequest="100" HeightRequest="32" /> | ||
<BoxView Color="Red" Margin="150,0,0,0" WidthRequest="200" HeightRequest="32" /> | ||
<BoxView Color="Red" Margin="200,0,0,0" WidthRequest="200" HeightRequest="32" /> | ||
|
||
<Label Text=" " /> | ||
|
||
<StackLayout Spacing="16" Margin="0,8,0,0"> | ||
<BoxView Color="Red" Margin="50,0,0,0" WidthRequest="400" HeightRequest="64" /> | ||
<BoxView Color="Red" Margin="200,0,0,0" WidthRequest="400" HeightRequest="64" /> | ||
</StackLayout> | ||
</StackLayout> | ||
|
||
<StackLayout Spacing="6"> | ||
<Label Text="simple scale X" BackgroundColor="#AAFFFFFF" /> | ||
|
||
<Button Text="default" ScaleX="1" TranslationX="0" /> | ||
<Button Text="scale 2x" ScaleX="2" TranslationX="0" /> | ||
<Button Text="left scale 2x" ScaleX="2" TranslationX="0" AnchorX="0" /> | ||
|
||
<Label Text="Scale X then translate X to 200" BackgroundColor="#AAFFFFFF" /> | ||
|
||
<Button Text="default" ScaleX="1" TranslationX="200" /> | ||
<Button Text="scale 2x" ScaleX="2" TranslationX="200" /> | ||
<Button Text="left scale 2x" ScaleX="2" TranslationX="200" AnchorX="0" /> | ||
|
||
<Label Text="Scale 2x then scale X then translate to 200" BackgroundColor="#AAFFFFFF" /> | ||
|
||
<StackLayout Spacing="48" Margin="0,24,0,0"> | ||
<Button Text="scale 2x" Scale="2" ScaleX="2" TranslationX="200" /> | ||
<Button Text="left scale 2x" Scale="2" ScaleX="2" TranslationX="200" AnchorX="0" /> | ||
</StackLayout> | ||
</StackLayout> | ||
</Grid> | ||
|
||
</Grid> | ||
</ScrollView> | ||
</StackLayout> | ||
|
||
</controls:TestContentPage> |
36 changes: 36 additions & 0 deletions
36
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue11931.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Xamarin.Forms.Internals; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Shapes; | ||
using System.Collections.Generic; | ||
|
||
#if UITEST | ||
using Xamarin.UITest; | ||
using NUnit.Framework; | ||
using Xamarin.Forms.Core.UITests; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
#if UITEST | ||
[Category(UITestCategories.ViewBaseTests)] | ||
#endif | ||
[Preserve(AllMembers = true)] | ||
[Issue( | ||
IssueTracker.Github, 11931, | ||
"[Bug] View translation is incorrectly calculated", | ||
PlatformAffected.All)] | ||
public partial class Issue11931: TestContentPage | ||
{ | ||
public Issue11931() | ||
{ | ||
#if APP | ||
InitializeComponent(); | ||
#endif | ||
} | ||
|
||
protected override void Init() | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Xamarin.Forms.Platform.Android.UnitTests/TransformationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Collections; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Internal; | ||
|
||
namespace Xamarin.Forms.Platform.Android.UnitTests | ||
{ | ||
[TestFixture] | ||
public class TransformationTests : PlatformTestFixture | ||
{ | ||
static IEnumerable TransformationCases | ||
{ | ||
get | ||
{ | ||
foreach (var element in BasicElements) | ||
{ | ||
element.TranslationX = 10.0; | ||
element.TranslationY = 30.0; | ||
element.Rotation = 248.0; | ||
element.Scale = 2.0; | ||
element.ScaleX = 2.0; | ||
yield return CreateTestCase(element); | ||
} | ||
} | ||
} | ||
|
||
[Test, Category("Transformation"), TestCaseSource(nameof(TransformationCases))] | ||
[Description("View transformation should match renderer transformation")] | ||
public async Task TransformationConsistent(View element) | ||
{ | ||
var expected = (Context.ToPixels(10d), Context.ToPixels(30d), 248d, 4d, 2d); | ||
var actual = await GetRendererProperty(element, ver => | ||
{ | ||
var v = ver.View; | ||
return (v.TranslationX, v.TranslationY, v.Rotation, v.ScaleX, v.ScaleY); | ||
}, requiresParent: true); | ||
|
||
Assert.That(actual, Is.EqualTo(expected)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
Xamarin.Forms.Platform.UAP.UnitTests/TransformationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using Windows.UI.Xaml; | ||
using WCompositeTransform = Windows.UI.Xaml.Media.CompositeTransform; | ||
|
||
namespace Xamarin.Forms.Platform.UAP.UnitTests | ||
{ | ||
[TestFixture] | ||
public class TransformationTests : PlatformTestFixture | ||
{ | ||
static IEnumerable TransformationCases | ||
{ | ||
get | ||
{ | ||
foreach (var element in BasicViews) | ||
{ | ||
element.TranslationX = 10.0; | ||
element.TranslationY = 30.0; | ||
element.Rotation = 248.0; | ||
element.Scale = 2.0; | ||
element.ScaleX = 2.0; | ||
yield return CreateTestCase(element); | ||
} | ||
} | ||
} | ||
|
||
[Test, Category("Transformation"), TestCaseSource(nameof(TransformationCases))] | ||
[Description("View transformation should match renderer transformation")] | ||
public async Task TransformationConsistent(View view) | ||
{ | ||
var expected = (10d, 30d, 248d, 4d, 2d); | ||
var actual = await GetRendererProperty(view, ver => | ||
{ | ||
var t = GetTransform(ver.ContainerElement); | ||
return (t.TranslateX, t.TranslateY, t.Rotation, t.ScaleX, t.ScaleY); | ||
}); | ||
Assert.That(actual, Is.EqualTo(expected)); | ||
} | ||
|
||
WCompositeTransform GetTransform(FrameworkElement fe) | ||
{ | ||
if (fe.RenderTransform is WCompositeTransform transform) | ||
return transform; | ||
|
||
throw new Exception("No rotation found"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.